I have a problem when bind
ing a function object created by bind
as an argument to a function.
I have two functions fa
and fb
. fa
takes a function as a parameter. I bind fa
and the function (fb
in that case) into a closure. I do it in two different ways, given below. The first one works, the second one does not compile.
(I know, I would not need to bind on the marked line since there are no parameters. But of course this is only the minimal example to show the behavior, in practice I will bind parameters to fb
)
void fa(function<void()> f){
f();
}
void fb(){
}
void test_which_compiles() {
auto bb = fb; // *** QUESTIONABLE LINE ***
auto aa = std::bind(fa, bb);
aa();
}
void test_which_fails() {
auto bb = std::bind(fb); // *** QUESTIONABLE LINE ***
auto aa = std::bind(fa, bb);
aa(); // COMPILE ERROR HERE
}
The compile error happens when invoking aa()
.
So it seems that the compiler does not accept when I bind a function object as an argument which was itself created by bind.
The compile error is a long list of stuff that I would not consider directly related to the line. I only give the first line:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:3476:13: error: no matching function for call to '__invoke' __invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)
The compiler is an Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
with C++11 enabled.