27 #ifndef __KEYVALUEPAIR__ 28 #define __KEYVALUEPAIR__ 30 #include <adobe/move.hpp> 31 #include <adobe/typeinfo.hpp> 37 template <
class _T1,
class _T2>
42 typedef _T2 value_type;
49 : fKey(adobe::move(other.source.fKey)), fValue(adobe::move(other.source.fValue)) {}
52 : fKey(adobe::move(__a)), fValue(adobe::move(__b)) {}
63 swap(a.fValue, b.fValue);
72 _T1&
Key() {
return fKey; }
82 const _T1&
Key()
const {
return fKey; }
87 const _T2&
Value()
const {
return fValue; }
92 void SetValue(
const _T2& val) { fValue = val; }
103 template <class _T1, class _T2>
118 template <
class _T1,
class _T2>
121 return __x.
Key() == __y;
133 template <
class _T1,
class _T2>
136 return __x.
Key() == __y;
145 template <
class _T1,
class _T2>
148 return __x.
Key() < __y.Key();
156 template <
class _T1,
class _T2>
157 inline bool operator<(const KeyValuePair<_T1, _T2>& __x,
const _T1& __y)
159 return __x.
Key() < __y;
167 template <
class _T1,
class _T2>
168 inline bool operator<(const _T1& __y, const KeyValuePair<_T1, _T2>& __x)
170 return __y < __x.Key();
178 template <
class _T1,
class _T2>
180 return !(__x == __y);
188 template <
class _T1,
class _T2>
198 template <
class _T1,
class _T2>
208 template <
class _T1,
class _T2>
218 template <
class _T1,
class _T2>
227 bool operator()(
const T& lhs,
const T& rhs)
229 return lhs.fKey < rhs.fKey;
235 template <
class Key,
class Value>
257 template <
class Key,
class Container>
258 int32 FindLocation(
const Container& cont,
const Key& key)
260 typedef typename Container::value_type KVP;
261 typedef typename KVP::value_type Value;
264 return cont.end() == p ? -1 : p - cont.begin();
271 template <
class Key,
class Value>
284 template <
class Value,
class Container>
285 int32 FindLocationByValue(
const Container& cont,
const Value& value)
287 typedef typename Container::value_type KVP;
288 typedef typename KVP::key_type Key;
291 return cont.end() == p ? -1 : p - cont.begin();
301 template <
class Key,
class Value,
class Container>
302 void InsertKeyValue(Container& cont,
const Key& key,
const Value& val)
315 template <
class Key,
class Value,
class Container>
316 void InsertOrReplaceKeyValue(Container& cont,
const Key& key,
const Value& val)
318 typename Container::iterator p = K2find(cont.begin(), cont.end(), key);
331 template <
class Value,
class Container>
332 int32 InsertInSorted(Container& c,
const Value& t)
334 typename Container::iterator i = std::lower_bound(c.begin(), c.end(), t);
336 return i - c.begin();
345 template <
class Key,
class Value,
class Container>
346 int32 InsertKeyValueInSorted(Container& c,
const Key& k,
const Value& v)
350 typename Container::iterator i = std::lower_bound(c.begin(), c.end(), el);
351 ASSERT(i == c.end() || *i != el);
353 return i - c.begin();
362 template <
class Key,
class Value,
class Container>
363 int32 InsertOrReplaceKeyValueInSorted(Container& c,
const Key& k,
const Value& v)
365 typename Container::iterator i = std::lower_bound(c.begin(), c.end(), k);
366 if (i == c.end() || i->Key() != k)
370 return i - c.begin();
378 template <
class Key,
class Container>
379 int32 FindLocationInSorted(
const Container& c,
const Key& k)
381 typename Container::const_iterator i = std::lower_bound(c.begin(), c.end(), k);
382 return (i != c.end() && *i == k) ? (i - c.begin()) : -1;