Skip to content

Commit cba31e0

Browse files
committed
meta: as_is -> as_value / as_auto -> as_is (breaking)
1 parent d366a5e commit cba31e0

File tree

8 files changed

+64
-63
lines changed

8 files changed

+64
-63
lines changed

TODO

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ TODO:
3535
* introduce compile-time flag to skip dll-only checks in basic_any
3636
* find a way to test deleter and the absence of it in basic_any
3737
* archetype-like a-l� EnTT support (see my own notes)
38-
* rename meta policy as_is in as_copy
38+
* meta_factory: add a replace flag to traits to get around the |-only mechanism
39+
* support searching meta data and func only on top level types, no bases

docs/md/meta.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ other problems.
787787

788788
There are a few alternatives available at the moment:
789789

790-
* The _as-is_ policy, associated with the type `entt::as_is_t`.<br/>
790+
* The _as-value_ policy, associated with the type `entt::as_value_t`.<br/>
791791
This is the default policy. In general, it should never be used explicitly,
792792
since it is implicitly selected if no other policy is specified.<br/>
793793
In this case, the return values of the functions as well as the properties
@@ -825,12 +825,12 @@ There are a few alternatives available at the moment:
825825
`as_ref_t` _adapts_ to the constness of the passed object and to that of the
826826
return type if any.
827827

828-
* The _as-auto_ policy, associated with the type `entt::as_auto_t`.<br/>
828+
* The _as-is_ policy, associated with the type `entt::as_is_t`.<br/>
829829
Useful for decoupling meta type creation code from calling code while still
830830
preserving the behavior of data members and member functions as defined:
831831

832832
```cpp
833-
entt::meta_factory<my_type>{}.func<&my_type::any_member, entt::as_auto_t>("member"_hs);
833+
entt::meta_factory<my_type>{}.func<&my_type::any_member, entt::as_is_t>("member"_hs);
834834
```
835835

836836
For data members or member functions that return a reference type, the value

