aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/variable.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-08-24 10:51:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-08-24 10:51:26 +0200
commitb86c1d8d2e0be140f6854d869e07139ff3c4221c (patch)
tree02b38914484afb6c2a69d041cf026f1d377220bf /libbuild2/variable.txx
parentb2df0b0663d0537dd3b4f2d28d145ccd90417cab (diff)
Add copying version of convert<T>(value)
Diffstat (limited to 'libbuild2/variable.txx')
-rw-r--r--libbuild2/variable.txx22
1 files changed, 14 insertions, 8 deletions
diff --git a/libbuild2/variable.txx b/libbuild2/variable.txx
index 51176ae..0e10e87 100644
--- a/libbuild2/variable.txx
+++ b/libbuild2/variable.txx
@@ -55,6 +55,9 @@ namespace build2
(n == 0 ? " value: empty" : " value: multiple names"));
}
+ [[noreturn]] void
+ convert_throw (const value_type* from, const value_type& to);
+
template <typename T>
T
convert (value&& v)
@@ -67,19 +70,22 @@ namespace build2
return move (v).as<T> ();
}
- string m ("invalid ");
- m += value_traits<T>::value_type.name;
- m += " value: ";
+ convert_throw (v ? v.type : nullptr, value_traits<T>::value_type);
+ }
+ template <typename T>
+ T
+ convert (const value& v)
+ {
if (v)
{
- m += "conversion from ";
- m += v.type->name;
+ if (v.type == nullptr)
+ return convert<T> (names (v.as<names> ()));
+ else if (v.type == &value_traits<T>::value_type)
+ return v.as<T> ();
}
- else
- m += "null";
- throw invalid_argument (move (m));
+ convert_throw (v ? v.type : nullptr, value_traits<T>::value_type);
}
template <typename T>