#include #include #include #include #include #include #include #include struct clazz_t { clazz_t() = default; operator int() const { return value; } bool to_bool() const { return (value != 0); } int value{}; }; double conv_to_double(const clazz_t &instance) { return instance.value * 2.; } struct MetaConv: ::testing::Test { void SetUp() override { using namespace entt::literals; entt::meta() .type("clazz"_hs) .conv() .conv<&clazz_t::to_bool>() .conv(); } void TearDown() override { entt::meta_reset(); } }; TEST_F(MetaConv, Functionalities) { auto any = entt::resolve().construct(); any.cast().value = 42; const auto as_int = std::as_const(any).allow_cast(); const auto as_bool = std::as_const(any).allow_cast(); const auto as_double = std::as_const(any).allow_cast(); ASSERT_FALSE(any.allow_cast()); ASSERT_TRUE(as_int); ASSERT_TRUE(as_bool); ASSERT_TRUE(as_double); ASSERT_EQ(as_int.cast(), any.cast().operator int()); ASSERT_EQ(as_bool.cast(), any.cast().to_bool()); ASSERT_EQ(as_double.cast(), conv_to_double(any.cast())); } TEST_F(MetaConv, ReRegistration) { SetUp(); auto &&node = entt::internal::resolve(entt::internal::meta_context::from(entt::locator::value_or())); ASSERT_TRUE(node.details); ASSERT_FALSE(node.details->conv.empty()); ASSERT_EQ(node.details->conv.size(), 3u); }