src/entt/meta/factory.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class meta_factory: private internal::basic_meta_factory {
255255
* @tparam Policy Optional policy (no policy set by default).
256256
* @return A meta factory for the parent type.
257257
*/
258-
template<auto Candidate, typename Policy = as_is_t>
258+
template<auto Candidate, typename Policy = as_value_t>
259259
meta_factory ctor() noexcept {
260260
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
261261
static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");
@@ -292,7 +292,7 @@ class meta_factory: private internal::basic_meta_factory {
292292
* @param name A custom unique identifier as a **string literal**.
293293
* @return A meta factory for the given type.
294294
*/
295-
template<auto Data, typename Policy = as_is_t>
295+
template<auto Data, typename Policy = as_value_t>
296296
meta_factory data(const char *name) noexcept {
297297
return data<Data, Policy>(hashed_string::value(name), name);
298298
}
@@ -311,7 +311,7 @@ class meta_factory: private internal::basic_meta_factory {
311311
* @param name An optional name for the meta data as a **string literal**.
312312
* @return A meta factory for the parent type.
313313
*/
314-
template<auto Data, typename Policy = as_is_t>
314+
template<auto Data, typename Policy = as_value_t>
315315
meta_factory data(const id_type id, const char *name = nullptr) noexcept {
316316
if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
317317
using data_type = std::invoke_result_t<decltype(Data), Type &>;
@@ -361,7 +361,7 @@ class meta_factory: private internal::basic_meta_factory {
361361
* @param name A custom unique identifier as a **string literal**.
362362
* @return A meta factory for the given type.
363363
*/
364-
template<auto Setter, auto Getter, typename Policy = as_is_t>
364+
template<auto Setter, auto Getter, typename Policy = as_value_t>
365365
meta_factory data(const char *name) noexcept {
366366
return data<Setter, Getter, Policy>(hashed_string::value(name), name);
367367
}
@@ -387,7 +387,7 @@ class meta_factory: private internal::basic_meta_factory {
387387
* @param name An optional name for the meta data as a **string literal**.
388388
* @return A meta factory for the parent type.
389389
*/
390-
template<auto Setter, auto Getter, typename Policy = as_is_t>
390+
template<auto Setter, auto Getter, typename Policy = as_value_t>
391391
meta_factory data(const id_type id, const char *name = nullptr) noexcept {
392392
using descriptor = meta_function_helper_t<Type, decltype(Getter)>;
393393
static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");
@@ -430,7 +430,7 @@ class meta_factory: private internal::basic_meta_factory {
430430
* @param name A custom unique identifier as a **string literal**.
431431
* @return A meta factory for the given type.
432432
*/
433-
template<auto Candidate, typename Policy = as_is_t>
433+
template<auto Candidate, typename Policy = as_value_t>
434434
meta_factory func(const char *name) noexcept {
435435
return func<Candidate, Policy>(hashed_string::value(name), name);
436436
}
@@ -449,7 +449,7 @@ class meta_factory: private internal::basic_meta_factory {
449449
* @param name An optional name for the function as a **string literal**.
450450
* @return A meta factory for the parent type.
451451
*/
452-
template<auto Candidate, typename Policy = as_is_t>
452+
template<auto Candidate, typename Policy = as_value_t>
453453
meta_factory func(const id_type id, const char *name = nullptr) noexcept {
454454
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
455455
static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");

src/entt/meta/policy.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct meta_policy {};
1414
/*! @endcond */
1515

1616
/*! @brief Empty class type used to request the _as-is_ policy. */
17-
struct as_is_t final: private internal::meta_policy {
17+
struct as_value_t final: private internal::meta_policy {
1818
/*! @cond TURN_OFF_DOXYGEN */
1919
template<typename>
2020
static constexpr bool value = true;
@@ -46,7 +46,7 @@ struct as_cref_t final: private internal::meta_policy {
4646
};
4747

4848
/*! @brief Empty class type used to request the _as auto_ policy. */
49-
struct as_auto_t final: private internal::meta_policy {
49+
struct as_is_t final: private internal::meta_policy {
5050
/*! @cond TURN_OFF_DOXYGEN */
5151
template<typename>
5252
static constexpr bool value = true;

src/entt/meta/utility.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ using meta_function_helper_t = typename meta_function_helper<Type, Candidate>::t
164164
* @param value Value to wrap.
165165
* @return A meta any containing the returned value, if any.
166166
*/
167-
template<typename Policy = as_is_t, typename Type>
167+
template<typename Policy = as_value_t, typename Type>
168168
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_dispatch(const meta_ctx &ctx, [[maybe_unused]] Type &&value) {
169169
if constexpr(std::is_same_v<Policy, as_cref_t>) {
170170
static_assert(std::is_lvalue_reference_v<Type>, "Invalid type");
171171
return meta_any{ctx, std::in_place_type<const std::remove_reference_t<Type> &>, std::as_const(value)};
172-
} else if constexpr(std::is_same_v<Policy, as_ref_t> || (std::is_same_v<Policy, as_auto_t> && std::is_lvalue_reference_v<Type>)) {
172+
} else if constexpr(std::is_same_v<Policy, as_ref_t> || (std::is_same_v<Policy, as_is_t> && std::is_lvalue_reference_v<Type>)) {
173173
return meta_any{ctx, std::in_place_type<Type>, value};
174174
} else if constexpr(std::is_same_v<Policy, as_void_t>) {
175175
return meta_any{ctx, std::in_place_type<void>};
@@ -185,7 +185,7 @@ template<typename Policy = as_is_t, typename Type>
185185
* @param value Value to wrap.
186186
* @return A meta any containing the returned value, if any.
187187
*/
188-
template<typename Policy = as_is_t, typename Type>
188+
template<typename Policy = as_value_t, typename Type>
189189
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_dispatch(Type &&value) {
190190
return meta_dispatch<Policy, Type>(locator<meta_ctx>::value_or(), std::forward<Type>(value));
191191
}
@@ -313,7 +313,7 @@ template<typename Type, auto Data>
313313
* @param instance An opaque instance of the underlying type, if required.
314314
* @return A meta any containing the value of the underlying variable.
315315
*/
316-
template<typename Type, auto Data, typename Policy = as_is_t>
316+
template<typename Type, auto Data, typename Policy = as_value_t>
317317
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_getter(meta_handle instance) {
318318
if constexpr(std::is_member_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
319319
if constexpr(!std::is_array_v<std::remove_const_t<std::remove_reference_t<std::invoke_result_t<decltype(Data), Type &>>>>) {
@@ -352,7 +352,7 @@ template<typename Type, auto Data, typename Policy = as_is_t>
352352
* @param args Parameters to use to _invoke_ the object.
353353
* @return A meta any containing the returned value, if any.
354354
*/
355-
template<typename Type, typename Policy = as_is_t, typename Candidate>
355+
template<typename Type, typename Policy = as_value_t, typename Candidate>
356356
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_invoke(meta_handle instance, Candidate &&candidate, meta_any *const args) {
357357
return internal::meta_invoke<Type, Policy>(*instance.operator->(), std::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
358358
}
@@ -366,7 +366,7 @@ template<typename Type, typename Policy = as_is_t, typename Candidate>
366366
* @param args Parameters to use to invoke the function.
367367
* @return A meta any containing the returned value, if any.
368368
*/
369-
template<typename Type, auto Candidate, typename Policy = as_is_t>
369+
template<typename Type, auto Candidate, typename Policy = as_value_t>
370370
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_invoke(meta_handle instance, meta_any *const args) {
371371
return internal::meta_invoke<Type, Policy>(*instance.operator->(), Candidate, args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<decltype(Candidate)>>::args_type::size>{});
372372
}
@@ -416,7 +416,7 @@ template<typename Type, typename... Args>
416416
* @param args Parameters to use to _invoke_ the object.
417417
* @return A meta any containing the returned value, if any.
418418
*/
419-
template<typename Type, typename Policy = as_is_t, typename Candidate>
419+
template<typename Type, typename Policy = as_value_t, typename Candidate>
420420
[[nodiscard]] meta_any meta_construct(const meta_ctx &ctx, Candidate &&candidate, meta_any *const args) {
421421
if constexpr(meta_function_helper_t<Type, Candidate>::is_static || std::is_class_v<std::remove_const_t<std::remove_reference_t<Candidate>>>) {
422422
meta_any placeholder{meta_ctx_arg, ctx};
@@ -436,7 +436,7 @@ template<typename Type, typename Policy = as_is_t, typename Candidate>
436436
* @param args Parameters to use to _invoke_ the object.
437437
* @return A meta any containing the returned value, if any.
438438
*/
439-
template<typename Type, typename Policy = as_is_t, typename Candidate>
439+
template<typename Type, typename Policy = as_value_t, typename Candidate>
440440
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_construct(Candidate &&candidate, meta_any *const args) {
441441
return meta_construct<Type, Policy>(locator<meta_ctx>::value_or(), std::forward<Candidate>(candidate), args);
442442
}
@@ -455,7 +455,7 @@ template<typename Type, typename Policy = as_is_t, typename Candidate>
455455
* @param args Parameters to use to invoke the function.
456456
* @return A meta any containing the returned value, if any.
457457
*/
458-
template<typename Type, auto Candidate, typename Policy = as_is_t>
458+
template<typename Type, auto Candidate, typename Policy = as_value_t>
459459
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_construct(const meta_ctx &ctx, meta_any *const args) {
460460
return meta_construct<Type, Policy>(ctx, Candidate, args);
461461
}
@@ -468,7 +468,7 @@ template<typename Type, auto Candidate, typename Policy = as_is_t>
468468
* @param args Parameters to use to invoke the function.
469469
* @return A meta any containing the returned value, if any.
470470
*/
471-
template<typename Type, auto Candidate, typename Policy = as_is_t>
471+
template<typename Type, auto Candidate, typename Policy = as_value_t>
472472
[[nodiscard]] std::enable_if_t<is_meta_policy_v<Policy>, meta_any> meta_construct(meta_any *const args) {
473473
return meta_construct<Type, Candidate, Policy>(locator<meta_ctx>::value_or(), args);
474474
}

test/entt/meta/meta_data.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ struct MetaData: ::testing::Test {
9898
.conv<int>();
9999

100100
entt::meta_factory<clazz>{}
101-
.data<&clazz::i, entt::as_auto_t>("ai"_hs)
102-
.data<&clazz::j, entt::as_auto_t>("aj"_hs)
103-
.data<&clazz::h, entt::as_auto_t>("ah"_hs)
104-
.data<&clazz::k, entt::as_auto_t>("ak"_hs)
105-
.data<nullptr, &clazz::operator int, entt::as_auto_t>("ao"_hs);
101+
.data<&clazz::i, entt::as_is_t>("ir"_hs)
102+
.data<&clazz::j, entt::as_is_t>("jc"_hs)
103+
.data<&clazz::h, entt::as_is_t>("hr"_hs)
104+
.data<&clazz::k, entt::as_is_t>("kc"_hs)
105+
.data<nullptr, &clazz::operator int, entt::as_is_t>("ov"_hs);
106106

107107
entt::meta_factory<setter_getter>{}
108108
.type("setter_getter"_hs)
@@ -548,38 +548,38 @@ TEST_F(MetaData, AsVoid) {
548548
ASSERT_EQ(data.get(instance), entt::meta_any{std::in_place_type<void>});
549549
}
550550

551-
TEST_F(MetaData, AsAuto) {
551+
TEST_F(MetaData, AsIs) {
552552
using namespace entt::literals;
553553

554554
auto type = entt::resolve<clazz>();
555555
entt::meta_data data{};
556556
clazz instance{};
557557

558-
data = type.data("ai"_hs);
558+
data = type.data("ir"_hs);
559559

560560
ASSERT_TRUE(data);
561561
ASSERT_EQ(data.type(), entt::resolve<int>());
562562
ASSERT_EQ(data.get(instance).base().policy(), entt::any_policy::ref);
563563

564-
data = type.data("aj"_hs);
564+
data = type.data("jc"_hs);
565565

566566
ASSERT_TRUE(data);
567567
ASSERT_EQ(data.type(), entt::resolve<int>());
568568
ASSERT_EQ(data.get(instance).base().policy(), entt::any_policy::cref);
569569

570-
data = type.data("ah"_hs);
570+
data = type.data("hr"_hs);
571571

572572
ASSERT_TRUE(data);
573573
ASSERT_EQ(data.type(), entt::resolve<int>());
574574
ASSERT_EQ(data.get(instance).base().policy(), entt::any_policy::ref);
575575

576-
data = type.data("ak"_hs);
576+
data = type.data("kc"_hs);
577577

578578
ASSERT_TRUE(data);
579579
ASSERT_EQ(data.type(), entt::resolve<int>());
580580
ASSERT_EQ(data.get(instance).base().policy(), entt::any_policy::cref);
581581

582-
data = type.data("ao"_hs);
582+
data = type.data("ov"_hs);
583583

584584
ASSERT_TRUE(data);
585585
ASSERT_EQ(data.type(), entt::resolve<int>());

test/entt/meta/meta_func.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ struct MetaFunc: ::testing::Test {
139139
.conv<int>();
140140

141141
entt::meta_factory<function>{}
142-
.func<&function::a, entt::as_auto_t>("aa"_hs)
143-
.func<&function::v, entt::as_auto_t>("av"_hs)
144-
.func<&function::operator int, entt::as_auto_t>("ao"_hs)
145-
.func<&function::g, entt::as_auto_t>("ag"_hs);
142+
.func<&function::a, entt::as_is_t>("ar"_hs)
143+
.func<&function::v, entt::as_is_t>("vc"_hs)
144+
.func<&function::operator int, entt::as_is_t>("ov"_hs)
145+
.func<&function::g, entt::as_is_t>("ge"_hs);
146146
}
147147

148148
void TearDown() override {
@@ -509,32 +509,32 @@ TEST_F(MetaFunc, AsVoid) {
509509
ASSERT_EQ(value, instance.value);
510510
}
511511

512-
TEST_F(MetaFunc, AsAuto) {
512+
TEST_F(MetaFunc, AsIs) {
513513
using namespace entt::literals;
514514

515515
auto type = entt::resolve<function>();
516516
entt::meta_func func{};
517517
function instance{3};
518518

519-
func = type.func("aa"_hs);
519+
func = type.func("ar"_hs);
520520

521521
ASSERT_TRUE(func);
522522
ASSERT_EQ(func.ret(), entt::resolve<int>());
523523
ASSERT_EQ(func.invoke(instance).base().policy(), entt::any_policy::ref);
524524

525-
func = type.func("av"_hs);
525+
func = type.func("vc"_hs);
526526

527527
ASSERT_TRUE(func);
528528
ASSERT_EQ(func.ret(), entt::resolve<int>());
529529
ASSERT_EQ(func.invoke(instance, 3).base().policy(), entt::any_policy::cref);
530530

531-
func = type.func("ao"_hs);
531+
func = type.func("ov"_hs);
532532

533533
ASSERT_TRUE(func);
534534
ASSERT_EQ(func.ret(), entt::resolve<int>());
535535
ASSERT_EQ(func.invoke(instance).base().policy(), entt::any_policy::embedded);
536536

537-
func = type.func("ag"_hs);
537+
func = type.func("ge"_hs);
538538

539539
ASSERT_TRUE(func);
540540
ASSERT_EQ(func.ret(), entt::resolve<void>());

test/entt/meta/meta_utility.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,41 @@ TEST_F(MetaUtility, MetaDispatch) {
6262
auto as_cref = entt::meta_dispatch<entt::as_cref_t>(value);
6363
auto as_ref = entt::meta_dispatch<entt::as_ref_t>(value);
6464
auto as_void = entt::meta_dispatch<entt::as_void_t>(value);
65-
auto as_auto_copy = entt::meta_dispatch<entt::as_auto_t>(static_cast<int &&>(value));
66-
auto as_auto_cref = entt::meta_dispatch<entt::as_auto_t>(std::as_const(value));
67-
auto as_auto_ref = entt::meta_dispatch<entt::as_auto_t>(value);
68-
auto as_is = entt::meta_dispatch(value);
65+
auto as_is_copy = entt::meta_dispatch<entt::as_is_t>(static_cast<int &&>(value));
66+
auto as_is_cref = entt::meta_dispatch<entt::as_is_t>(std::as_const(value));
67+
auto as_is_ref = entt::meta_dispatch<entt::as_is_t>(value);
68+
auto as_value = entt::meta_dispatch(value);
6969

7070
ASSERT_EQ(as_cref.type(), entt::resolve<int>());
7171
ASSERT_EQ(as_ref.type(), entt::resolve<int>());
7272
ASSERT_EQ(as_void.type(), entt::resolve<void>());
73-
ASSERT_EQ(as_auto_copy.type(), entt::resolve<int>());
74-
ASSERT_EQ(as_auto_cref.type(), entt::resolve<int>());
75-
ASSERT_EQ(as_auto_ref.type(), entt::resolve<int>());
76-
ASSERT_EQ(as_is.type(), entt::resolve<int>());
73+
ASSERT_EQ(as_is_copy.type(), entt::resolve<int>());
74+
ASSERT_EQ(as_is_cref.type(), entt::resolve<int>());
75+
ASSERT_EQ(as_is_ref.type(), entt::resolve<int>());
76+
ASSERT_EQ(as_value.type(), entt::resolve<int>());
7777

7878
ASSERT_EQ(as_cref.base().policy(), entt::any_policy::cref);
7979
ASSERT_EQ(as_ref.base().policy(), entt::any_policy::ref);
8080
ASSERT_EQ(as_void.base().policy(), entt::any_policy::empty);
81-
ASSERT_EQ(as_auto_copy.base().policy(), entt::any_policy::embedded);
82-
ASSERT_EQ(as_auto_cref.base().policy(), entt::any_policy::cref);
83-
ASSERT_EQ(as_auto_ref.base().policy(), entt::any_policy::ref);
84-
ASSERT_EQ(as_is.base().policy(), entt::any_policy::embedded);
81+
ASSERT_EQ(as_is_copy.base().policy(), entt::any_policy::embedded);
82+
ASSERT_EQ(as_is_cref.base().policy(), entt::any_policy::cref);
83+
ASSERT_EQ(as_is_ref.base().policy(), entt::any_policy::ref);
84+
ASSERT_EQ(as_value.base().policy(), entt::any_policy::embedded);
8585

8686
ASSERT_EQ(as_cref.try_cast<int>(), nullptr);
8787
ASSERT_NE(as_cref.try_cast<const int>(), nullptr);
8888
ASSERT_NE(as_ref.try_cast<int>(), nullptr);
89-
ASSERT_NE(as_auto_copy.try_cast<int>(), nullptr);
90-
ASSERT_EQ(as_auto_cref.try_cast<int>(), nullptr);
91-
ASSERT_NE(as_auto_ref.try_cast<int>(), nullptr);
92-
ASSERT_NE(as_is.try_cast<int>(), nullptr);
89+
ASSERT_NE(as_is_copy.try_cast<int>(), nullptr);
90+
ASSERT_EQ(as_is_cref.try_cast<int>(), nullptr);
91+
ASSERT_NE(as_is_ref.try_cast<int>(), nullptr);
92+
ASSERT_NE(as_value.try_cast<int>(), nullptr);
9393

9494
ASSERT_EQ(as_cref.cast<int>(), 2);
9595
ASSERT_EQ(as_ref.cast<int>(), 2);
96-
ASSERT_EQ(as_auto_copy.cast<int>(), 2);
97-
ASSERT_EQ(as_auto_cref.cast<int>(), 2);
98-
ASSERT_EQ(as_auto_ref.cast<int>(), 2);
99-
ASSERT_EQ(as_is.cast<int>(), 2);
96+
ASSERT_EQ(as_is_copy.cast<int>(), 2);
97+
ASSERT_EQ(as_is_cref.cast<int>(), 2);
98+
ASSERT_EQ(as_is_ref.cast<int>(), 2);
99+
ASSERT_EQ(as_value.cast<int>(), 2);
100100
}
101101

102102
TEST_F(MetaUtility, MetaDispatchMetaAny) {

0 commit comments

Comments
 (0)