Why is a class with a non-console copy constructor not treated as copyable?

Considering

struct Foo 
{
    Foo(Foo&) {} 
};

std::is_copy_constructible<Foo>::value false

Foo has a valid constructor instance: from draft n4659:

15.8.1 Copy/move constructors [class.copy.ctor]
1
A non-template constructor for class X is a copy constructor if its first parameter is of type X& , const X& ,
volatile X& or const volatile X& , and either there are no other parameters or else all other parameters
have default arguments (11.3.6). [Example: X::X(const X&) and X::X(X&,int=1) are copy constructors.

but is_copy_constructiblechecks is_constructible_v<T, const T&>( const ) according to the standard.

Why isn't a class with a non-const copy constructor considered a way to copy?

+4
source share
1 answer

Despite the fact that the copy constructor does, the is_copy_constructibletype of trait is determined to give the same result as is_constructible_v<T, const T&>, since it is designed to conform to the CopyConstructibleconcept, it is also defined by the standard.

[utility.arg.requirements]/1

++ , 20-27. T , ++ C; [...] (< > Const) rvalue const T.

CopyConstructible 24

24 - ( MoveConstructible)
 
T u = v;         v u (v)                 V (V)

, const Foo lvalue, CopyConstructible, .

+3

Source: https://habr.com/ru/post/1675597/


All Articles