Search code examples
c++stlconstructorcontainersassociative

Constructing associative containers


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?


Solution

  • You can use Boost.Assign.

    std::set< int > _set = boost::assign::list_of(2)(3)(5);