fix github issue #15

This commit is contained in:
BlackMATov
2022-10-29 10:32:27 +07:00
parent 24c1457ca9
commit d7a4353ab7
4 changed files with 58 additions and 6 deletions

View File

@@ -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<return_type> ) {
function(
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else if constexpr ( stdex::same_as<Policy, function_policy::discard_return> ) {
std::ignore = function(
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};

View File

@@ -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<return_type> ) {
(inst.cast<qualified_type>().*method)(
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else if constexpr ( stdex::same_as<Policy, method_policy::discard_return> ) {
std::ignore = (inst.cast<qualified_type>().*method)(
inst.cast<qualified_type>(),
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else {

View File

@@ -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<return_type> ) {
function(
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else if constexpr ( stdex::same_as<Policy, function_policy::discard_return> ) {
std::ignore = function(
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
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<return_type> ) {
(inst.cast<qualified_type>().*method)(
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else if constexpr ( stdex::same_as<Policy, method_policy::discard_return> ) {
std::ignore = (inst.cast<qualified_type>().*method)(
inst.cast<qualified_type>(),
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else {

View File

@@ -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_<rect>()
.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);
}