使用 STL/Boost 来初始化一个硬编码集合<vector<int>>

2022-01-19 00:00:00 initialization c++ stl boost

像这样 问题 已经问过了,我想使用 STL 初始化一个容器,其中元素以最干净的方式进行硬编码.在这种情况下,元素是一个双重嵌套的容器:

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 following values in:

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

C++0x 很好,使用 g++ 4.4.1.STL 更可取,因为我不将 Boost 用于代码的任何其他部分(尽管我不介意使用它的示例!).

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!).

推荐答案

这确实使用g++ 4.4.1, with -std=c++0x

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}};

}

相关文章