fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <tuple>
  4. #include <utility>
  5. #include <unordered_map>
  6.  
  7. typedef std::tuple<std::string,int,char> key_t;
  8.  
  9. struct key_hash : public std::unary_function<key_t, std::size_t>
  10. {
  11. std::size_t operator()(const key_t& k) const
  12. {
  13. return std::get<0>(k)[0] ^ std::get<1>(k) ^ std::get<2>(k);
  14. }
  15. };
  16.  
  17. struct key_equal : public std::binary_function<key_t, key_t, bool>
  18. {
  19. bool operator()(const key_t& v0, const key_t& v1) const
  20. {
  21. return (
  22. std::get<0>(v0) == std::get<0>(v1) &&
  23. std::get<1>(v0) == std::get<1>(v1) &&
  24. std::get<2>(v0) == std::get<2>(v1)
  25. );
  26. }
  27. };
  28.  
  29. struct data
  30. {
  31. std::string x;
  32. };
  33.  
  34. typedef std::unordered_map<const key_t,data,key_hash,key_equal> map_t;
  35.  
  36.  
  37. int main()
  38. {
  39. map_t m;
  40. data d;
  41. d.x = "test data";
  42. m[std::make_tuple("abc",1,'X')] = d;
  43. auto itr = m.find(std::make_tuple(std::string("abc"),1,'X'));
  44. if (m.end() != itr)
  45. {
  46. std::cout << "x: " << itr->second.x;
  47. }
  48. return 0;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:7:42: error: conflicting declaration 'typedef class std::tuple<std::basic_string<char>, int, char> key_t'
/usr/include/sys/types.h:123:17: error: 'key_t' has a previous declaration as 'typedef __key_t key_t'
prog.cpp: In member function 'size_t key_hash::operator()(const key_t&) const':
prog.cpp:13:27: error: no matching function for call to 'get(const key_t&)'
prog.cpp:13:47: error: no matching function for call to 'get(const key_t&)'
prog.cpp:13:64: error: no matching function for call to 'get(const key_t&)'
prog.cpp: In member function 'bool key_equal::operator()(const key_t&, const key_t&) const':
prog.cpp:22:30: error: no matching function for call to 'get(const key_t&)'
prog.cpp:22:49: error: no matching function for call to 'get(const key_t&)'
prog.cpp:23:30: error: no matching function for call to 'get(const key_t&)'
prog.cpp:23:49: error: no matching function for call to 'get(const key_t&)'
prog.cpp:24:30: error: no matching function for call to 'get(const key_t&)'
prog.cpp:24:49: error: no matching function for call to 'get(const key_t&)'
prog.cpp: In function 'int main()':
prog.cpp:42:34: error: no match for 'operator[]' in 'm[std::make_tuple(_Elements&& ...) [with _Elements = {const char (&)[4], int, char}, typename std::__decay_and_strip<_Elements>::__type = <type error>](((int&&)(&1)), ((char&&)(&'X')))]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/hashtable_policy.h:531:5: note: candidate is: std::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type& std::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::operator[](const _Key&) [with _Key = const int, _Pair = std::pair<const int, data>, _Hashtable = std::_Hashtable<const int, std::pair<const int, data>, std::allocator<std::pair<const int, data> >, std::_Select1st<std::pair<const int, data> >, key_equal, key_hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true>, std::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type = data]
prog.cpp:43:63: error: no matching function for call to 'std::unordered_map<const int, data, key_hash, key_equal>::find(std::tuple<std::basic_string<char>, int, char>)'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/hashtable.h:741:5: note: candidates are: std::_Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys>::iterator std::_Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys>::find(const key_type&) [with _Key = const int, _Value = std::pair<const int, data>, _Allocator = std::allocator<std::pair<const int, data> >, _ExtractKey = std::_Select1st<std::pair<const int, data> >, _Equal = key_equal, _H1 = key_hash, _H2 = std::__detail::_Mod_range_hashing, _Hash = std::__detail::_Default_ranged_hash, _RehashPolicy = std::__detail::_Prime_rehash_policy, bool __cache_hash_code = false, bool __constant_iterators = false, bool __unique_keys = true, std::_Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys>::iterator = std::__detail::_Hashtable_iterator<std::pair<const int, data>, false, false>, key_type = const int]
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/hashtable.h:758:5: note:                 std::_Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys>::const_iterator std::_Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys>::find(const key_type&) const [with _Key = const int, _Value = std::pair<const int, data>, _Allocator = std::allocator<std::pair<const int, data> >, _ExtractKey = std::_Select1st<std::pair<const int, data> >, _Equal = key_equal, _H1 = key_hash, _H2 = std::__detail::_Mod_range_hashing, _Hash = std::__detail::_Default_ranged_hash, _RehashPolicy = std::__detail::_Prime_rehash_policy, bool __cache_hash_code = false, bool __constant_iterators = false, bool __unique_keys = true, std::_Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys>::const_iterator = std::__detail::_Hashtable_const_iterator<std::pair<const int, data>, false, false>, key_type = const int]
prog.cpp:43:63: error: unable to deduce 'auto' from '<expression error>'
stdout
Standard output is empty