c++ - lambda 函数不是 throw_move_assignable 吗?

标签 c++ lambda typetraits

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/

相关文章:

c++ - 是否有类型特征可以立即删除顶级 cv 和引用?

c++ - wget for windows 在调用 createprocess() 时忽略选项

c++ - 无法创建 QFile(仅适用于 msvc2017 uwp)

c++ - 初始化命名空间中的 const 对象

c++ - 显式指定通用 lambda 的 operator() 模板参数是否合法?

C++ 模板专门化以提供/添加不同的成员函数

c++ - 如何在模板化对象的 vector 上获取迭代器?

java - 如何每次使用列表中的不同值来应用使用 .map lambda 表达式的操作?

c# - 用参数替换 Where 子句 Lambda 中的运算符

c++ - 为什么 SFINAE 在这个例子中没有按预期工作?