From 5c369faa461ec4416d2d4b231a5b36963a7315ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 Apr 2016 13:06:50 +0200 Subject: Implement value typing, null support via value attributes For example: v = [null] v = [string] abc v += ABC # abcABC --- build2/variable | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'build2/variable') diff --git a/build2/variable b/build2/variable index 48acfea..10a0f59 100644 --- a/build2/variable +++ b/build2/variable @@ -120,14 +120,16 @@ namespace build2 // // public: - ~value () {if (!null ()) *this = nullptr;} + ~value () {*this = nullptr;} explicit value (const value_type* t = nullptr) : type (t), state (value_state::null) {} + // Note: preserves type. + // value& - operator= (nullptr_t); + operator= (nullptr_t) {if (!null ()) reset (); return *this;} value (value&&); explicit value (const value&); @@ -185,6 +187,10 @@ namespace build2 // Make sure we have sufficient storage for untyped values. // static_assert (sizeof (names) <= size_, "insufficient space"); + + private: + void + reset (); }; // The values should be of the same type (or both be untyped). NULL values -- cgit v1.1