Fureeish
Fureeish

Reputation: 13434

Is there a reason for the lack of vector's (and other sequential containers such as deque) constructor that moves an element to perfom one less copy?

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 value value.

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

Answers (0)

Related Questions