meta: non-const access to meta custom
This commit is contained in:
1
TODO
1
TODO
@@ -45,4 +45,3 @@ TODO:
|
||||
* natvis for meta_custom
|
||||
* meta: vectors for details and props
|
||||
* suppress -Wself-move on CI with g++13
|
||||
* meta_custom operator bool
|
||||
|
||||
@@ -843,7 +843,7 @@ struct meta_custom {
|
||||
* @tparam Type Type to which conversion is requested.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] operator const Type *() const noexcept {
|
||||
[[nodiscard]] operator Type *() const noexcept {
|
||||
return (type_id<Type>().hash() == node.type) ? std::static_pointer_cast<Type>(node.value).get() : nullptr;
|
||||
}
|
||||
|
||||
@@ -852,7 +852,7 @@ struct meta_custom {
|
||||
* @tparam Type Type to which conversion is requested.
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] operator const Type &() const noexcept {
|
||||
[[nodiscard]] operator Type &() const noexcept {
|
||||
ENTT_ASSERT(type_id<Type>().hash() == node.type, "Invalid type");
|
||||
return *std::static_pointer_cast<Type>(node.value);
|
||||
}
|
||||
|
||||
@@ -113,6 +113,17 @@ TEST_F(MetaCustom, Func) {
|
||||
ASSERT_EQ(static_cast<const int *>(entt::resolve<clazz>().func("g"_hs).custom()), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(MetaCustom, ConstNonConstAndAllInBetween) {
|
||||
testing::StaticAssertTypeEq<decltype(static_cast<int *>(entt::meta_custom{})), int *>();
|
||||
testing::StaticAssertTypeEq<decltype(static_cast<int &>(entt::meta_custom{})), int &>();
|
||||
testing::StaticAssertTypeEq<decltype(static_cast<const int *>(entt::meta_custom{})), const int *>();
|
||||
testing::StaticAssertTypeEq<decltype(static_cast<const int &>(entt::meta_custom{})), const int &>();
|
||||
|
||||
static_cast<char &>(entt::resolve<clazz>().custom()) = '\n';
|
||||
|
||||
ASSERT_EQ(*static_cast<const char *>(entt::resolve<clazz>().custom()), '\n');
|
||||
}
|
||||
|
||||
TEST_F(MetaCustom, ReRegistration) {
|
||||
using namespace entt::literals;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user