From be14801929cf2a6caced87df034ae12a85f42aa6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 30 Nov 2016 17:32:43 +0200 Subject: Add support for typed/untyped concatenated expansion --- build2/variable.txx | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'build2/variable.txx') diff --git a/build2/variable.txx b/build2/variable.txx index 0678a6a..ab31a45 100644 --- a/build2/variable.txx +++ b/build2/variable.txx @@ -6,9 +6,35 @@ namespace build2 { - // value + // This one will be SFINAE'd out unless T is a simple value. // template + auto + convert (names&& ns) -> + decltype (value_traits::convert (move (ns[0]), nullptr)) + { + size_t n (ns.size ()); + + if (n == 0) + { + if (value_traits::empty_value) + return T (); + } + else if (n == 1) + { + return convert (move (ns[0])); + } + else if (n == 2 && ns[0].pair != '\0') + { + return convert (move (ns[0]), move (ns[1])); + } + + throw invalid_argument ( + string ("invalid ") + value_traits::type_name + + (n == 0 ? " value: empty" : " value: multiple names")); + } + + template void default_dtor (value& v) { @@ -42,13 +68,13 @@ namespace build2 return value_traits::empty (v.as ()); } - template + template void simple_assign (value& v, names&& ns, const variable* var) { size_t n (ns.size ()); - if (empty ? n <= 1 : n == 1) + if (value_traits::empty_value ? n <= 1 : n == 1) { try { @@ -72,13 +98,13 @@ namespace build2 dr << " in variable " << var->name; } - template + template void simple_append (value& v, names&& ns, const variable* var) { size_t n (ns.size ()); - if (empty ? n <= 1 : n == 1) + if (value_traits::empty_value ? n <= 1 : n == 1) { try { @@ -102,13 +128,13 @@ namespace build2 dr << " in variable " << var->name; } - template + template void simple_prepend (value& v, names&& ns, const variable* var) { size_t n (ns.size ()); - if (empty ? n <= 1 : n == 1) + if (value_traits::empty_value ? n <= 1 : n == 1) { try { -- cgit v1.1