Hoo*_*ked 4 c++ boost stl initialization
就像已经问到的这个问题一样,我想用STL初始化一个容器,其中元素以最干净的方式进行硬编码.在这种情况下,元素是双嵌套容器:
set<vector<int> > A;
Run Code Online (Sandbox Code Playgroud)
我希望(例如)将以下值放入:
A = [[0,0,1],[0,1,0],[1,0,0],[0,0,0]];
Run Code Online (Sandbox Code Playgroud)
C++ 0x没问题,使用g++4.4.1.STL是优选的,因为我不使用Boost代码的任何其他部分(虽然我不介意用它的例子!).
Mat*_*hen 10
这确实使用g ++ 4.4.1,-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}};
}
Run Code Online (Sandbox Code Playgroud)
#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;
}
Run Code Online (Sandbox Code Playgroud)