diff --git a/ROADMAP.md b/ROADMAP.md index 6384ac3..43edcb5 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -6,7 +6,6 @@ - fix all includes to work with the library more flexible - remove ctor_type and dtor_type? - add variadic variant of invoking to meta_invoke -- delete rvalue uvalue::as/try_as for pointers ## Version 1.0 diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 60526ee..e773cb1 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -2496,13 +2496,13 @@ namespace meta_hpp template < pointer_kind T > [[nodiscard]] T as() const; - template < non_pointer_kind T > - [[nodiscard]] T as() &&; template < non_pointer_kind T > [[nodiscard]] T& as() &; template < non_pointer_kind T > [[nodiscard]] const T& as() const&; template < non_pointer_kind T > + [[nodiscard]] T as() &&; + template < non_pointer_kind T > [[nodiscard]] const T&& as() const&&; template < pointer_kind T > @@ -2511,9 +2511,13 @@ namespace meta_hpp [[nodiscard]] T try_as() const noexcept; template < non_pointer_kind T > - [[nodiscard]] T* try_as() noexcept; + [[nodiscard]] T* try_as() & noexcept; template < non_pointer_kind T > - [[nodiscard]] const T* try_as() const noexcept; + [[nodiscard]] const T* try_as() const& noexcept; + template < non_pointer_kind T > + void try_as() && = delete; + template < non_pointer_kind T > + void try_as() const&& = delete; private: struct vtable_t; @@ -10635,17 +10639,6 @@ namespace meta_hpp throw_exception(error_code::bad_uvalue_access); } - template < non_pointer_kind T > - T uvalue::as() && { - static_assert(std::is_same_v>); - - if ( T* ptr = try_as() ) { - return std::move(*ptr); - } - - throw_exception(error_code::bad_uvalue_access); - } - template < non_pointer_kind T > T& uvalue::as() & { static_assert(std::is_same_v>); @@ -10668,6 +10661,17 @@ namespace meta_hpp throw_exception(error_code::bad_uvalue_access); } + template < non_pointer_kind T > + T uvalue::as() && { + static_assert(std::is_same_v>); + + if ( T* ptr = try_as() ) { + return std::move(*ptr); + } + + throw_exception(error_code::bad_uvalue_access); + } + template < non_pointer_kind T > const T&& uvalue::as() const&& { static_assert(std::is_same_v>); @@ -10708,7 +10712,7 @@ namespace meta_hpp } template < non_pointer_kind T > - T* uvalue::try_as() noexcept { + T* uvalue::try_as() & noexcept { static_assert(std::is_same_v>); using namespace detail; @@ -10722,7 +10726,7 @@ namespace meta_hpp } template < non_pointer_kind T > - const T* uvalue::try_as() const noexcept { + const T* uvalue::try_as() const& noexcept { static_assert(std::is_same_v>); using namespace detail; diff --git a/develop/untests/meta_utilities/value3_tests.cpp b/develop/untests/meta_utilities/value3_tests.cpp index 988fbf0..c6464d6 100644 --- a/develop/untests/meta_utilities/value3_tests.cpp +++ b/develop/untests/meta_utilities/value3_tests.cpp @@ -224,9 +224,7 @@ TEST_CASE("meta/meta_utilities/value3/try_as") { namespace meta = meta_hpp; static_assert(std::is_same_v().try_as()), derived*>); - static_assert(std::is_same_v().try_as()), derived*>); static_assert(std::is_same_v().try_as()), const derived*>); - static_assert(std::is_same_v().try_as()), const derived*>); static_assert(std::is_same_v().try_as()), derived*>); static_assert(std::is_same_v().try_as()), derived*>); diff --git a/headers/meta.hpp/meta_uvalue.hpp b/headers/meta.hpp/meta_uvalue.hpp index 0cf6cda..a2d0477 100644 --- a/headers/meta.hpp/meta_uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue.hpp @@ -87,13 +87,13 @@ namespace meta_hpp template < pointer_kind T > [[nodiscard]] T as() const; - template < non_pointer_kind T > - [[nodiscard]] T as() &&; template < non_pointer_kind T > [[nodiscard]] T& as() &; template < non_pointer_kind T > [[nodiscard]] const T& as() const&; template < non_pointer_kind T > + [[nodiscard]] T as() &&; + template < non_pointer_kind T > [[nodiscard]] const T&& as() const&&; template < pointer_kind T > @@ -102,9 +102,13 @@ namespace meta_hpp [[nodiscard]] T try_as() const noexcept; template < non_pointer_kind T > - [[nodiscard]] T* try_as() noexcept; + [[nodiscard]] T* try_as() & noexcept; template < non_pointer_kind T > - [[nodiscard]] const T* try_as() const noexcept; + [[nodiscard]] const T* try_as() const& noexcept; + template < non_pointer_kind T > + void try_as() && = delete; + template < non_pointer_kind T > + void try_as() const&& = delete; private: struct vtable_t; diff --git a/headers/meta.hpp/meta_uvalue/uvalue.hpp b/headers/meta.hpp/meta_uvalue/uvalue.hpp index 42cbd5b..fd19485 100644 --- a/headers/meta.hpp/meta_uvalue/uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue/uvalue.hpp @@ -442,17 +442,6 @@ namespace meta_hpp throw_exception(error_code::bad_uvalue_access); } - template < non_pointer_kind T > - T uvalue::as() && { - static_assert(std::is_same_v>); - - if ( T* ptr = try_as() ) { - return std::move(*ptr); - } - - throw_exception(error_code::bad_uvalue_access); - } - template < non_pointer_kind T > T& uvalue::as() & { static_assert(std::is_same_v>); @@ -475,6 +464,17 @@ namespace meta_hpp throw_exception(error_code::bad_uvalue_access); } + template < non_pointer_kind T > + T uvalue::as() && { + static_assert(std::is_same_v>); + + if ( T* ptr = try_as() ) { + return std::move(*ptr); + } + + throw_exception(error_code::bad_uvalue_access); + } + template < non_pointer_kind T > const T&& uvalue::as() const&& { static_assert(std::is_same_v>); @@ -515,7 +515,7 @@ namespace meta_hpp } template < non_pointer_kind T > - T* uvalue::try_as() noexcept { + T* uvalue::try_as() & noexcept { static_assert(std::is_same_v>); using namespace detail; @@ -529,7 +529,7 @@ namespace meta_hpp } template < non_pointer_kind T > - const T* uvalue::try_as() const noexcept { + const T* uvalue::try_as() const& noexcept { static_assert(std::is_same_v>); using namespace detail;