Skip to content

Commit

Permalink
all function arguments are taken by alias
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Sep 10, 2019
1 parent 91f69c2 commit 3bc199e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,8 @@ class func {
*/
template<typename... Args>
any invoke(handle handle, Args &&... args) const {
std::array<any, sizeof...(Args)> arguments{{std::forward<Args>(args)...}};
// makes aliasing on the values and passes forward references if any
std::array<any, sizeof...(Args)> arguments{{meta::handle{args}...}};
any any{};

if(sizeof...(Args) == size()) {
Expand Down
20 changes: 17 additions & 3 deletions test/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct func_type {
int f(int v) const { return v*v; }
void g(int v) { value = v*v; }

static int h(int v) { return v; }
static int h(int &v) { return (v *= value); }
static void k(int v) { value = v; }

int v(int v) const { return (value = v); }
Expand Down Expand Up @@ -1542,6 +1542,7 @@ TEST_F(Meta, MetaFuncRetVoid) {
TEST_F(Meta, MetaFuncStatic) {
std::hash<std::string_view> hash{};
auto func = meta::resolve<func_type>().func(hash("h"));
func_type::value = 2;

ASSERT_TRUE(func);
ASSERT_EQ(func.parent(), meta::resolve(hash("func")));
Expand All @@ -1552,13 +1553,13 @@ TEST_F(Meta, MetaFuncStatic) {
ASSERT_EQ(func.arg(meta::func::size_type{0}), meta::resolve<int>());
ASSERT_FALSE(func.arg(meta::func::size_type{1}));

auto any = func.invoke({}, 42);
auto any = func.invoke({}, 3);
auto empty = func.invoke({}, 'c');

ASSERT_FALSE(empty);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), meta::resolve<int>());
ASSERT_EQ(any.cast<int>(), 42);
ASSERT_EQ(any.cast<int>(), 6);

func.prop([](auto prop) {
ASSERT_TRUE(prop);
Expand Down Expand Up @@ -1661,6 +1662,19 @@ TEST_F(Meta, MetaFuncAsAlias) {
ASSERT_EQ(instance.value, 3);
}

TEST_F(Meta, MetaFuncByReference) {
std::hash<std::string_view> hash{};
auto func = meta::resolve<func_type>().func(hash("h"));
func_type::value = 2;
meta::any any{3};
int value = 4;

ASSERT_EQ(func.invoke({}, value).cast<int>(), 8);
ASSERT_EQ(func.invoke({}, any).cast<int>(), 6);
ASSERT_EQ(any.cast<int>(), 6);
ASSERT_EQ(value, 8);
}

TEST_F(Meta, MetaType) {
auto type = meta::resolve<derived_type>();

Expand Down

0 comments on commit 3bc199e

Please sign in to comment.