开发者

Using STL/Boost to initialize a hard-coded set<vector<int> >

开发者 https://www.devze.com 2022-12-28 12:23 出处:网络
Like this question already asked, I\'d like to initialize a container using STL where the elements are hard-coded in the cleanest manner possible. In this case, the elements are a doubly nested contai

Like this question already asked, I'd like to initialize a container using STL where the elements are hard-coded in the cleanest manner possible. In this case, the elements are a doubly nested container:

set<vector<int> > A;

And I'd like (for example) to put the follo开发者_StackOverflow社区wing values in:

A = [[0,0,1],[0,1,0],[1,0,0],[0,0,0]];

C++0x fine, using g++ 4.4.1. STL is preferable as I don't use Boost for any other parts of the code (though I wouldn't mind an example with it!).


This does use g++ 4.4.1, with -std=c++0x

#include <set>
#include <vector>

using namespace std;

int main()
{
    set<vector<int>> A = {{0,0,1},{0,1,0},{1,0,0},{0,0,0}};

}


#include <boost/assign/list_of.hpp> 
#include <vector>
#include <set>

using namespace std;
using namespace boost::assign;

int main()
{
    set<vector<int> > A;

    A = list_of
        (list_of(0)(0)(1))
        (list_of(0)(1)(0))
        (list_of(1)(0)(0));
        (list_of(0)(0)(0));
    return 0;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消