meta:
* meta_any: convert -> allow_cast * support for const references * as_cref_t policy
This commit is contained in:
+10
-10
@@ -596,11 +596,11 @@ TEST_F(MetaAny, Convert) {
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_EQ(any.type(), entt::resolve<double>());
|
||||
ASSERT_TRUE(any.convert<double>());
|
||||
ASSERT_FALSE(any.convert<char>());
|
||||
ASSERT_TRUE(any.allow_cast<double>());
|
||||
ASSERT_FALSE(any.allow_cast<char>());
|
||||
ASSERT_EQ(any.type(), entt::resolve<double>());
|
||||
ASSERT_EQ(any.cast<double>(), 42.);
|
||||
ASSERT_TRUE(any.convert<int>());
|
||||
ASSERT_TRUE(any.allow_cast<int>());
|
||||
ASSERT_EQ(any.type(), entt::resolve<int>());
|
||||
ASSERT_EQ(any.cast<int>(), 42);
|
||||
}
|
||||
@@ -610,12 +610,12 @@ TEST_F(MetaAny, ConstConvert) {
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_EQ(any.type(), entt::resolve<double>());
|
||||
ASSERT_TRUE(any.convert<double>());
|
||||
ASSERT_FALSE(any.convert<char>());
|
||||
ASSERT_TRUE(any.allow_cast<double>());
|
||||
ASSERT_FALSE(any.allow_cast<char>());
|
||||
ASSERT_EQ(any.type(), entt::resolve<double>());
|
||||
ASSERT_EQ(any.cast<double>(), 42.);
|
||||
|
||||
auto other = any.convert<int>();
|
||||
auto other = any.allow_cast<int>();
|
||||
|
||||
ASSERT_EQ(any.type(), entt::resolve<double>());
|
||||
ASSERT_EQ(any.cast<double>(), 42.);
|
||||
@@ -638,11 +638,11 @@ TEST_F(MetaAny, UnmanageableType) {
|
||||
ASSERT_EQ(any.try_cast<int>(), nullptr);
|
||||
ASSERT_NE(any.try_cast<unmanageable_t>(), nullptr);
|
||||
|
||||
ASSERT_TRUE(any.convert<unmanageable_t>());
|
||||
ASSERT_FALSE(any.convert<int>());
|
||||
ASSERT_TRUE(any.allow_cast<unmanageable_t>());
|
||||
ASSERT_FALSE(any.allow_cast<int>());
|
||||
|
||||
ASSERT_TRUE(std::as_const(any).convert<unmanageable_t>());
|
||||
ASSERT_FALSE(std::as_const(any).convert<int>());
|
||||
ASSERT_TRUE(std::as_const(any).allow_cast<unmanageable_t>());
|
||||
ASSERT_FALSE(std::as_const(any).allow_cast<int>());
|
||||
}
|
||||
|
||||
TEST_F(MetaAny, Invoke) {
|
||||
|
||||
@@ -583,8 +583,8 @@ TEST_F(MetaType, ResetAndReRegistrationAfterReset) {
|
||||
entt::meta_any any{42.};
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_FALSE(any.convert<int>());
|
||||
ASSERT_TRUE(any.convert<float>());
|
||||
ASSERT_FALSE(any.allow_cast<int>());
|
||||
ASSERT_TRUE(any.allow_cast<float>());
|
||||
|
||||
ASSERT_FALSE(entt::resolve("derived"_hs));
|
||||
ASSERT_TRUE(entt::resolve("double"_hs));
|
||||
|
||||
@@ -35,7 +35,7 @@ TEST(Lib, Meta) {
|
||||
ASSERT_EQ(pos.type().data("y"_hs).get(pos).cast<int>(), 3);
|
||||
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
|
||||
ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).convert<double>());
|
||||
ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).allow_cast<double>());
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast<double>(), 0.);
|
||||
ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast<double>(), 0.);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST(Lib, Meta) {
|
||||
ASSERT_EQ(pos.type().data("y"_hs).get(pos).cast<int>(), 3);
|
||||
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
|
||||
ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).convert<double>());
|
||||
ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).allow_cast<double>());
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast<double>(), 0.);
|
||||
ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast<double>(), 0.);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST(Lib, Meta) {
|
||||
ASSERT_EQ(pos.type().data("y"_hs).get(pos).cast<int>(), 3);
|
||||
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
|
||||
ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).convert<double>());
|
||||
ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).allow_cast<double>());
|
||||
ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast<double>(), 0.);
|
||||
ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast<double>(), 0.);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user