我只是在学习图的数据结构。我被困在这种情况下。
我写我的Graph
课就像
template <char... Args>
class Graph{};
其中Args
of 类型char
表示 my 的顶点Graph
。但是,当我想在我的图表中搜索时,我需要将每个顶点char
及其索引Args
作为 astd::pair<char,size_t>
插入到 astd::map<char,size_t>
中。我所做的是我构造了一个std::tuple
like
std::tuple<decltype(Args)...> t(Args...);
然后我想做这样
for(size_t i =0;i<sizeof...(Args);++i)
Map.insert({0,std::get<i>(t)});
其中 Map 表示一个std::map<size_t,char>
. 它当然不起作用,因为i
使用的 instd::get<>
不是constexpr
. 我现在能做的是像一张一张地插入地图
Map.insert({0,std::get<0>(t)});
Map.insert({1,std::get<1>(t)});
Map.insert({2,std::get<2>(t)});
但这不是我想要的结果。那么还有其他适合我的解决方案吗?
谢谢你的帮助!