23 #include <type_traits>
24 #include <unordered_map>
39 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ <= 7) && \
40 defined(__GLIBCXX__) && !defined(__clang__)
42 template <
typename MAP_TYPE_CONT,
typename FIRST,
typename SECOND>
43 inline std::pair<typename MAP_TYPE_CONT::iterator, bool> try_emplace(
44 MAP_TYPE_CONT& map_type_cont, FIRST&& first, SECOND&& second) {
45 return map_type_cont.insert(
46 std::make_pair(std::forward<FIRST>(first), std::forward<SECOND>(second)));
49 template <
typename MAP_TYPE_CONT,
typename FIRST,
typename SECOND,
51 inline std::pair<typename MAP_TYPE_CONT::iterator, bool> try_emplace(
52 MAP_TYPE_CONT& map_type_cont, FIRST&& first, SECOND&& second,
54 return map_type_cont.insert(std::make_pair(
55 std::forward<FIRST>(first),
56 typename MAP_TYPE_CONT::mapped_type(std::forward<SECOND>(second),
57 std::forward<ARGS>(args)...)));
63 struct IsMap :
public std::false_type {};
65 template <
class... ARGS>
66 struct IsMap<std::map<ARGS...> > :
public std::true_type {};
71 template <
class... ARGS>
72 struct IsUnorderedMap<std::unordered_map<ARGS...> > :
public std::true_type {};
76 template <
class MAP_TYPE_CONT,
class... ARGS>
77 inline typename std::enable_if<
79 std::pair<typename MAP_TYPE_CONT::iterator, bool> >::type
80 try_emplace(MAP_TYPE_CONT& map_type_cont,
81 typename MAP_TYPE_CONT::key_type&& key, ARGS&&... args) {
82 auto it = map_type_cont.lower_bound(key);
83 if (it == map_type_cont.end() || map_type_cont.key_comp()(key, it->first)) {
84 return {map_type_cont.emplace_hint(
85 it, std::piecewise_construct,
86 std::forward_as_tuple(
87 std::forward<typename MAP_TYPE_CONT::key_type>(key)),
88 std::forward_as_tuple(std::forward<ARGS>(args)...)),
94 template <
class MAP_TYPE_CONT,
class... ARGS>
95 inline typename std::enable_if<
96 IsMap<MAP_TYPE_CONT>::value,
97 std::pair<typename MAP_TYPE_CONT::iterator, bool> >::type
98 try_emplace(MAP_TYPE_CONT& map_type_cont,
99 const typename MAP_TYPE_CONT::key_type& key, ARGS&&... args) {
100 auto it = map_type_cont.lower_bound(key);
101 if (it == map_type_cont.end() || map_type_cont.key_comp()(key, it->first)) {
102 return {map_type_cont.emplace_hint(
103 it, std::piecewise_construct, std::forward_as_tuple(key),
104 std::forward_as_tuple(std::forward<ARGS>(args)...)),
112 template <
class MAP_TYPE_CONT,
class... ARGS>
113 inline typename std::enable_if<
114 IsUnorderedMap<MAP_TYPE_CONT>::value,
115 std::pair<typename MAP_TYPE_CONT::iterator, bool> >::type
116 try_emplace(MAP_TYPE_CONT& map_type_cont,
117 typename MAP_TYPE_CONT::key_type&& key, ARGS&&... args) {
118 auto it = map_type_cont.find(key);
119 if (it == map_type_cont.end()) {
120 return map_type_cont.emplace(
121 std::piecewise_construct,
122 std::forward_as_tuple(
123 std::forward<typename MAP_TYPE_CONT::key_type>(key)),
124 std::forward_as_tuple(std::forward<ARGS>(args)...));
129 template <
class MAP_TYPE_CONT,
class... ARGS>
130 inline typename std::enable_if<
131 IsUnorderedMap<MAP_TYPE_CONT>::value,
132 std::pair<typename MAP_TYPE_CONT::iterator, bool> >::type
133 try_emplace(MAP_TYPE_CONT& map_type_cont,
134 const typename MAP_TYPE_CONT::key_type& key, ARGS&&... args) {
135 auto it = map_type_cont.find(key);
136 if (it == map_type_cont.end()) {
137 return map_type_cont.emplace(
138 std::piecewise_construct, std::forward_as_tuple(key),
139 std::forward_as_tuple(std::forward<ARGS>(args)...));
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
Definition: try_emplace.h:63
Definition: try_emplace.h:69