Bu sorun, this question'dan geldi. std :: function oluştururken libstdC++ ve libC++ arasındaki farklı davranış
++ libstdc ile clang 3.4 kullanarak kod compiles fine aşağıdadır:In file included from main.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:599:
/usr/include/c++/v1/tuple:320:11: error: rvalue reference to type '<lambda at main.cpp:4:31>' cannot bind to lvalue of type '<lambda at main.cpp:4:31>'
: value(__t.get())
^ ~~~~~~~~~
/usr/include/c++/v1/tuple:444:8: note: in instantiation of member function 'std::__1::__tuple_leaf<0, <lambda at main.cpp:4:31> &&, false>::__tuple_leaf' requested here
struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
^
/usr/include/c++/v1/functional:1278:26: note: in instantiation of member function 'std::__1::__function::__func<<lambda at main.cpp:4:31>, std::__1::allocator<<lambda at main.cpp:4:31> >, void()>::__func' requested here
::new (__f_) _FF(_VSTD::move(__f));
^
main.cpp:4:31: note: in instantiation of function template specialization 'std::__1::function<void()>::function<<lambda at main.cpp:4:31> >' requested here
std::function<void()> f = []() {};
^
In file included from main.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:599:
/usr/include/c++/v1/tuple:321:10: error: static_assert failed "Can not copy a tuple with rvalue reference member"
{static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/v1/tuple:320:11: error: rvalue reference to type 'allocator<[...]>' cannot bind to lvalue of type 'allocator<[...]>'
: value(__t.get())
^ ~~~~~~~~~
/usr/include/c++/v1/tuple:444:8: note: in instantiation of member function 'std::__1::__tuple_leaf<0, std::__1::allocator<<lambda at main.cpp:4:31> > &&, false>::__tuple_leaf' requested here
struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
^
/usr/include/c++/v1/functional:1286:34: note: in instantiation of member function 'std::__1::__function::__func<<lambda at main.cpp:4:31>, std::__1::allocator<<lambda at main.cpp:4:31> >, void()>::__func' requested here
::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
^
main.cpp:4:31: note: in instantiation of function template specialization 'std::__1::function<void()>::function<<lambda at main.cpp:4:31> >' requested here
std::function<void()> f = []() {};
^
In file included from main.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:599:
/usr/include/c++/v1/tuple:321:10: error: static_assert failed "Can not copy a tuple with rvalue reference member"
{static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.
hangi davranış doğrudur:
#include <functional>
int main() {
std::function<void()> f = []() {};
}
Ama fails miserably ++ clang 3.4 ve libc kullanımıyla?
Evet, bir kere []() {} biçimine indirildikten sonra, doğru davranış oldukça açıktır. Hata raporuna bağlantı için teşekkürler. –