diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-05-20 12:23:58 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-05-20 12:23:58 +0200 |
commit | fd94c6f239d2436b6152935b4c99217129953a5d (patch) | |
tree | c9ebef4ec79371ae02d24a9817797baa3447f20b /libbuild2/variable.hxx | |
parent | 2fc53c801eb551154f0a2aa96522cf3182a65b7a (diff) |
Add convert_to_base<T>(value) variants that allow derive-to-base conversion
Diffstat (limited to 'libbuild2/variable.hxx')
-rw-r--r-- | libbuild2/variable.hxx | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx index aed3350..6dfbbc6 100644 --- a/libbuild2/variable.hxx +++ b/libbuild2/variable.hxx @@ -92,6 +92,9 @@ namespace build2 // static_cast to const T*. If it is NULL, then cast data_ directly. Note // that this function is used for both const and non-const values. // + // @@ This is currently ignored by as<T>() which is now used in quite a + // few places (in particular, grep for as<T>). + // const void* (*const cast) (const value&, const value_type*); // If NULL, then the types are compared as PODs using memcmp(). @@ -702,14 +705,18 @@ namespace build2 template <typename T> T convert (names&&); // Convert value to T. If value is already of type T, then simply cast it. - // Otherwise call convert(names) above. If value is NULL, then throw - // invalid_argument (with an appropriate message). + // Otherwise call convert(names) above. If the value is NULL, then throw + // invalid_argument (with an appropriate message). See also + // convert_to_base() below. // template <typename T> T convert (value&&); + template <typename T> T convert (const value&); - // As above but preserving the value. + // As above but also allow the derived-to-base conversions (where T is + // base). Note that this call may potentially slice the value. // - template <typename T> T convert (const value&); + template <typename T> T convert_to_base (value&&); + template <typename T> T convert_to_base (const value&); // Default implementations of the dtor/copy_ctor/copy_assing callbacks for // types that are stored directly in value::data_ and the provide all the |