In [vector.cons] there is the std::vector
constructor (emphasis mine):
template<class InputIterator> constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
Effects: Constructs a vector equal to the range
[first, last)
, using the specified allocator.Complexity: Makes only N calls to the copy constructor of
T
(where N is the distance betweenfirst
andlast
) and no reallocations if iteratorsfirst
andlast
are of forward, bidirectional, or random access categories. It makes order N calls to the copy constructor ofT
and order logN reallocations if they are just input iterators.
However, the following example compiles fine in GCC, Clang (using libc++), and at least in the version of MSVC hosted in godbolt.org.
#include <cstddef>
#include <vector>
#include <complex>
class A
{
private:
std::complex<double> const x;
public:
A() = delete;
A(A const &) = delete;
explicit A(std::complex<double> const x_) : x(x_) {}
};
void f(std::size_t Size)
{
std::vector<std::complex<double>> v(Size);
std::vector<A> u(std::begin(v), std::end(v));
}
i. e. the appropriate constructor is chosen instead of the deleted copy constructor. Can I rely on such behavior? Am I misunderstanding the standard wording?