meta_any: deprecated std::reference_wrapper support

This commit is contained in:
Michele Caini
2021-04-25 23:14:13 +02:00
parent 3fac3fe2d7
commit 955d325f07
9 changed files with 52 additions and 50 deletions

View File

@@ -253,6 +253,7 @@ public:
* @param value An instance of an object to use to initialize the wrapper.
*/
template<typename Type>
[[deprecated("Use std::in_place_type<T &> or entt::make_meta_any<T &> instead")]]
meta_any(std::reference_wrapper<Type> value)
: meta_any{std::in_place_type<Type &>, value.get()}
{}
@@ -319,6 +320,7 @@ public:
* @return This meta any object.
*/
template<typename Type>
[[deprecated("Use emplace<Type &> instead")]]
meta_any & operator=(std::reference_wrapper<Type> value) {
emplace<Type &>(value.get());
return *this;

View File

@@ -147,7 +147,7 @@ TEST_F(MetaAny, SBOInPlaceTypeConstruction) {
TEST_F(MetaAny, SBOAsRefConstruction) {
int value = 3;
int compare = 42;
entt::meta_any any{std::ref(value)};
auto any = entt::make_meta_any<int &>(value);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<int>());
@@ -159,13 +159,13 @@ TEST_F(MetaAny, SBOAsRefConstruction) {
ASSERT_EQ(any.data(), &value);
ASSERT_EQ(std::as_const(any).data(), &value);
ASSERT_EQ(any, (entt::meta_any{std::ref(value)}));
ASSERT_NE(any, (entt::meta_any{std::ref(compare)}));
ASSERT_EQ(any, entt::make_meta_any<int &>(value));
ASSERT_NE(any, entt::make_meta_any<int &>(compare));
ASSERT_NE(any, entt::meta_any{42});
ASSERT_EQ(entt::meta_any{3}, any);
any = std::ref(value);
any = entt::make_meta_any<int &>(value);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<int>());
@@ -182,7 +182,7 @@ TEST_F(MetaAny, SBOAsRefConstruction) {
TEST_F(MetaAny, SBOAsConstRefConstruction) {
int value = 3;
int compare = 42;
entt::meta_any any{std::cref(value)};
auto any = entt::make_meta_any<const int &>(value);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<int>());
@@ -194,13 +194,13 @@ TEST_F(MetaAny, SBOAsConstRefConstruction) {
ASSERT_EQ(any.data(), nullptr);
ASSERT_EQ(std::as_const(any).data(), &value);
ASSERT_EQ(any, (entt::meta_any{std::cref(value)}));
ASSERT_NE(any, (entt::meta_any{std::cref(compare)}));
ASSERT_EQ(any, entt::make_meta_any<const int &>(value));
ASSERT_NE(any, entt::make_meta_any<const int &>(compare));
ASSERT_NE(any, entt::meta_any{42});
ASSERT_EQ(entt::meta_any{3}, any);
any = std::cref(value);
any = entt::make_meta_any<const int &>(value);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<int>());
@@ -291,7 +291,7 @@ TEST_F(MetaAny, NoSBOInPlaceTypeConstruction) {
TEST_F(MetaAny, NoSBOAsRefConstruction) {
fat_t instance{.1, .2, .3, .4};
entt::meta_any any{std::ref(instance)};
auto any = entt::make_meta_any<fat_t &>(instance);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<fat_t>());
@@ -303,12 +303,12 @@ TEST_F(MetaAny, NoSBOAsRefConstruction) {
ASSERT_EQ(any.data(), &instance);
ASSERT_EQ(std::as_const(any).data(), &instance);
ASSERT_EQ(any, (entt::meta_any{std::ref(instance)}));
ASSERT_EQ(any, entt::make_meta_any<fat_t &>(instance));
ASSERT_EQ(any, entt::meta_any{instance});
ASSERT_NE(entt::meta_any{fat_t{}}, any);
any = std::ref(instance);
any = entt::make_meta_any<fat_t &>(instance);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<fat_t>());
@@ -324,7 +324,7 @@ TEST_F(MetaAny, NoSBOAsRefConstruction) {
TEST_F(MetaAny, NoSBOAsConstRefConstruction) {
fat_t instance{.1, .2, .3, .4};
entt::meta_any any{std::cref(instance)};
auto any = entt::make_meta_any<const fat_t &>(instance);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<fat_t>());
@@ -336,12 +336,12 @@ TEST_F(MetaAny, NoSBOAsConstRefConstruction) {
ASSERT_EQ(any.data(), nullptr);
ASSERT_EQ(std::as_const(any).data(), &instance);
ASSERT_EQ(any, (entt::meta_any{std::cref(instance)}));
ASSERT_EQ(any, entt::make_meta_any<const fat_t &>(instance));
ASSERT_EQ(any, entt::meta_any{instance});
ASSERT_NE(entt::meta_any{fat_t{}}, any);
any = std::cref(instance);
any = entt::make_meta_any<const fat_t &>(instance);
ASSERT_TRUE(any);
ASSERT_EQ(any.type(), entt::resolve<fat_t>());
@@ -852,7 +852,7 @@ TEST_F(MetaAny, ConstConvert) {
TEST_F(MetaAny, UnmanageableType) {
unmanageable_t instance;
entt::meta_any any{std::ref(instance)};
auto any = entt::make_meta_any<unmanageable_t &>(instance);
entt::meta_any other = any.as_ref();
std::swap(any, other);
@@ -876,7 +876,7 @@ TEST_F(MetaAny, Invoke) {
using namespace entt::literals;
clazz_t instance;
entt::meta_any any{std::ref(instance)};
auto any = entt::make_meta_any<clazz_t &>(instance);
ASSERT_TRUE(any.invoke("func"_hs));
ASSERT_TRUE(any.invoke("member"_hs, 42));
@@ -892,7 +892,7 @@ TEST_F(MetaAny, SetGet) {
using namespace entt::literals;
clazz_t instance;
entt::meta_any any{std::ref(instance)};
auto any = entt::make_meta_any<clazz_t &>(instance);
ASSERT_TRUE(any.set("value"_hs, 42));

View File

@@ -57,7 +57,7 @@ TEST_F(MetaContainer, EmptyAssociativeContainer) {
TEST_F(MetaContainer, SequenceContainerIterator) {
std::vector<int> vec{2, 3, 4};
entt::meta_any any{std::ref(vec)};
auto any = entt::make_meta_any<std::vector<int> &>(vec);
entt::meta_sequence_container::iterator first{};
auto view = any.as_sequence_container();
@@ -84,7 +84,7 @@ TEST_F(MetaContainer, SequenceContainerIterator) {
TEST_F(MetaContainer, AssociativeContainerIterator) {
std::map<int, char> map{{2, 'c'}, {3, 'd'}, {4, 'e'}};
entt::meta_any any{std::ref(map)};
auto any = entt::make_meta_any<std::map<int, char> &>(map);
entt::meta_associative_container::iterator first{};
auto view = any.as_associative_container();
@@ -111,7 +111,7 @@ TEST_F(MetaContainer, AssociativeContainerIterator) {
TEST_F(MetaContainer, StdVector) {
std::vector<int> vec{};
entt::meta_any any{std::ref(vec)};
auto any = entt::make_meta_any<std::vector<int> &>(vec);
auto view = any.as_sequence_container();
@@ -154,7 +154,7 @@ TEST_F(MetaContainer, StdVector) {
TEST_F(MetaContainer, StdArray) {
std::array<int, 3> arr{};
entt::meta_any any{std::ref(arr)};
auto any = entt::make_meta_any<std::array<int, 3> &>(arr);
auto view = any.as_sequence_container();
@@ -196,7 +196,7 @@ TEST_F(MetaContainer, StdArray) {
TEST_F(MetaContainer, StdMap) {
std::map<int, char> map{{2, 'c'}, {3, 'd'}, {4, 'e'}};
entt::meta_any any{std::ref(map)};
auto any = entt::make_meta_any<std::map<int, char> &>(map);
auto view = any.as_associative_container();
@@ -240,7 +240,7 @@ TEST_F(MetaContainer, StdMap) {
TEST_F(MetaContainer, StdSet) {
std::set<int> set{2, 3, 4};
entt::meta_any any{std::ref(set)};
auto any = entt::make_meta_any<std::set<int> &>(set);
auto view = any.as_associative_container();
@@ -283,7 +283,7 @@ TEST_F(MetaContainer, StdSet) {
TEST_F(MetaContainer, ConstSequenceContainer) {
std::vector<int> vec{};
entt::meta_any any{std::cref(vec)};
auto any = entt::make_meta_any<const std::vector<int> &>(vec);
auto view = any.as_sequence_container();
@@ -324,7 +324,7 @@ TEST_F(MetaContainer, ConstSequenceContainer) {
TEST_F(MetaContainer, ConstKeyValueAssociativeContainer) {
std::map<int, char> map{};
entt::meta_any any{std::cref(map)};
auto any = entt::make_meta_any<const std::map<int, char> &>(map);
auto view = any.as_associative_container();
@@ -360,7 +360,7 @@ TEST_F(MetaContainer, ConstKeyValueAssociativeContainer) {
TEST_F(MetaContainer, ConstKeyOnlyAssociativeContainer) {
std::set<int> set{};
entt::meta_any any{std::cref(set)};
auto any = entt::make_meta_any<const std::set<int> &>(set);
auto view = any.as_associative_container();
@@ -409,8 +409,8 @@ TEST_F(MetaContainer, SequenceContainerConstMetaAny) {
std::vector<int> vec{42};
test(vec);
test(std::ref(vec));
test(std::cref(vec));
test(entt::make_meta_any<std::vector<int> &>(vec));
test(entt::make_meta_any<const std::vector<int> &>(vec));
}
TEST_F(MetaContainer, KeyValueAssociativeContainerConstMetaAny) {
@@ -426,8 +426,8 @@ TEST_F(MetaContainer, KeyValueAssociativeContainerConstMetaAny) {
std::map<int, char> map{{2, 'c'}};
test(map);
test(std::ref(map));
test(std::cref(map));
test(entt::make_meta_any<std::map<int, char> &>(map));
test(entt::make_meta_any<const std::map<int, char> &>(map));
}
TEST_F(MetaContainer, KeyOnlyAssociativeContainerConstMetaAny) {
@@ -446,8 +446,8 @@ TEST_F(MetaContainer, KeyOnlyAssociativeContainerConstMetaAny) {
std::set<int> set{2};
test(set);
test(std::ref(set));
test(std::cref(set));
test(entt::make_meta_any<std::set<int> &>(set));
test(entt::make_meta_any<const std::set<int> &>(set));
}
TEST_F(MetaContainer, StdVectorBool) {
@@ -455,7 +455,7 @@ TEST_F(MetaContainer, StdVectorBool) {
using const_proxy_type = typename std::vector<bool>::const_reference;
std::vector<bool> vec{};
entt::meta_any any{std::ref(vec)};
auto any = entt::make_meta_any<std::vector<bool> &>(vec);
auto cany = std::as_const(any).as_ref();
auto view = any.as_sequence_container();

View File

@@ -155,7 +155,7 @@ TEST_F(MetaCtor, ConstNonConstRefArgs) {
int ivalue = 42;
char cvalue = 'c';
auto any = entt::resolve<clazz_t>().ctor<int, char>().invoke(std::ref(ivalue), std::cref(cvalue));
auto any = entt::resolve<clazz_t>().ctor<int, char>().invoke(entt::make_meta_any<int &>(ivalue), entt::make_meta_any<const char &>(cvalue));
ASSERT_TRUE(any);
ASSERT_EQ(any.cast<clazz_t>().i, 42);
@@ -187,8 +187,8 @@ TEST_F(MetaCtor, FuncConstNonConstRefArgs) {
int ivalue = 42;
auto ctor = entt::resolve<clazz_t>().ctor<int>();
auto any = ctor.invoke(std::ref(ivalue));
auto other = ctor.invoke(std::cref(ivalue));
auto any = ctor.invoke(entt::make_meta_any<int &>(ivalue));
auto other = ctor.invoke(entt::make_meta_any<const int &>(ivalue));
ASSERT_TRUE(any);
ASSERT_TRUE(other);
@@ -215,7 +215,7 @@ TEST_F(MetaCtor, ExternalMemberFunction) {
ASSERT_FALSE(registry.all_of<clazz_t>(entity));
const auto any = ctor.invoke(std::ref(registry), entity, 3, 'c');
const auto any = ctor.invoke(entt::make_meta_any<entt::registry &>(registry), entity, 3, 'c');
ASSERT_TRUE(any);
ASSERT_TRUE(registry.all_of<clazz_t>(entity));

View File

@@ -309,11 +309,11 @@ TEST_F(MetaData, SetByRef) {
int value{42};
ASSERT_EQ(any.cast<clazz_t>().i, 0);
ASSERT_TRUE(entt::resolve<clazz_t>().data("i"_hs).set(any, std::ref(value)));
ASSERT_TRUE(entt::resolve<clazz_t>().data("i"_hs).set(any, entt::make_meta_any<int &>(value)));
ASSERT_EQ(any.cast<clazz_t>().i, 42);
value = 3;
entt::meta_any wrapper{std::ref(value)};
auto wrapper = entt::make_meta_any<int &>(value);
ASSERT_TRUE(entt::resolve<clazz_t>().data("i"_hs).set(any, wrapper.as_ref()));
ASSERT_EQ(any.cast<clazz_t>().i, 3);
@@ -326,11 +326,11 @@ TEST_F(MetaData, SetByConstRef) {
int value{42};
ASSERT_EQ(any.cast<clazz_t>().i, 0);
ASSERT_TRUE(entt::resolve<clazz_t>().data("i"_hs).set(any, std::cref(value)));
ASSERT_TRUE(entt::resolve<clazz_t>().data("i"_hs).set(any, entt::make_meta_any<const int &>(value)));
ASSERT_EQ(any.cast<clazz_t>().i, 42);
value = 3;
entt::meta_any wrapper{std::cref(value)};
auto wrapper = entt::make_meta_any<const int &>(value);
ASSERT_TRUE(entt::resolve<clazz_t>().data("i"_hs).set(any, wrapper.as_ref()));
ASSERT_EQ(any.cast<clazz_t>().i, 3);

View File

@@ -74,8 +74,8 @@ TEST_F(MetaDtor, AsRefConstruction) {
ASSERT_EQ(clazz_t::counter, 0);
clazz_t instance{};
entt::meta_any any{std::ref(instance)};
entt::meta_any cany{std::cref(instance)};
auto any = entt::make_meta_any<clazz_t &>(instance);
auto cany = entt::make_meta_any<const clazz_t &>(instance);
auto cref = cany.as_ref();
auto ref = any.as_ref();

View File

@@ -332,7 +332,7 @@ TEST_F(MetaFunc, ArgsByRef) {
entt::meta_any any{3};
int value = 4;
ASSERT_EQ(func.invoke({}, std::ref(value)).cast<int>(), 8);
ASSERT_EQ(func.invoke({}, entt::make_meta_any<int &>(value)).cast<int>(), 8);
ASSERT_EQ(func.invoke({}, any.as_ref()).cast<int>(), 6);
ASSERT_EQ(any.cast<int>(), 6);
ASSERT_EQ(value, 8);
@@ -346,7 +346,7 @@ TEST_F(MetaFunc, ArgsByConstRef) {
entt::meta_any any{2};
int value = 3;
ASSERT_TRUE(func.invoke(instance, std::cref(value)));
ASSERT_TRUE(func.invoke(instance, entt::make_meta_any<const int &>(value)));
ASSERT_EQ(func_t::value, 9);
ASSERT_TRUE(func.invoke(instance, std::as_const(any).as_ref()));
@@ -434,7 +434,7 @@ TEST_F(MetaFunc, ExternalMemberFunction) {
ASSERT_FALSE(registry.all_of<func_t>(entity));
func.invoke({}, std::ref(registry), entity);
func.invoke({}, entt::make_meta_any<entt::registry &>(registry), entity);
ASSERT_TRUE(registry.all_of<func_t>(entity));
}

View File

@@ -42,7 +42,7 @@ TEST_F(MetaHandle, Functionalities) {
ASSERT_TRUE(handle->invoke("incr"_hs));
ASSERT_EQ(instance.value, 1);
entt::meta_any any{std::ref(instance)};
auto any = entt::make_meta_any<clazz_t &>(instance);
handle = entt::meta_handle{any};
ASSERT_FALSE(std::as_const(handle)->invoke("decr"_hs));

View File

@@ -182,7 +182,7 @@ TEST(MetaPointerLike, PointerToConstMoveOnlyType) {
TEST(MetaPointerLike, AsRef) {
int value = 0;
int * ptr = &value;
entt::meta_any any{std::ref(ptr)};
auto any = entt::make_meta_any<int * &>(ptr);
ASSERT_TRUE(any.type().is_pointer());
ASSERT_TRUE(any.type().is_pointer_like());
@@ -204,7 +204,7 @@ TEST(MetaPointerLike, AsRef) {
TEST(MetaPointerLike, AsConstRef) {
int value = 42;
int * ptr = &value;
entt::meta_any any{std::cref(ptr)};
auto any = entt::make_meta_any<int * const &>(ptr);
ASSERT_TRUE(any.type().is_pointer());
ASSERT_TRUE(any.type().is_pointer_like());
@@ -309,7 +309,7 @@ TEST(MetaPointerLike, DereferencePointerToFunction) {
TEST(MetaPointerLike, DereferenceSelfPointer) {
self_ptr obj{42};
entt::meta_any any{std::ref(obj)};
auto any = entt::make_meta_any<self_ptr &>(obj);
entt::meta_any deref = *any;
ASSERT_TRUE(deref);