Lambda implicit capture fails with variable declared from structured binding

后端 未结 2 402
梦谈多话
梦谈多话 2020-11-28 10:45

With the following code, I get a compile error C2065 \'a\': undeclared identifier (using visual studio 2017):

[] {
    auto [a, b] = [] {return          


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 11:35

    A possible workaround is to use a lambda capture with the initializer. The following code compiles fine in Visual Studio 2017 15.5.

    [] {
        auto[a, b] = [] {return std::make_tuple(1, 2); }();
        auto r = [a = a] {return a; }();
    }();
    

提交回复
热议问题