I am wondering if an initializer_list<T>
requires that T has an assignment operator. The following
struct Foo
{
Foo& operator=( const Foo& ) = delete;
};
std::vector<Foo> f = { Foo( ), Foo( ) };
compiles on clang 3.4.2 but fails on Visual Studo 2013 with a "error C2280: 'Foo &Foo::operator =(const Foo &)' : attempting to reference a deleted function"
. I am assuming clang is correct here but wanted to check that there is no requirement for T to to be assignable.
std::initializer_list<T>
does not require T
to be assignable in any way, because copying std::initializer_list
objects is shallow - it does not copy the underlying data.
You're getting the error because MSVC 2013 (and below) does not support automatic generation of move constructors and move assignment operators. So the error actually comes from std::vector
trying to copy from the initializer list, not from the initializer list itself.
It's still a question why the error is triggered, since the std::vector
constructor taking std::initializer_list
only requires the type to be EmplaceConstructible
and possibly MoveInsertable
, neither of which uses assignments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With