fix uvalue deref traits

ref: https://github.com/BlackMATov/meta.hpp/issues/100
This commit is contained in:
BlackMATov
2024-09-05 07:18:15 +07:00
parent 5d5ba52045
commit 41855b3ed7
2 changed files with 40 additions and 5 deletions

View File

@@ -107,11 +107,17 @@ namespace
bool operator==(const ivec2_big& l, const ivec2_big& r) noexcept {
return l.x == r.x && l.y == r.y;
}
struct deref_custom_class {
int operator*() const { return 42; }
};
}
META_HPP_DECLARE_COPY_TRAITS_FOR(ivec2)
META_HPP_DECLARE_COPY_TRAITS_FOR(ivec2_big)
META_HPP_DECLARE_DEREF_TRAITS_FOR(deref_custom_class)
TEST_CASE("meta/meta_utilities/value/_") {
namespace meta = meta_hpp;
@@ -645,6 +651,18 @@ TEST_CASE("meta/meta_utilities/value") {
meta::uvalue v{std::make_unique<int>(42)};
CHECK((*v).as<int>() == 42);
}
{
CHECK(meta::uvalue{std::make_shared<std::vector<std::shared_ptr<int>>>()}.has_deref_op());
CHECK_FALSE(meta::uvalue{std::make_shared<std::vector<std::unique_ptr<int>>>()}.has_deref_op());
}
{
const meta::uvalue v{deref_custom_class{}};
CHECK(v.has_deref_op());
const meta::uvalue u = *v;
CHECK(u.get_type() == meta::resolve_type<int>());
CHECK(u.as<int>() == 42);
}
}
SUBCASE("less/equal") {