clang-cl (4.0.0-trunk) 似乎认为是,而 vc2015 (update3) 认为不是。
此实现是否已定义或标准是否规定了 lambda 函数应如何在术语或 nothrow 和 move assignable 中实现?
#include <type_traits>
#include <iostream>
template <typename T>
void test_nothrow_move_assignable(T&&) {
std::cout << std::boolalpha
<< std::is_nothrow_move_assignable<T>::value
<< "\n";
}
int main() {
test_nothrow_move_assignable([]{});
return 0;
}
// $ clang-cl.exe scratch.cpp
// $ scratch.exe
// true
// $ cl /nologo /EHsc scratch.cpp
// scratch.cpp
// $ scratch.exe
// false
最佳答案
这是 clang 错误。来自 [expr.prim.lambda]:
The closure type associated with a lambda-expression has no default constructor and a deleted copy assignment operator. It has a defaulted copy constructor and a defaulted move constructor (12.8).
所以这个类型根本不应该是 move assignable 的,更不用说 nothrow move assignable 了。
关于c++ - lambda 函数不是 throw_move_assignable 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40223413/