I have a type X, which is copy-constructible but not copy assignable
struct X {
X();
X(const X&);
X& operator=(const X&) = delete; // !!
X(X&&) noexcept;
X& operator=(X&&) noexcept;
int data = 54;
};
I have two vectors of 'X': a and b and I want to insert all the contents of b at the front of a:
void add_to_front(std::vector<X>& a, const std::vector<X>& b) {
a.insert(a.begin(), b.begin(), b.end());
}
This compiles and works as expected on msvc but fails to compile on clang and gcc. I'm guessing due to poor implementations of libc++ and libstdc++ which need something to compile even though it will never get called (or, worse yet, it will get called!?).
I could write a manual loop to emplace elements of b into a which will produce a correct result, but the complexity of this is a*b instead of a+b, as each call to emplace will shift all elements of a over and over again.
So is there an efficient way to do it?