diff --git a/headers/meta.hpp/meta_detail/value_traits/deref_traits.hpp b/headers/meta.hpp/meta_detail/value_traits/deref_traits.hpp index 83b9ea9..0d73557 100644 --- a/headers/meta.hpp/meta_detail/value_traits/deref_traits.hpp +++ b/headers/meta.hpp/meta_detail/value_traits/deref_traits.hpp @@ -22,28 +22,32 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits { uvalue operator()(T* v) const { return uvalue{*v}; } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits { uvalue operator()(const T* v) const { return uvalue{*v}; } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits> { uvalue operator()(const std::shared_ptr& v) const { return uvalue{*v}; } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits> { uvalue operator()(const std::unique_ptr& v) const { return uvalue{*v}; diff --git a/headers/meta.hpp/meta_detail/value_traits/index_traits.hpp b/headers/meta.hpp/meta_detail/value_traits/index_traits.hpp index f46f722..0bc517a 100644 --- a/headers/meta.hpp/meta_detail/value_traits/index_traits.hpp +++ b/headers/meta.hpp/meta_detail/value_traits/index_traits.hpp @@ -22,7 +22,8 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct index_traits { uvalue operator()(T* v, std::size_t i) const { // NOLINTNEXTLINE(*-pointer-arithmetic) @@ -30,7 +31,8 @@ namespace meta_hpp::detail } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct index_traits { uvalue operator()(const T* v, std::size_t i) const { // NOLINTNEXTLINE(*-pointer-arithmetic) @@ -38,28 +40,32 @@ namespace meta_hpp::detail } }; - template < std::copy_constructible T, std::size_t Size > + template < typename T, std::size_t Size > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::array& v, std::size_t i) const { return uvalue{v[i]}; } }; - template < std::copy_constructible T, std::size_t Extent > + template < typename T, std::size_t Extent > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::span& v, std::size_t i) const { return uvalue{v[i]}; } }; - template < std::copy_constructible T, typename Traits, typename Allocator > + template < typename T, typename Traits, typename Allocator > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::basic_string& v, std::size_t i) const { return uvalue{v[i]}; } }; - template < std::copy_constructible T, typename Allocator > + template < typename T, typename Allocator > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::vector& v, std::size_t i) { return uvalue{v[i]}; diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 875ede7..5283ce5 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -21,7 +21,7 @@ namespace meta_hpp::detail using argument_types = typename ct::argument_types; constexpr bool as_object = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_raw_ptr = diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 2b19e78..dbd5120 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -21,7 +21,7 @@ namespace meta_hpp::detail using argument_types = typename ft::argument_types; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_void = diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index 31e571e..6e52ef2 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -22,7 +22,7 @@ namespace meta_hpp::detail using value_type = typename mt::value_type; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_ptr = diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index 5e552d5..09c222c 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -23,7 +23,7 @@ namespace meta_hpp::detail using argument_types = typename mt::argument_types; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_void = diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 070ee6d..26b6b84 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -20,7 +20,7 @@ namespace meta_hpp::detail using data_type = typename pt::data_type; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_ptr = diff --git a/headers/meta.hpp/meta_uvalue.hpp b/headers/meta.hpp/meta_uvalue.hpp index f4cc7eb..86b008f 100644 --- a/headers/meta.hpp/meta_uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue.hpp @@ -38,12 +38,12 @@ namespace meta_hpp uvalue& operator=(const uvalue& other); template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> // NOLINTNEXTLINE(*-forwarding-reference-overload) explicit uvalue(T&& val); template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> uvalue& operator=(T&& val); [[nodiscard]] bool is_valid() const noexcept; diff --git a/headers/meta.hpp/meta_uvalue/uvalue.hpp b/headers/meta.hpp/meta_uvalue/uvalue.hpp index 977a8db..b44d145 100644 --- a/headers/meta.hpp/meta_uvalue/uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue/uvalue.hpp @@ -271,14 +271,14 @@ namespace meta_hpp } template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> // NOLINTNEXTLINE(*-forwarding-reference-overload) uvalue::uvalue(T&& val) { vtable_t::construct(*this, std::forward(val)); } template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> uvalue& uvalue::operator=(T&& val) { uvalue{std::forward(val)}.swap(*this); return *this; diff --git a/singles/headers/meta.hpp/meta_all.hpp b/singles/headers/meta.hpp/meta_all.hpp index 6da184e..df7c733 100644 --- a/singles/headers/meta.hpp/meta_all.hpp +++ b/singles/headers/meta.hpp/meta_all.hpp @@ -2212,12 +2212,12 @@ namespace meta_hpp uvalue& operator=(const uvalue& other); template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> // NOLINTNEXTLINE(*-forwarding-reference-overload) explicit uvalue(T&& val); template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> uvalue& operator=(T&& val); [[nodiscard]] bool is_valid() const noexcept; @@ -5115,7 +5115,7 @@ namespace meta_hpp::detail using argument_types = typename ct::argument_types; constexpr bool as_object = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_raw_ptr = @@ -5641,7 +5641,7 @@ namespace meta_hpp::detail using argument_types = typename ft::argument_types; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_void = @@ -6118,7 +6118,7 @@ namespace meta_hpp::detail using value_type = typename mt::value_type; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_ptr = @@ -6415,7 +6415,7 @@ namespace meta_hpp::detail using argument_types = typename mt::argument_types; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_void = @@ -6664,7 +6664,7 @@ namespace meta_hpp::detail using data_type = typename pt::data_type; constexpr bool as_copy = - std::copy_constructible && + std::is_copy_constructible_v && std::same_as; constexpr bool as_ptr = @@ -7831,28 +7831,32 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits { uvalue operator()(T* v) const { return uvalue{*v}; } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits { uvalue operator()(const T* v) const { return uvalue{*v}; } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits> { uvalue operator()(const std::shared_ptr& v) const { return uvalue{*v}; } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct deref_traits> { uvalue operator()(const std::unique_ptr& v) const { return uvalue{*v}; @@ -7897,7 +7901,8 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct index_traits { uvalue operator()(T* v, std::size_t i) const { // NOLINTNEXTLINE(*-pointer-arithmetic) @@ -7905,7 +7910,8 @@ namespace meta_hpp::detail } }; - template < std::copy_constructible T > + template < typename T > + requires std::is_copy_constructible_v struct index_traits { uvalue operator()(const T* v, std::size_t i) const { // NOLINTNEXTLINE(*-pointer-arithmetic) @@ -7913,28 +7919,32 @@ namespace meta_hpp::detail } }; - template < std::copy_constructible T, std::size_t Size > + template < typename T, std::size_t Size > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::array& v, std::size_t i) const { return uvalue{v[i]}; } }; - template < std::copy_constructible T, std::size_t Extent > + template < typename T, std::size_t Extent > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::span& v, std::size_t i) const { return uvalue{v[i]}; } }; - template < std::copy_constructible T, typename Traits, typename Allocator > + template < typename T, typename Traits, typename Allocator > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::basic_string& v, std::size_t i) const { return uvalue{v[i]}; } }; - template < std::copy_constructible T, typename Allocator > + template < typename T, typename Allocator > + requires std::is_copy_constructible_v struct index_traits> { uvalue operator()(const std::vector& v, std::size_t i) { return uvalue{v[i]}; @@ -8266,14 +8276,14 @@ namespace meta_hpp } template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> // NOLINTNEXTLINE(*-forwarding-reference-overload) uvalue::uvalue(T&& val) { vtable_t::construct(*this, std::forward(val)); } template < detail::decay_non_value_kind T > - requires std::copy_constructible> + requires std::is_copy_constructible_v> uvalue& uvalue::operator=(T&& val) { uvalue{std::forward(val)}.swap(*this); return *this; diff --git a/untests/meta_utilities/value4_tests.cpp b/untests/meta_utilities/value4_tests.cpp new file mode 100644 index 0000000..5e3a280 --- /dev/null +++ b/untests/meta_utilities/value4_tests.cpp @@ -0,0 +1,70 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2022, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include "../meta_untests.hpp" + +namespace +{ + struct clazz_throw_dtor { + int i{}; + + clazz_throw_dtor(int ni) : i{ni} {} + clazz_throw_dtor(const clazz_throw_dtor&) = default; + + ~clazz_throw_dtor() noexcept(false) = default; + + static clazz_throw_dtor make(int ni) { + return {ni}; + } + }; +} + +TEST_CASE("meta/meta_utilities/value5/throw_dtor") { + namespace meta = meta_hpp; + + meta::class_() + .function_("make", &clazz_throw_dtor::make); + + SUBCASE("value") { + meta::uvalue v{clazz_throw_dtor{42}}; + + CHECK(v.get_type() == meta::resolve_type()); + CHECK(v.get_as().i == 42); + } + + SUBCASE("ptr_deref") { + clazz_throw_dtor obj{42}; + + meta::uvalue v_ptr{&obj}; + CHECK(v_ptr.get_type() == meta::resolve_type()); + CHECK(v_ptr.get_as() == &obj); + + meta::uvalue v = *v_ptr; + CHECK(v.get_type() == meta::resolve_type()); + CHECK(v.get_as().i == 42); + } + + SUBCASE("array_index") { + clazz_throw_dtor objs[2]{42, 21}; + + meta::uvalue v_ptr{objs}; + CHECK(v_ptr.get_type() == meta::resolve_type()); + CHECK(v_ptr.get_as() == objs); + + meta::uvalue v = v_ptr[1]; + CHECK(v.get_type() == meta::resolve_type()); + CHECK(v.get_as().i == 21); + } + + SUBCASE("as_return_value") { + meta::class_type clazz_throw_dtor_type = meta::resolve_type(); + meta::function clazz_throw_dtor_make_function = clazz_throw_dtor_type.get_function("make"); + + meta::uvalue v{clazz_throw_dtor_make_function(42)}; + CHECK(v.get_type() == meta::resolve_type()); + CHECK(v.get_as().i == 42); + } +}