diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index a6cc5ce..bb35a8d 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -44,7 +44,11 @@ namespace meta_hpp::detail throw_exception_with("an attempt to call a function with incorrect argument types"); } - if constexpr ( as_void ) { + if constexpr ( std::is_void_v ) { + function( + args[Is].cast>()...); + return uvalue{}; + } else if constexpr ( stdex::same_as ) { std::ignore = function( args[Is].cast>()...); return uvalue{}; diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index f0984ca..c778210 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -50,9 +50,12 @@ namespace meta_hpp::detail throw_exception_with("an attempt to call a method with incorrect argument types"); } - if constexpr ( as_void ) { + if constexpr ( std::is_void_v ) { + (inst.cast().*method)( + args[Is].cast>()...); + return uvalue{}; + } else if constexpr ( stdex::same_as ) { std::ignore = (inst.cast().*method)( - inst.cast(), args[Is].cast>()...); return uvalue{}; } else { diff --git a/singles/headers/meta.hpp/meta_all.hpp b/singles/headers/meta.hpp/meta_all.hpp index 0775287..921c424 100644 --- a/singles/headers/meta.hpp/meta_all.hpp +++ b/singles/headers/meta.hpp/meta_all.hpp @@ -5624,7 +5624,11 @@ namespace meta_hpp::detail throw_exception_with("an attempt to call a function with incorrect argument types"); } - if constexpr ( as_void ) { + if constexpr ( std::is_void_v ) { + function( + args[Is].cast>()...); + return uvalue{}; + } else if constexpr ( stdex::same_as ) { std::ignore = function( args[Is].cast>()...); return uvalue{}; @@ -6364,9 +6368,12 @@ namespace meta_hpp::detail throw_exception_with("an attempt to call a method with incorrect argument types"); } - if constexpr ( as_void ) { + if constexpr ( std::is_void_v ) { + (inst.cast().*method)( + args[Is].cast>()...); + return uvalue{}; + } else if constexpr ( stdex::same_as ) { std::ignore = (inst.cast().*method)( - inst.cast(), args[Is].cast>()...); return uvalue{}; } else { diff --git a/untests/meta_issues/github_issue_15.cpp b/untests/meta_issues/github_issue_15.cpp new file mode 100644 index 0000000..ae1f032 --- /dev/null +++ b/untests/meta_issues/github_issue_15.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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 +{ + class rect { + public: + void get_width(int* v) { + *v = 42; + } + + static void get_width_static(int* v) { + *v = 84; + } + }; +} + +TEST_CASE("meta/meta_issues/15") { + namespace meta = meta_hpp; + + meta::class_() + .method_("get_width", &rect::get_width) + .function_("get_width_static", &rect::get_width_static); + + int v{}; + rect r{}; + + meta::resolve_type(r).get_method("get_width").invoke(r, &v); + CHECK(v == 42); + + meta::resolve_type(r).get_function("get_width_static").invoke(&v); + CHECK(v == 84); +}