可以在C++中创建一个无序向量集吗?类似这样的东西。
std::unordered_set<std::vector<int>> s1;
因为我知道标准库中的“set”类可以做到这一点,但似乎对于无序版本不起作用。 谢谢
更新: 这正是我正在尝试使用的代码
typedef int CustomerId;
typedef std::vector<CustomerId> Route;
typedef std::unordered_set<Route> Plan;
// ... in the main
Route r1 = { 4, 5, 2, 10 };
Route r2 = { 1, 3, 8 , 6 };
Route r3 = { 9, 7 };
Plan p = { r1, r2 };
如果我使用set是可以的,但当我尝试使用无序版本时,会收到编译错误。
main.cpp:46:11: error: non-aggregate type 'Route' (aka 'vector<CustomerId>') cannot be initialized with an initializer list
Route r3 = { 9, 7 };
std::unordered_set<std::vector<int>>
这样的东西? - πάντα ῥεῖstd::unordered_set<std::vector<some_type>>
。 - NathanOliverr3
失败了,但Plan
构造函数没有失败? - Barry