From 2c8294b069f5df30d281e0f4f580f6f313a50eb2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 Dec 2017 12:39:33 +0200 Subject: Add cast_empty() for value casting --- build2/variable.hxx | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'build2/variable.hxx') diff --git a/build2/variable.hxx b/build2/variable.hxx index c5e1a13..9a58584 100644 --- a/build2/variable.hxx +++ b/build2/variable.hxx @@ -289,6 +289,12 @@ namespace build2 template const T* cast_null (const value&); template const T* cast_null (const lookup&); + // As above but returns empty value if the value is NULL (or not defined, in + // case of lookup). + // + template const T& cast_empty (const value&); + template const T& cast_empty (const lookup&); + // As above but returns false/true if the value is NULL (or not defined, // in case of lookup). Note that the template argument is only for // documentation and should be bool (or semantically compatible). @@ -433,6 +439,8 @@ namespace build2 // // // static const bool empty_value = true; // + // static const T empty_instance; + // // // For simple types (those that can be used as elements of containers), // // type_name must be constexpr in order to sidestep the static init // // order issue (in fact, that's the only reason we have it both here @@ -579,6 +587,7 @@ namespace build2 static bool empty (const string& x) {return x.empty ();} static const bool empty_value = true; + static const string& empty_instance; static const char* const type_name; static const build2::value_type value_type; }; @@ -608,6 +617,7 @@ namespace build2 static bool empty (const path& x) {return x.empty ();} static const bool empty_value = true; + static const path& empty_instance; static const char* const type_name; static const build2::value_type value_type; }; @@ -628,6 +638,7 @@ namespace build2 static bool empty (const dir_path& x) {return x.empty ();} static const bool empty_value = true; + static const dir_path& empty_instance; static const char* const type_name; static const build2::value_type value_type; }; -- cgit v1.1