Reputation: 13434
Inspecting the constructor std::vector::vector( size_type count, const T& value, const Allocator& alloc = Allocator() );
(ref), we can read that it:
Constructs a vector with
count
copies of elements with valuevalue
.
I think I see a missed opportunity for optimization, albeit a very minor one. An introduction of std::vector::vector( size_type count, T&& value, const Allocator& alloc = Allocator() );
would allow for count - 1
copies and 1 move, which would most likely be more performant. This constructor could first move from value
into the vector's buffer and copy from it, or start copying and replace a final copy with a move.
Apart from nobody has yet proposed it and this seems like an insanely minor gain for introducing yet another constructor, are there any valid reasons why such optimization is absent from constructor overloads?
Upvotes: 2
Views: 97