#include <type_traits>
#include <utility>
int main()
{
using T = std::pair<const int, int>;
const auto ok = std::is_assignable<T, T>::value; // true
T x;
T y;
x = y; // compiler error
}
但以下三个编译器中,变量 ok
的值都为真。
- g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
- clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
- MSVC++ 2017 15.2 26430.6
为什么会这样呢?
std::cout << std::boolalpha << ok << '\n';
在 Clang 5.0 中输出false
。 - Henri Menke