它是安全的(在理论上还是在实践中),以reinterpret_cast一std::pair<T1, T2> const &成std::pair<T1 const, T2> const &,假设程序员没有故意做了一些奇怪的类似专业std::pair<T1 const, T2>?
正如所料,以下代码无法编译.
#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
}
Run Code Online (Sandbox Code Playgroud)
但是以下三个编译器的值ok 是正确的.
为什么是这样?