質問

I have a lot of functors that I am passing to a function to do some testing work. My goal is to do these with std::bind and not use lambdas. But the very simple cases seem hard to do with bind. My first question was here.

Now I want to know if there is a pass through delayed function call that I can create with bind. Something like: auto foo = std::bind( std::placeholders::_1 ) Such that foo( 13 ) will return 13.

役に立ちましたか?

解決

This is the same answer given on the linked question:

So there is a way to accomplish this using std::integral_constant:

const int thirteen = 13;
auto refWrap = bind( &std::integral_constant< int, thirteen >::operator int, std::integral_constant< int, thirteen >() );

This does solve the question, but for all intents and purposes is inferior to the lambda:

const int thirteen = 13;
auto refWrap = [=](){ return thirteen; };
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top