【发布时间】:2019-02-01 07:19:35
【问题描述】:
#include <type_traits>
int main()
{
std::is_constructible_v<int&, const int&>; // false, as expected.
std::is_copy_constructible_v<int&>; // true, NOT as expected!
}
根据cppref:
如果 T 是对象或引用类型且变量定义为 T obj(std::declval()...);结构良好,为会员提供 常量值等于真。在所有其他情况下,值为 false。
std::is_copy_constructible_v<int&> 应该给出与std::is_constructible_v<int&, const int&> 相同的结果;但是,clang 7.0 给出了不同的结果,如上所示。
这种行为是否符合 C++ 标准?
【问题讨论】:
-
另一方面,
using T = int&; static_assert(std::is_constructible_v<T, const T&>); // true至少匹配is_copy_constructible_v结果。
标签: c++ c++11 standards typetraits compile-time-constant