/******************************************************************************* * 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_tests.hpp" namespace { struct ivec2 { int x{}; int y{}; int dot(const ivec2& other) const { return x * other.x + y * other.y; } int length2() const { return dot(*this); } }; } TEST_CASE("meta/examples/method") { namespace meta = meta_hpp; meta::class_() .member_("x", &ivec2::x) .member_("y", &ivec2::y) .method_("dot", &ivec2::dot) .method_("length2", &ivec2::length2); const meta::class_type ivec2_type = meta::resolve_type(); CHECK(ivec2_type.get_methods().size() == 2); { const meta::method ivec2_dot = ivec2_type.get_method("dot"); CHECK(ivec2_dot.get_name() == "dot"); CHECK(ivec2_dot.get_type() == meta::resolve_type()); CHECK(ivec2_dot.get_type().get_arity() == 1); CHECK(ivec2_dot.get_type().get_return_type() == meta::resolve_type()); CHECK(ivec2_dot.get_type().get_argument_type(0) == meta::resolve_type()); } }