Why is class with non-const copy constructor not treated as copy constructible?

非 Y 不嫁゛ 提交于 2019-12-05 13:39:39

While this is indeed a valid copy constructor, the is_copy_constructible type-trait is defined to give the same result as is_constructible_v<T, const T&>, because it is intended to correspond to the CopyConstructible concept that is also defined by the standard.

In [utility.arg.requirements]/1 it says

The template definitions in the C++ standard library refer to various named requirements whose details are set out in Tables 20–27. In these tables, T is an object or reference type to be supplied by a C++ program instantiating a template;[...] and v is an lvalue of type (possibly const) T or an rvalue of type const T.

The CopyConstructible concept is defined in Table 24 as

Table 24 — CopyConstructible requirements (in addition to MoveConstructible)
Expression     Post-condition
T u = v;           the value of v is unchanged and is equivalent to u
T(v)                 the value of v is unchanged and is equivalent to T(v)

Therefore, since your object is not constructible from a const Foo lvalue, which is one of the requirements of CopyConstructible, it is not regarded as such.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!