From f211934d6ff53388a806c5cc06483e9d843056e4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 27 Jan 2021 06:14:57 +0200 Subject: Make std::map prepend (=+) overriding (like insert_or_assign()) --- libbuild2/variable.hxx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'libbuild2/variable.hxx') diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx index a9dde7f..a04e0a9 100644 --- a/libbuild2/variable.hxx +++ b/libbuild2/variable.hxx @@ -339,15 +339,17 @@ namespace build2 // Assign/Append/Prepend. // public: - // Assign/append a typed value. For assign, LHS should be either of the - // same type or untyped. For append, LHS should be either of the same type - // or untyped and NULL. + // Assign/append/prepend a typed value. For assign, LHS should be either + // of the same type or untyped. For append, LHS should be either of the + // same type or untyped and NULL. // template value& operator= (T); template value& operator+= (T); + template value& prepend (T); value& operator= (names); value& operator+= (names); + //value& prepend (names); // See below. template value& operator= (T* v) { return v != nullptr ? *this = *v : *this = nullptr;} @@ -355,8 +357,12 @@ namespace build2 template value& operator+= (T* v) { return v != nullptr ? *this += *v : *this;} + template value& prepend (T* v) { + return v != nullptr ? prepend (*v) : *this;} + value& operator= (const char* v) {return *this = string (v);} value& operator+= (const char* v) {return *this += string (v);} + value& prepend (const char* v) {return prepend (string (v));} // Assign/append/prepend raw data. Variable is optional and is only used // for diagnostics. @@ -1113,6 +1119,9 @@ namespace build2 // // Either K or V can be optional making the key or value optional. // + // Note that append/+= is non-overriding (like insert()) while prepend/=+ + // is (like insert_or_assign()). + // template struct map_value_type; @@ -1125,8 +1134,7 @@ namespace build2 static void assign (value&, map&&); static void append (value&, map&&); - static void prepend (value& v, map&& x) { - return append (v, move (x));} + static void prepend (value&, map&&); static bool empty (const map& x) {return x.empty ();} static const map empty_instance; @@ -1156,6 +1164,9 @@ namespace build2 value_traits, string>>>; extern template struct LIBBUILD2_DECEXPORT + value_traits>>>; + + extern template struct LIBBUILD2_DECEXPORT value_traits>; extern template struct LIBBUILD2_DECEXPORT @@ -1165,6 +1176,9 @@ namespace build2 value_traits, string>>; extern template struct LIBBUILD2_DECEXPORT + value_traits>>; + + extern template struct LIBBUILD2_DECEXPORT value_traits>; // var_subprojects // Project-wide (as opposed to global) variable overrides (see context ctor -- cgit v1.1