3

I need to capture a move-only bind object in a lambda, and I'm trying to use a workaround with std::bind to obtain move-capturing semantics with C++11 as detailed here. I've reduced a test case that shows the move-only part of it isn't relevant to the compile error I'm encountering, so most generally this question is about using std::bind to bind the result from another std::bind as an argument.

Here's a minimal example reduced from more complex code:

void g(int);

void test() {
    auto fn = std::bind(g, 0);
    using Fn = decltype(fn);
//    auto bound = [fn] {};
    auto bound = std::bind([] (Fn) {}, fn);
    bound();
}

This produces the error "No matching function for call to '__invoke'". The complete error output is available here.

The equivalent simpler case using a capturing lambda (commented out in the above code) works fine, of course. But in my actual code I would need to write [fn = std::move(fn)] {} and I don't have the option of requring C++14 yet.

What am I doing wrong?

Community
  • 1
  • 1
John
  • 29,546
  • 11
  • 78
  • 79
  • 3
    You are running into [`bind`'s special handling for bind expressions](http://stackoverflow.com/questions/10777421/stdbind-a-bound-function). – T.C. May 02 '15 at 16:59
  • Anyway, here's a possible fix: http://coliru.stacked-crooked.com/a/3084ebd679f723a7 – T.C. May 02 '15 at 17:12

0 Answers0