/******************************************************************************* * 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 clazz { int member{1}; int method(int i) const { return i; } static int function(int i) { return i; } }; } TEST_CASE("meta/meta_utilities/invoke") { namespace meta = meta_hpp; meta::class_() .member_("member", &clazz::member) .method_("method", &clazz::method) .function_("function", &clazz::function); const meta::class_type& clazz_type = meta::resolve_type(); REQUIRE(clazz_type); const meta::member& clazz_member = clazz_type.get_member("member"); const meta::method& clazz_method = clazz_type.get_method("method"); const meta::function& clazz_function = clazz_type.get_function("function"); REQUIRE((clazz_member && clazz_method && clazz_function)); { CHECK(meta::invoke(&clazz::function, 3).as() == 3); CHECK(meta::invoke(&clazz::function, meta::uvalue{3}).as() == 3); CHECK(meta::invoke(clazz_function, 3).as() == 3); CHECK(meta::invoke(clazz_function, meta::uvalue{3}).as() == 3); CHECK(meta::is_invocable_with(clazz_function, 3)); CHECK(meta::is_invocable_with(clazz_function, meta::uvalue{3})); CHECK(meta::is_invocable_with(clazz_function)); CHECK(meta::is_invocable_with(&clazz::function, 3)); CHECK(meta::is_invocable_with(&clazz::function, meta::uvalue{3})); CHECK(meta::is_invocable_with(&clazz::function)); } { clazz cl; CHECK(meta::invoke(&clazz::member, cl).as() == 1); CHECK(meta::invoke(&clazz::member, meta::uvalue{cl}).as() == 1); CHECK(meta::invoke(clazz_member, cl).as() == 1); CHECK(meta::invoke(clazz_member, meta::uvalue{cl}).as() == 1); CHECK(meta::is_invocable_with(clazz_member, cl)); CHECK(meta::is_invocable_with(clazz_member, meta::uvalue{cl})); CHECK(meta::is_invocable_with(clazz_member)); CHECK(meta::is_invocable_with(&clazz::member, cl)); CHECK(meta::is_invocable_with(&clazz::member, meta::uvalue{cl})); CHECK(meta::is_invocable_with(&clazz::member)); } { clazz cl; CHECK(meta::invoke(&clazz::method, cl, 2).as() == 2); CHECK(meta::invoke(&clazz::method, meta::uvalue{cl}, meta::uvalue{2}).as() == 2); CHECK(meta::invoke(clazz_method, cl, 2).as() == 2); CHECK(meta::invoke(clazz_method, meta::uvalue{cl}, meta::uvalue{2}).as() == 2); CHECK(meta::is_invocable_with(clazz_method, cl, 2)); CHECK(meta::is_invocable_with(clazz_method, meta::uvalue{cl}, meta::uvalue{2})); CHECK(meta::is_invocable_with(clazz_method)); CHECK(meta::is_invocable_with(&clazz::method, cl, 2)); CHECK(meta::is_invocable_with(&clazz::method, meta::uvalue{cl}, meta::uvalue{2})); CHECK(meta::is_invocable_with(&clazz::method)); } }