diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 5e849d7..435ba7b 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -298,16 +298,23 @@ namespace meta_hpp::detail #if !defined(META_HPP_NO_EXCEPTIONS) # define META_HPP_TRY try -# define META_HPP_CATCH(e) catch ( e ) +# define META_HPP_CATCH(...) catch ( __VA_ARGS__ ) # define META_HPP_RETHROW() throw -# define META_HPP_THROW_AS(e, m) throw e(m) +# define META_HPP_THROW(...) throw ::meta_hpp::detail::exception(__VA_ARGS__) #else # define META_HPP_TRY if ( true ) -# define META_HPP_CATCH(e) if ( false ) -# define META_HPP_RETHROW() std::abort() -# define META_HPP_THROW_AS(e, m) std::terminate() +# define META_HPP_CATCH(...) if ( false ) +# define META_HPP_RETHROW() std::terminate() +# define META_HPP_THROW(...) std::terminate() #endif +#define META_HPP_THROW_IF(yesno, ...) \ + do { \ + if ( yesno ) { \ + META_HPP_THROW(__VA_ARGS__); \ + } \ + } while ( false ) + namespace meta_hpp::detail { #if !defined(META_HPP_NO_EXCEPTIONS) @@ -374,7 +381,7 @@ namespace meta_hpp::detail } R operator()(Args... args) const { - META_HPP_ASSERT(vtable_ && "bad function call"); + META_HPP_THROW_IF(!vtable_, "bad function call"); return vtable_->call(*this, std::forward(args)...); } @@ -2677,6 +2684,7 @@ namespace meta_hpp explicit evalue_index(enum_type type, std::string name); [[nodiscard]] enum_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -2695,6 +2703,7 @@ namespace meta_hpp explicit function_index(function_type type, std::string name); [[nodiscard]] function_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -2713,6 +2722,7 @@ namespace meta_hpp explicit member_index(member_type type, std::string name); [[nodiscard]] member_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -2731,6 +2741,7 @@ namespace meta_hpp explicit method_index(method_type type, std::string name); [[nodiscard]] method_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -2765,6 +2776,7 @@ namespace meta_hpp explicit variable_index(pointer_type type, std::string name); [[nodiscard]] pointer_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -4472,9 +4484,10 @@ namespace meta_hpp { auto state = detail::constructor_state::make(std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match constructor argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided argument names don't match constructor argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -4521,9 +4534,10 @@ namespace meta_hpp class_bind& class_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided arguments don't match function argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided arguments don't match function argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -4540,9 +4554,10 @@ namespace meta_hpp class_bind& class_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, {}); - if ( arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match function argument count"); - } + META_HPP_THROW_IF( // + arguments.size() > state->arguments.size(), + "provided argument names don't match function argument count" + ); for ( std::size_t i = 0; i < arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -4591,9 +4606,10 @@ namespace meta_hpp class_bind& class_bind::method_(std::string name, Method method_ptr, method_opts opts, Policy) { auto state = detail::method_state::make(std::move(name), method_ptr, std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided arguments don't match method argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided arguments don't match method argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -4611,9 +4627,10 @@ namespace meta_hpp class_bind& class_bind::method_(std::string name, Method method_ptr, string_ilist arguments, Policy) { auto state = detail::method_state::make(std::move(name), method_ptr, {}); - if ( arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match method argument count"); - } + META_HPP_THROW_IF( // + arguments.size() > state->arguments.size(), + "provided argument names don't match method argument count" + ); for ( std::size_t i = 0; i < arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -4741,9 +4758,10 @@ namespace meta_hpp scope_bind& scope_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided arguments don't match function argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided arguments don't match function argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -4759,9 +4777,10 @@ namespace meta_hpp scope_bind& scope_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, {}); - if ( arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match function argument count"); - } + META_HPP_THROW_IF( // + arguments.size() > state->arguments.size(), + "provided argument names don't match function argument count" + ); for ( std::size_t i = 0; i < arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -5425,9 +5444,7 @@ namespace meta_hpp::detail template < typename To > // NOLINTNEXTLINE(*-cognitive-complexity) To uarg::cast() const { - if ( !can_cast_to() ) { - META_HPP_THROW_AS(exception, "bad argument cast"); - } + META_HPP_THROW_IF(!can_cast_to(), "bad argument cast"); using to_raw_type_cv = std::remove_reference_t; using to_raw_type = std::remove_cv_t; @@ -5536,7 +5553,7 @@ namespace meta_hpp::detail } } - META_HPP_THROW_AS(exception, "bad argument cast"); + META_HPP_THROW("bad argument cast"); } } @@ -5615,15 +5632,17 @@ namespace meta_hpp::detail static_assert(as_object || as_raw_ptr || as_shared_ptr); - if ( args.size() != ct::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != ct::arity, + "an attempt to call a constructor with an incorrect arity" + ); return std::invoke( [args](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with incorrect argument types"); - } + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a constructor with incorrect argument types" + ); if constexpr ( as_object ) { return make_uvalue(args[Is].cast>()...); @@ -5647,17 +5666,22 @@ namespace meta_hpp::detail using class_type = typename ct::class_type; using argument_types = typename ct::argument_types; - if ( args.size() != ct::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != ct::arity, + "an attempt to call a constructor with an incorrect arity" + ); return std::invoke( [ mem, args ](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with incorrect argument types"); - } - return uvalue{ - std::construct_at(static_cast(mem), args[Is].cast>()...)}; + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a constructor with incorrect argument types" + ); + + return uvalue{std::construct_at( // + static_cast(mem), + args[Is].cast>()... + )}; }, std::make_index_sequence() ); @@ -6165,15 +6189,17 @@ namespace meta_hpp::detail static_assert(as_copy || as_void || ref_as_ptr); - if ( args.size() != ft::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a function with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != ft::arity, + "an attempt to call a function with an incorrect arity" + ); return std::invoke( [ function_ptr, args ](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a function with incorrect argument types"); - } + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a function with incorrect argument types" + ); if constexpr ( std::is_void_v ) { function_ptr(args[Is].cast>()...); @@ -6508,9 +6534,7 @@ namespace meta_hpp::detail { template < inst_class_ref_kind Q > decltype(auto) uinst::cast() const { - if ( !can_cast_to() ) { - META_HPP_THROW_AS(exception, "bad instance cast"); - } + META_HPP_THROW_IF(!can_cast_to(), "bad instance cast"); using inst_class_cv = std::remove_reference_t; using inst_class = std::remove_cv_t; @@ -6558,7 +6582,7 @@ namespace meta_hpp::detail } } - META_HPP_THROW_AS(exception, "bad instance cast"); + META_HPP_THROW("bad instance cast"); } } @@ -6629,9 +6653,10 @@ namespace meta_hpp::detail static_assert(as_copy || as_ptr || as_ref_wrap); - if ( !inst.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to get a member with an incorrect instance type"); - } + META_HPP_THROW_IF( // + !inst.can_cast_to(), + "an attempt to get a member with an incorrect instance type" + ); if ( inst.is_inst_const() ) { auto&& return_value = inst.cast().*member_ptr; @@ -6682,19 +6707,22 @@ namespace meta_hpp::detail using value_type = typename mt::value_type; if constexpr ( std::is_const_v ) { - META_HPP_THROW_AS(exception, "an attempt to set a constant member"); + META_HPP_THROW("an attempt to set a constant member"); } else { - if ( inst.is_inst_const() ) { - META_HPP_THROW_AS(exception, "an attempt to set a member with an const instance type"); - } + META_HPP_THROW_IF( // + inst.is_inst_const(), + "an attempt to set a member with an const instance type" + ); - if ( !inst.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to set a member with an incorrect instance type"); - } + META_HPP_THROW_IF( // + !inst.can_cast_to(), + "an attempt to set a member with an incorrect instance type" + ); - if ( !arg.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to set a member with an incorrect argument type"); - } + META_HPP_THROW_IF( // + !arg.can_cast_to(), + "an attempt to set a member with an incorrect argument type" + ); inst.cast().*member_ptr = arg.cast(); } @@ -6928,19 +6956,22 @@ namespace meta_hpp::detail static_assert(as_copy || as_void || ref_as_ptr); - if ( args.size() != mt::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a method with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != mt::arity, + "an attempt to call a method with an incorrect arity" + ); - if ( !inst.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to call a method with an incorrect instance type"); - } + META_HPP_THROW_IF( // + !inst.can_cast_to(), + "an attempt to call a method with an incorrect instance type" + ); return std::invoke( [ method_ptr, &inst, args ](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a method with incorrect argument types"); - } + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a method with incorrect argument types" + ); if constexpr ( std::is_void_v ) { (inst.cast().*method_ptr)(args[Is].cast>()...); @@ -7197,11 +7228,12 @@ namespace meta_hpp::detail using data_type = typename pt::data_type; if constexpr ( std::is_const_v ) { - META_HPP_THROW_AS(exception, "an attempt to set a constant variable"); + META_HPP_THROW("an attempt to set a constant variable"); } else { - if ( !arg.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to set a variable with an incorrect argument type"); - } + META_HPP_THROW_IF( // + !arg.can_cast_to(), + "an attempt to set a variable with an incorrect argument type" + ); *variable_ptr = arg.cast(); } } @@ -8896,7 +8928,7 @@ namespace meta_hpp } } - META_HPP_THROW_AS(exception, "bad value cast"); + META_HPP_THROW("bad value cast"); } template < typename T > @@ -8913,7 +8945,7 @@ namespace meta_hpp } } - META_HPP_THROW_AS(exception, "bad value cast"); + META_HPP_THROW("bad value cast"); } template < typename T > @@ -8930,7 +8962,7 @@ namespace meta_hpp } } - META_HPP_THROW_AS(exception, "bad value cast"); + META_HPP_THROW("bad value cast"); } template < typename T > diff --git a/develop/untests/meta_indices/ops_tests.cpp b/develop/untests/meta_indices/ops_tests.cpp new file mode 100644 index 0000000..2db1656 --- /dev/null +++ b/develop/untests/meta_indices/ops_tests.cpp @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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-2023, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include +#include + +namespace +{ + struct ivec2 { + int x{}; + int y{}; + + ivec2& add(const ivec2& other) { + x += other.x; + y += other.y; + return *this; + } + }; +} + +TEST_CASE("meta/meta_indices/ops/_") { + namespace meta = meta_hpp; + + meta::class_() + .member_("x", &ivec2::x) + .member_("y", &ivec2::y) + .method_("add", &ivec2::add); +} + +TEST_CASE("meta/meta_indices/ops") { + namespace meta = meta_hpp; + + const meta::class_type ivec2_type = meta::resolve_type(); + REQUIRE(ivec2_type); + + const meta::member ivec2_x = ivec2_type.get_member("x"); + REQUIRE(ivec2_x); + + const meta::member ivec2_y = ivec2_type.get_member("y"); + REQUIRE(ivec2_y); + + const meta::method ivec2_add = ivec2_type.get_method("add"); + REQUIRE(ivec2_add); + + SUBCASE("get_type") { + CHECK(ivec2_x.get_index().get_type() == meta::resolve_type()); + CHECK(ivec2_add.get_index().get_type() == meta::resolve_type()); + } + + SUBCASE("get_name") { + { + meta::member_index ivec2_x_index = ivec2_x.get_index(); + CHECK(ivec2_x_index.get_name() == "x"); + CHECK(std::move(ivec2_x_index).get_name() == "x"); + } + { + meta::method_index ivec2_add_index = ivec2_add.get_index(); + CHECK(ivec2_add_index.get_name() == "add"); + CHECK(std::move(ivec2_add_index).get_name() == "add"); + } + } +} diff --git a/headers/meta.hpp/meta_base/exceptions.hpp b/headers/meta.hpp/meta_base/exceptions.hpp index 7ea1f99..705bdc5 100644 --- a/headers/meta.hpp/meta_base/exceptions.hpp +++ b/headers/meta.hpp/meta_base/exceptions.hpp @@ -10,16 +10,23 @@ #if !defined(META_HPP_NO_EXCEPTIONS) # define META_HPP_TRY try -# define META_HPP_CATCH(e) catch ( e ) +# define META_HPP_CATCH(...) catch ( __VA_ARGS__ ) # define META_HPP_RETHROW() throw -# define META_HPP_THROW_AS(e, m) throw e(m) +# define META_HPP_THROW(...) throw ::meta_hpp::detail::exception(__VA_ARGS__) #else # define META_HPP_TRY if ( true ) -# define META_HPP_CATCH(e) if ( false ) -# define META_HPP_RETHROW() std::abort() -# define META_HPP_THROW_AS(e, m) std::terminate() +# define META_HPP_CATCH(...) if ( false ) +# define META_HPP_RETHROW() std::terminate() +# define META_HPP_THROW(...) std::terminate() #endif +#define META_HPP_THROW_IF(yesno, ...) \ + do { \ + if ( yesno ) { \ + META_HPP_THROW(__VA_ARGS__); \ + } \ + } while ( false ) + namespace meta_hpp::detail { #if !defined(META_HPP_NO_EXCEPTIONS) diff --git a/headers/meta.hpp/meta_base/fixed_function.hpp b/headers/meta.hpp/meta_base/fixed_function.hpp index 1e26c8e..a3951e8 100644 --- a/headers/meta.hpp/meta_base/fixed_function.hpp +++ b/headers/meta.hpp/meta_base/fixed_function.hpp @@ -64,7 +64,7 @@ namespace meta_hpp::detail } R operator()(Args... args) const { - META_HPP_ASSERT(vtable_ && "bad function call"); + META_HPP_THROW_IF(!vtable_, "bad function call"); return vtable_->call(*this, std::forward(args)...); } diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index 043bbc8..b68ee5d 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -72,9 +72,10 @@ namespace meta_hpp { auto state = detail::constructor_state::make(std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match constructor argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided argument names don't match constructor argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -121,9 +122,10 @@ namespace meta_hpp class_bind& class_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided arguments don't match function argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided arguments don't match function argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -140,9 +142,10 @@ namespace meta_hpp class_bind& class_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, {}); - if ( arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match function argument count"); - } + META_HPP_THROW_IF( // + arguments.size() > state->arguments.size(), + "provided argument names don't match function argument count" + ); for ( std::size_t i = 0; i < arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -191,9 +194,10 @@ namespace meta_hpp class_bind& class_bind::method_(std::string name, Method method_ptr, method_opts opts, Policy) { auto state = detail::method_state::make(std::move(name), method_ptr, std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided arguments don't match method argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided arguments don't match method argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -211,9 +215,10 @@ namespace meta_hpp class_bind& class_bind::method_(std::string name, Method method_ptr, string_ilist arguments, Policy) { auto state = detail::method_state::make(std::move(name), method_ptr, {}); - if ( arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match method argument count"); - } + META_HPP_THROW_IF( // + arguments.size() > state->arguments.size(), + "provided argument names don't match method argument count" + ); for ( std::size_t i = 0; i < arguments.size(); ++i ) { argument& arg = state->arguments[i]; diff --git a/headers/meta.hpp/meta_binds/scope_bind.hpp b/headers/meta.hpp/meta_binds/scope_bind.hpp index 1955bbd..78e3d5c 100644 --- a/headers/meta.hpp/meta_binds/scope_bind.hpp +++ b/headers/meta.hpp/meta_binds/scope_bind.hpp @@ -28,9 +28,10 @@ namespace meta_hpp scope_bind& scope_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, std::move(opts.metadata)); - if ( opts.arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided arguments don't match function argument count"); - } + META_HPP_THROW_IF( // + opts.arguments.size() > state->arguments.size(), + "provided arguments don't match function argument count" + ); for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) { argument& arg = state->arguments[i]; @@ -46,9 +47,10 @@ namespace meta_hpp scope_bind& scope_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) { auto state = detail::function_state::make(std::move(name), function_ptr, {}); - if ( arguments.size() > state->arguments.size() ) { - META_HPP_THROW_AS(exception, "provided argument names don't match function argument count"); - } + META_HPP_THROW_IF( // + arguments.size() > state->arguments.size(), + "provided argument names don't match function argument count" + ); for ( std::size_t i = 0; i < arguments.size(); ++i ) { argument& arg = state->arguments[i]; diff --git a/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp b/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp index 1ba3777..de39217 100644 --- a/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp +++ b/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp @@ -234,9 +234,7 @@ namespace meta_hpp::detail template < typename To > // NOLINTNEXTLINE(*-cognitive-complexity) To uarg::cast() const { - if ( !can_cast_to() ) { - META_HPP_THROW_AS(exception, "bad argument cast"); - } + META_HPP_THROW_IF(!can_cast_to(), "bad argument cast"); using to_raw_type_cv = std::remove_reference_t; using to_raw_type = std::remove_cv_t; @@ -345,6 +343,6 @@ namespace meta_hpp::detail } } - META_HPP_THROW_AS(exception, "bad argument cast"); + META_HPP_THROW("bad argument cast"); } } diff --git a/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp b/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp index f7c49e3..1fd67f9 100644 --- a/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp +++ b/headers/meta.hpp/meta_detail/value_utilities/uinst.hpp @@ -183,9 +183,7 @@ namespace meta_hpp::detail { template < inst_class_ref_kind Q > decltype(auto) uinst::cast() const { - if ( !can_cast_to() ) { - META_HPP_THROW_AS(exception, "bad instance cast"); - } + META_HPP_THROW_IF(!can_cast_to(), "bad instance cast"); using inst_class_cv = std::remove_reference_t; using inst_class = std::remove_cv_t; @@ -233,6 +231,6 @@ namespace meta_hpp::detail } } - META_HPP_THROW_AS(exception, "bad instance cast"); + META_HPP_THROW("bad instance cast"); } } diff --git a/headers/meta.hpp/meta_indices.hpp b/headers/meta.hpp/meta_indices.hpp index 698ef65..6b3e292 100644 --- a/headers/meta.hpp/meta_indices.hpp +++ b/headers/meta.hpp/meta_indices.hpp @@ -66,6 +66,7 @@ namespace meta_hpp explicit evalue_index(enum_type type, std::string name); [[nodiscard]] enum_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -84,6 +85,7 @@ namespace meta_hpp explicit function_index(function_type type, std::string name); [[nodiscard]] function_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -102,6 +104,7 @@ namespace meta_hpp explicit member_index(member_type type, std::string name); [[nodiscard]] member_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -120,6 +123,7 @@ namespace meta_hpp explicit method_index(method_type type, std::string name); [[nodiscard]] method_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; @@ -154,6 +158,7 @@ namespace meta_hpp explicit variable_index(pointer_type type, std::string name); [[nodiscard]] pointer_type get_type() const noexcept; + [[nodiscard]] std::string&& get_name() && noexcept; [[nodiscard]] const std::string& get_name() const& noexcept; diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index f26799e..8eb4165 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -32,15 +32,17 @@ namespace meta_hpp::detail static_assert(as_object || as_raw_ptr || as_shared_ptr); - if ( args.size() != ct::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != ct::arity, + "an attempt to call a constructor with an incorrect arity" + ); return std::invoke( [args](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with incorrect argument types"); - } + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a constructor with incorrect argument types" + ); if constexpr ( as_object ) { return make_uvalue(args[Is].cast>()...); @@ -64,17 +66,22 @@ namespace meta_hpp::detail using class_type = typename ct::class_type; using argument_types = typename ct::argument_types; - if ( args.size() != ct::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != ct::arity, + "an attempt to call a constructor with an incorrect arity" + ); return std::invoke( [ mem, args ](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a constructor with incorrect argument types"); - } - return uvalue{ - std::construct_at(static_cast(mem), args[Is].cast>()...)}; + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a constructor with incorrect argument types" + ); + + return uvalue{std::construct_at( // + static_cast(mem), + args[Is].cast>()... + )}; }, std::make_index_sequence() ); diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 75c3684..8b341ba 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -34,15 +34,17 @@ namespace meta_hpp::detail static_assert(as_copy || as_void || ref_as_ptr); - if ( args.size() != ft::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a function with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != ft::arity, + "an attempt to call a function with an incorrect arity" + ); return std::invoke( [ function_ptr, args ](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a function with incorrect argument types"); - } + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a function with incorrect argument types" + ); if constexpr ( std::is_void_v ) { function_ptr(args[Is].cast>()...); diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index 5fe5402..605df41 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -33,9 +33,10 @@ namespace meta_hpp::detail static_assert(as_copy || as_ptr || as_ref_wrap); - if ( !inst.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to get a member with an incorrect instance type"); - } + META_HPP_THROW_IF( // + !inst.can_cast_to(), + "an attempt to get a member with an incorrect instance type" + ); if ( inst.is_inst_const() ) { auto&& return_value = inst.cast().*member_ptr; @@ -86,19 +87,22 @@ namespace meta_hpp::detail using value_type = typename mt::value_type; if constexpr ( std::is_const_v ) { - META_HPP_THROW_AS(exception, "an attempt to set a constant member"); + META_HPP_THROW("an attempt to set a constant member"); } else { - if ( inst.is_inst_const() ) { - META_HPP_THROW_AS(exception, "an attempt to set a member with an const instance type"); - } + META_HPP_THROW_IF( // + inst.is_inst_const(), + "an attempt to set a member with an const instance type" + ); - if ( !inst.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to set a member with an incorrect instance type"); - } + META_HPP_THROW_IF( // + !inst.can_cast_to(), + "an attempt to set a member with an incorrect instance type" + ); - if ( !arg.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to set a member with an incorrect argument type"); - } + META_HPP_THROW_IF( // + !arg.can_cast_to(), + "an attempt to set a member with an incorrect argument type" + ); inst.cast().*member_ptr = arg.cast(); } diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index 81fc47b..1935d84 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -36,19 +36,22 @@ namespace meta_hpp::detail static_assert(as_copy || as_void || ref_as_ptr); - if ( args.size() != mt::arity ) { - META_HPP_THROW_AS(exception, "an attempt to call a method with an incorrect arity"); - } + META_HPP_THROW_IF( // + args.size() != mt::arity, + "an attempt to call a method with an incorrect arity" + ); - if ( !inst.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to call a method with an incorrect instance type"); - } + META_HPP_THROW_IF( // + !inst.can_cast_to(), + "an attempt to call a method with an incorrect instance type" + ); return std::invoke( [ method_ptr, &inst, args ](std::index_sequence)->uvalue { - if ( !(... && args[Is].can_cast_to>()) ) { - META_HPP_THROW_AS(exception, "an attempt to call a method with incorrect argument types"); - } + META_HPP_THROW_IF( // + !(... && args[Is].can_cast_to>()), + "an attempt to call a method with incorrect argument types" + ); if constexpr ( std::is_void_v ) { (inst.cast().*method_ptr)(args[Is].cast>()...); diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 22dd123..77b3b96 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -52,11 +52,12 @@ namespace meta_hpp::detail using data_type = typename pt::data_type; if constexpr ( std::is_const_v ) { - META_HPP_THROW_AS(exception, "an attempt to set a constant variable"); + META_HPP_THROW("an attempt to set a constant variable"); } else { - if ( !arg.can_cast_to() ) { - META_HPP_THROW_AS(exception, "an attempt to set a variable with an incorrect argument type"); - } + META_HPP_THROW_IF( // + !arg.can_cast_to(), + "an attempt to set a variable with an incorrect argument type" + ); *variable_ptr = arg.cast(); } } diff --git a/headers/meta.hpp/meta_uvalue/uvalue.hpp b/headers/meta.hpp/meta_uvalue/uvalue.hpp index 8e60695..762acf5 100644 --- a/headers/meta.hpp/meta_uvalue/uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue/uvalue.hpp @@ -453,7 +453,7 @@ namespace meta_hpp } } - META_HPP_THROW_AS(exception, "bad value cast"); + META_HPP_THROW("bad value cast"); } template < typename T > @@ -470,7 +470,7 @@ namespace meta_hpp } } - META_HPP_THROW_AS(exception, "bad value cast"); + META_HPP_THROW("bad value cast"); } template < typename T > @@ -487,7 +487,7 @@ namespace meta_hpp } } - META_HPP_THROW_AS(exception, "bad value cast"); + META_HPP_THROW("bad value cast"); } template < typename T >