riv
riv

Reputation: 7323

VS2013: Can't create vector from one size_t element

Just want to make sure its actually a bug and I'm not doing something wrong. It compiles fine with gcc (MinGW):

std::vector<size_t> a({1, 2}); // works
std::vector<size_t> b({1}); // does not work
std::vector<int> c({1}); // works

Error:

error C2440: 'initializing' : cannot convert from 'initializer-list' to 'std::vector<std::seed_seq::result_type,std::allocator<char32_t>>'

Upvotes: 2

Views: 139

Answers (1)

uesp
uesp

Reputation: 6204

It is probably a bug in VS2013 as I believe initializer-lists were added in that version. Note that if you omit the () it seems to work fine:

std::vector<size_t> b{ 1 }; // works

Trying a few other variations yields some surprising results too:

std::vector<size_t> b({ 1 });            // does not work
std::vector<size_t> b1({ 1u });          // does not work
std::vector<long> b2({ 1 });             // does not work
std::vector<long> b3({ 1l });            // works
std::vector<long long> b4({ 1l });       // does not work
std::vector<unsigned int> b5({ 1u });    // does not work
std::vector<size_t> b6{ 1 };             // works
std::vector<unsigned char> b7({ 1 });    // does not work
std::vector<unsigned char> b8({ 1u });   // works
std::vector<unsigned short> b9({ 1 });   // does not work
std::vector<unsigned short> b10({ 1u }); // works
std::vector<unsigned int> b11({ 1u });   // does not work
std::vector<int> b12({ 1u });            // works
std::vector<int> b13({ 1l });            // works

Removing the () from all the above cases that don't compile makes it work.

Upvotes: 1

Related Questions