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.hxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libbuild2/variable.hxx') diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx index d67098e..b157806 100644 --- a/libbuild2/variable.hxx +++ b/libbuild2/variable.hxx @@ -1177,6 +1177,26 @@ namespace build2 static const pair_vector_value_type value_type; }; + // set + // + template + struct set_value_type; + + template + struct value_traits> + { + static_assert (sizeof (set) <= value::size_, "insufficient space"); + + static set convert (names&&); + static void assign (value&, set&&); + static void append (value&, set&&); + static void prepend (value&, set&&); + static bool empty (const set& x) {return x.empty ();} + + static const set empty_instance; + static const set_value_type value_type; + }; + // map // // Either K or V can be optional making the key or value optional. @@ -1321,6 +1341,8 @@ namespace build2 extern template struct LIBBUILD2_DECEXPORT value_traits>>>; + extern template struct LIBBUILD2_DECEXPORT value_traits>; + extern template struct LIBBUILD2_DECEXPORT value_traits>; -- cgit v1.1