In my version of clang and libc++ (near HEAD
), this static_assert
passes:
static_assert(std::is_copy_constructible_v<std::vector<std::unique_ptr<int>>>)
Of course if you actually try to copy-construct a vector of unique pointers it fails to compile:
../include/c++/v1/__memory/allocator.h:151:28: error: call to implicitly-deleted copy constructor of 'std::unique_ptr<int>'
::new ((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
[...]
note: in instantiation of member function 'std::vector<std::unique_ptr<int>>::vector' requested here
const std::vector<std::unique_ptr<int>> bar(foo);
^
../include/c++/v1/__memory/unique_ptr.h:215:3: note: copy constructor is implicitly deleted because 'unique_ptr<int>' has a user-declared move constructor
unique_ptr(unique_ptr&& __u) _NOEXCEPT
I assume that this situation is because the std::vector<T>
implementation doesn't use SFINAE to disable the copy constructor when T
isn't copy-constructible. But why not? Is there something in the standard that says it must work this way? It's unfortunate because it means my own SFINAE around copy-constructibility doesn't do the right thing around vectors.