aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/variable.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-01-27 06:14:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-01-28 08:01:04 +0200
commitf211934d6ff53388a806c5cc06483e9d843056e4 (patch)
tree5085f616fe013fac6274e760b8e6c4c893fab4c1 /libbuild2/variable.ixx
parentac03ae75f46196c09cec0e3e45f401dc59faee73 (diff)
Make std::map prepend (=+) overriding (like insert_or_assign())
Diffstat (limited to 'libbuild2/variable.ixx')
-rw-r--r--libbuild2/variable.ixx36
1 files changed, 36 insertions, 0 deletions
diff --git a/libbuild2/variable.ixx b/libbuild2/variable.ixx
index 9b24b9d..fd78842 100644
--- a/libbuild2/variable.ixx
+++ b/libbuild2/variable.ixx
@@ -114,6 +114,22 @@ namespace build2
return *this;
}
+ template <typename T>
+ inline value& value::
+ prepend (T v)
+ {
+ assert (type == &value_traits<T>::value_type || (type == nullptr && null));
+
+ // Prepare the receiving value.
+ //
+ if (type == nullptr)
+ type = &value_traits<T>::value_type;
+
+ value_traits<T>::prepend (*this, move (v));
+ null = false;
+ return *this;
+ }
+
inline value& value::
operator= (names v)
{
@@ -867,6 +883,26 @@ namespace build2
new (&v.data_) map<K, V> (move (x));
}
+ template <typename K, typename V>
+ inline void value_traits<std::map<K, V>>::
+ prepend (value& v, map<K, V>&& x)
+ {
+ if (v)
+ {
+ map<K, V>& m (v.as<map<K, V>> ());
+
+ m.swap (x);
+
+ // Note that this will only move values. Keys (being const) are still
+ // copied.
+ //
+ m.insert (make_move_iterator (x.begin ()),
+ make_move_iterator (x.end ()));
+ }
+ else
+ new (&v.data_) map<K, V> (move (x));
+ }
+
// variable_pool
//
inline const variable& variable_pool::