c++ - How can I push an aggregate initialiser list into a vector? -


i trying write that:

vector<iovec> iovecs; iovec io = {&foo, sizeof(foo)}; iovevs.push_base(io); 

which ok compiler.

now trying transform more concise, that:

 vector<iovec> iovecs;  iovecs.push_back({&foo, sizeof(foo)}); 

but rejected error msg like:

warning: extended initializer lists available -std=c++0x or -std=gnu++0x 

i not want enable c++0x. still want able uses aggregates init style. there way that?

that usage of braced-initializer in terms of uniform-initialization feature introduced c++11.

if don't want enable such compiler support quite naturally forced work have in earlier standard(s); which, have found out, doesn't include uniform-initialization.


a simple "hack" might ease pain below:

template<typename t, typename u> iovec make_iovec (t const& a, u const& b) {  iovec  ret = {a, b};  return ret; } 

iovecs.push_back (make_iovec (&foo, sizeof(foo))); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -