Reputation: 40947
I was convinced (until I just tried it a moment ago) that it was possible to instantiate an associative container with array style notation.
For example,
std::set< int > _set = { 2, 3, 5 };
This isn't the case but I am wondering if there is any other way of bulk initialising a container in the constructor like this?
Upvotes: 0
Views: 93
Reputation: 272507
You could do:
const int x[] = { 2, 3, 5 };
std::set<int> _set(&x[0], &x[sizeof(x)/sizeof(x[0])]);
!
Upvotes: 0
Reputation: 76788
You can use Boost.Assign.
std::set< int > _set = boost::assign::list_of(2)(3)(5);
Upvotes: 2