Files
meta.hpp/untests/meta_utilities/arg6_tests.cpp
2022-01-14 10:47:33 +07:00

73 lines
2.3 KiB
C++

/*******************************************************************************
* 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, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include "../meta_untests.hpp"
namespace
{
struct base {
virtual ~base() = default;
virtual int int_method() const = 0;
};
struct clazz : base {
int int_member{42};
int int_method() const override { return int_member; }
};
using int_member_t = int clazz::*;
using int_method_t = int (clazz::*)() const;
int func_with_member(const clazz& cl, int_member_t m) {
return std::invoke(m, cl);
}
int func_with_method(const clazz& cl, int_method_t m) {
return std::invoke(m, cl);
}
}
TEST_CASE("meta/meta_utilities/arg6") {
namespace meta = meta_hpp;
using meta::detail::arg;
const meta::scope scope = meta::local_scope_("scope")
.function_("func_with_member", &func_with_member)
.function_("func_with_method", &func_with_method);
SUBCASE("int_member") {
static_assert(sizeof(int_member_t) == 8);
const meta::function f = scope.get_function("func_with_member");
REQUIRE(f);
clazz cl;
CHECK(f.is_invocable_with<clazz&, int_member_t>());
CHECK(f.is_invocable_with(cl, &clazz::int_member));
CHECK(f.invoke(cl, &clazz::int_member) == 42);
CHECK(f.is_invocable_with(meta::value{cl}, meta::value{&clazz::int_member}));
CHECK(f.invoke(meta::value{cl}, meta::value{&clazz::int_member}) == 42);
}
SUBCASE("int_method") {
static_assert(sizeof(int_method_t) == 16);
const meta::function f = scope.get_function("func_with_method");
REQUIRE(f);
clazz cl;
CHECK(f.is_invocable_with<clazz&, int_method_t>());
CHECK(f.is_invocable_with(cl, &clazz::int_method));
CHECK(f.invoke(cl, &clazz::int_method) == 42);
CHECK(f.is_invocable_with(meta::value{cl}, meta::value{&clazz::int_method}));
CHECK(f.invoke(meta::value{cl}, meta::value{&clazz::int_method}) == 42);
}
}