From 88640e677fa0695783eac68014d7d8d5bc42d117 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 19 Feb 2024 12:23:10 +0200 Subject: Add string_set buildfile value type This exposes the std::set type to buildfiles. New functions: $size() Subscript returns true if the value is present and false otherwise (so it is mapped to std::set::contains()). For example: set = [string_set] a b c if ($set[b]) ... Note that append (+=) and prepend (=+) have the same semantics (std::set::insert()). For example: set = [string_set] a b set += c b # a b c set =+ d b # a b c d Example of iteration: set = [string_set] a b c for k: $set ... --- libbuild2/variable.ixx | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'libbuild2/variable.ixx') diff --git a/libbuild2/variable.ixx b/libbuild2/variable.ixx index b8f80e3..a448cd8 100644 --- a/libbuild2/variable.ixx +++ b/libbuild2/variable.ixx @@ -853,6 +853,44 @@ namespace build2 new (&v.data_) vector> (move (x)); } + // set value + // + template + inline void value_traits>:: + assign (value& v, set&& x) + { + if (v) + v.as> () = move (x); + else + new (&v.data_) set (move (x)); + } + + template + inline void value_traits>:: + append (value& v, set&& x) + { + if (v) + { + set& p (v.as> ()); + + if (p.empty ()) + p.swap (x); + else + // Keys (being const) can only be copied. + // + p.insert (x.begin (), x.end ()); + } + else + new (&v.data_) set (move (x)); + } + + template + inline void value_traits>:: + prepend (value& v, set&& x) + { + append (v, move (x)); + } + // map value // template -- cgit v1.1