[map] Support moving value in sink interface
This commit is contained in:
parent
1bf9afaad0
commit
a9c6a20b19
|
@ -496,7 +496,7 @@ struct hb_pair_t
|
|||
hb_enable_if (std::is_default_constructible<U1>::value &&
|
||||
std::is_default_constructible<U2>::value)>
|
||||
hb_pair_t () : first (), second () {}
|
||||
hb_pair_t (T1 a, T2 b) : first (a), second (b) {}
|
||||
hb_pair_t (T1 a, T2 b) : first (std::forward<T1> (a)), second (std::forward<T2> (b)) {}
|
||||
|
||||
template <typename Q1, typename Q2,
|
||||
hb_enable_if (hb_is_convertible (T1, Q1) &&
|
||||
|
|
|
@ -315,6 +315,8 @@ struct hb_hashmap_t
|
|||
/* Sink interface. */
|
||||
hb_hashmap_t& operator << (const hb_pair_t<K, V>& v)
|
||||
{ set (v.first, v.second); return *this; }
|
||||
hb_hashmap_t& operator << (const hb_pair_t<K, V&&>& v)
|
||||
{ set (v.first, std::move (v.second)); return *this; }
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -179,10 +179,18 @@ main (int argc, char **argv)
|
|||
|
||||
hb_hashmap_t<vector_t, vector_t> m1;
|
||||
|
||||
m1 << hb_pair_t<vector_t, vector_t> {vector_t (), vector_t ()};
|
||||
m1.set (vector_t (), vector_t {1});
|
||||
m1.set (vector_t {1}, vector_t {2});
|
||||
|
||||
m1 << hb_pair_t<vector_t, vector_t> {vector_t {2}, vector_t ()};
|
||||
|
||||
vector_t v {3};
|
||||
assert (v.length == 1);
|
||||
m1 << hb_pair_t<vector_t, vector_t> {vector_t {3}, v};
|
||||
assert (v.length == 1);
|
||||
m1 << hb_pair_t<vector_t, vector_t&&> {vector_t {4}, std::move (v)};
|
||||
assert (v.length == 0);
|
||||
|
||||
assert (m1.get (vector_t ()) == vector_t {1});
|
||||
assert (m1.get (vector_t {1}) == vector_t {2});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue