aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/scope.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/scope.hxx')
-rw-r--r--libbuild2/scope.hxx65
1 files changed, 39 insertions, 26 deletions
diff --git a/libbuild2/scope.hxx b/libbuild2/scope.hxx
index 39be143..e1cdf78 100644
--- a/libbuild2/scope.hxx
+++ b/libbuild2/scope.hxx
@@ -187,6 +187,22 @@ namespace build2
value&
assign (const variable* var) {return vars.assign (var);} // For cached.
+ template <typename T>
+ T&
+ assign (const variable& var, T&& val)
+ {
+ value& v (assign (var) = forward<T> (val));
+ return v.as<T> ();
+ }
+
+ template <typename T>
+ T&
+ assign (const variable* var, T&& val)
+ {
+ value& v (assign (var) = forward<T> (val));
+ return v.as<T> ();
+ }
+
// Assign an untyped non-overridable variable with project visibility.
//
value&
@@ -195,47 +211,44 @@ namespace build2
return assign (var_pool ().insert (move (name)));
}
- // As above, but assign a typed variable.
+ // As above, but assign a typed variable (note: variable type must be
+ // specified explicitly).
//
- template <typename T>
+ template <typename V>
value&
assign (string name)
{
- return vars.assign (var_pool ().insert<T> (move (name)));
+ return vars.assign (var_pool ().insert<V> (move (name)));
}
- template <typename T>
- T&
+ template <typename V, typename T>
+ V&
assign (string name, T&& val)
{
- value& v (assign<T> (move (name)) = forward<T> (val));
- return v.as<T> ();
+ value& v (assign<V> (move (name)) = forward<T> (val));
+ return v.as<V> ();
}
- template <typename T>
- T&
- assign (const variable& var, T&& val)
- {
- value& v (assign (var) = forward<T> (val));
- return v.as<T> ();
- }
+ // Return a value suitable for appending. If the variable does not exist
+ // in this scope's map, then outer scopes are searched for the same
+ // variable. If found then a new variable with the found value is added to
+ // this scope and returned. Otherwise this function proceeds as assign().
+ //
+ value&
+ append (const variable&);
- template <typename T>
- T&
- assign (const variable* var, T&& val)
+ value&
+ append (string name)
{
- value& v (assign (var) = forward<T> (val));
- return v.as<T> ();
+ return append (var_pool ().insert (move (name)));
}
- // Return a value suitable for appending. If the variable does not
- // exist in this scope's map, then outer scopes are searched for
- // the same variable. If found then a new variable with the found
- // value is added to this scope and returned. Otherwise this
- // function proceeds as assign().
- //
+ template <typename V>
value&
- append (const variable&);
+ append (string name)
+ {
+ return append (var_pool ().insert<V> (move (name)));
+ }
// Target type/pattern-specific variables.
//