Search code examples
c++visual-c++c++11visual-studio-2012initializer

initializer_list in visual studio 2012


I found that initializer_list is not supported by MSVC 2012. But can it (initializer_list) be used in VS somehow (with the help of Boost library for example). Samples if you can, please.


Solution

  • Boost::assign is as close as you get.

    More specifically, assign::list_of is probably similar to the behavior you're looking for.

    // Examples from the documentation:
    const list<int> primes = list_of(2)(3)(5)(7)(11);
    const stack<string> names = list_of( "Mr. Foo" )( "Mr. Bar")( "Mrs. FooBar" ).to_adapter();
    map<int,int> next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6);