I have a problem with this program:
struct A {};
int main()
{
::std::vector< ::std::unique_ptr<A> > v;
::std::cout << ::std::is_copy_constructible<decltype(v)>{} << ::std::endl;
//decltype(v) w(v);
return 0;
}
This outputs:
1
Yet, if I uncomment the commented line, the program will fail to compile. Do you think, it is a bug in the standard, that ::std::is_copy_constructible<decltype(v)>{}
evaluates to true
and where in the standard? Should, for example, the metafunction be fixed, or should the container delete it's copy constructor, if the value_type
is not copyable?
EDIT: I suppose I should clarify why this is important. Say, you have a class template variant
, that contains a container class template instantiated with a non-copyable value_type
. The variant
could SFINAE
away methods that copy the container and avoid compile errors, but since it receives wrong information from the STL
, it can't. As a result of this problem, I've had to write a special moving_variant
class template, that only moves, never copies, whereas it could/should be possible to have a single variant
class template.
is_copy_constructible
is defined in terms of is_constructible
, which is true if an expression like this is well-formed:
T t(create<const T&>())
In the case of vector<unique_ptr>
, this is well-formed, since vector
declares a suitable copy constructor. The constructor can't be instantiated since it uses a deleted function; but templates aren't instantiated when used in an unevaluated context like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With