小编Leo*_*adt的帖子

unordered_map/unordered_set中元组的通用哈希

为什么不std::unordered_map<tuple<int, int>, string>开箱即用?必须为tuple<int, int>例如定义散列函数是繁琐的

template<> struct do_hash<tuple<int, int>>                               
{   size_t operator()(std::tuple<int, int> const& tt) const {...}  }; 
Run Code Online (Sandbox Code Playgroud)

构建一个以元组为键的无序映射(Matthieu M.)展示了如何自动执行此操作boost::tuple.有没有为c ++ 0x元组执行此操作而不使用可变参数模板?

当然这应该在标准:(

c++ unordered-map tuples unordered-set c++11

27
推荐指数
4
解决办法
2万
查看次数

emplace 和 unordered_map&lt;?, std::array&lt;?, N&gt;&gt;

我有一个std::unordered_map<string, std::array<int, 2>>. emplace将值放入地图的语法是什么?

unordered_map<string, array<int, 2>> contig_sizes;
string key{"key"};
array<int, 2> value{1, 2};

// OK ---1
contig_sizes.emplace(key, value);

// OK --- 2
contig_sizes.emplace(key, std::array<int, 2>{1, 2});

// compile error --3
//contig_sizes.emplace(key, {{1,2}});

// OK --4 (Nathan Oliver)
// Very inefficient results in two!!! extra copy c'tor
contig_sizes.insert({key, {1,2}});

// OK --5
// One extra move c'tor followed by one extra copy c'tor
contig_sizes.insert({key, std::array<int, 2>{1,2}});

// OK --6 
// Two extra move constructors
contig_sizes.insert(pair<const string, array<int, …
Run Code Online (Sandbox Code Playgroud)

c++ dictionary unordered-map stdarray emplace

3
推荐指数
1
解决办法
1403
查看次数