aboutsummaryrefslogtreecommitdiff
path: root/build2/variable
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-03-16 15:27:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-03-16 15:27:12 +0200
commit20677fb264e743b8e5423af31a7d8dc06cf509f6 (patch)
treef306f7afdff1fc1fc2818d136c631116b8e81c8c /build2/variable
parentcc57e830ac1d85ad588f849d30cdaf54e55ec0d1 (diff)
Cleanup typed variable assignment
Diffstat (limited to 'build2/variable')
-rw-r--r--build2/variable23
1 files changed, 16 insertions, 7 deletions
diff --git a/build2/variable b/build2/variable
index 0c945c7..1a52566 100644
--- a/build2/variable
+++ b/build2/variable
@@ -161,6 +161,12 @@ namespace build2
inline bool
operator!= (const value& x, const value& y) {return !(x == y);}
+ // Assign value type to the value. This triggers the assign callback.
+ //
+ template <typename T>
+ void assign (value&, const variable&);
+ void assign (value&, const value_type*, const variable&);
+
// lookup
//
// A variable can be undefined, NULL, or contain a (potentially
@@ -203,12 +209,8 @@ namespace build2
//
template <typename T> struct value_traits;
- // Assign value type to the value.
+ // Value cast.
//
- template <typename T>
- void assign (value&, const variable&);
- void assign (value&, const value_type*, const variable&);
-
template <typename T> typename value_traits<T>::type as (value&);
template <typename T> typename value_traits<T>::const_type as (const value&);
@@ -758,8 +760,8 @@ namespace build2
return operator[] (var_pool.find (name));
}
- // The second member in the pair indicates whether the new
- // value (which will be NULL) was assigned.
+ // The second member in the pair indicates whether the new value (which
+ // will be NULL) was assigned.
//
pair<reference_wrapper<value>, bool>
assign (const variable& var)
@@ -781,6 +783,13 @@ namespace build2
return assign (var_pool.find (name, type));
}
+ template <typename T>
+ pair<reference_wrapper<value>, bool>
+ assign (const string& name)
+ {
+ return assign (var_pool.find (name, &value_traits<T>::value_type));
+ }
+
pair<const_iterator, const_iterator>
find_namespace (const string& ns) const
{