fix value deref

This commit is contained in:
BlackMATov
2022-01-23 22:34:25 +07:00
parent f49dd09eca
commit d54194d52e
6 changed files with 22 additions and 18 deletions

View File

@@ -57,7 +57,7 @@ namespace meta_hpp
.deref = +[]([[maybe_unused]] const value& v) -> value { .deref = +[]([[maybe_unused]] const value& v) -> value {
if constexpr ( detail::has_value_deref_traits<T> ) { if constexpr ( detail::has_value_deref_traits<T> ) {
return value{*v.cast<T>()}; return detail::value_deref_traits<T>{}(v.cast<T>());
} else { } else {
throw std::logic_error("value type doesn't have value deref traits"); throw std::logic_error("value type doesn't have value deref traits");
} }

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "../../meta_base.hpp" #include "../../meta_base.hpp"
#include "../../meta_utilities.hpp"
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
@@ -14,16 +15,16 @@ namespace meta_hpp::detail
struct value_equals_traits; struct value_equals_traits;
template < typename T > template < typename T >
concept has_value_equals_traits = requires(const T& v) { concept has_value_equals_traits = requires(const T& l, const T& r) {
{ value_equals_traits<T>{}(v, v) } -> stdex::convertible_to<bool>; { value_equals_traits<T>{}(l, r) } -> stdex::convertible_to<bool>;
}; };
} }
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < typename T > template < typename T >
requires requires(const T& v) { requires requires(const T& l, const T& r) {
{ v == v } -> stdex::convertible_to<bool>; { l == r } -> stdex::convertible_to<bool>;
} }
struct value_equals_traits<T> { struct value_equals_traits<T> {
bool operator()(const T& l, const T& r) const { bool operator()(const T& l, const T& r) const {

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "../../meta_base.hpp" #include "../../meta_base.hpp"
#include "../../meta_utilities.hpp"
namespace meta_hpp::detail namespace meta_hpp::detail
{ {

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "../../meta_base.hpp" #include "../../meta_base.hpp"
#include "../../meta_utilities.hpp"
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
@@ -14,16 +15,16 @@ namespace meta_hpp::detail
struct value_less_traits; struct value_less_traits;
template < typename T > template < typename T >
concept has_value_less_traits = requires(const T& v) { concept has_value_less_traits = requires(const T& l, const T& r) {
{ value_less_traits<T>{}(v, v) } -> stdex::convertible_to<bool>; { value_less_traits<T>{}(l, r) } -> stdex::convertible_to<bool>;
}; };
} }
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < typename T > template < typename T >
requires requires(const T& v) { requires requires(const T& l, const T& r) {
{ v < v } -> stdex::convertible_to<bool>; { l < r } -> stdex::convertible_to<bool>;
} }
struct value_less_traits<T> { struct value_less_traits<T> {
bool operator()(const T& l, const T& r) const { bool operator()(const T& l, const T& r) const {

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "../../meta_base.hpp" #include "../../meta_base.hpp"
#include "../../meta_utilities.hpp"
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
@@ -14,8 +15,8 @@ namespace meta_hpp::detail
struct value_ostream_traits; struct value_ostream_traits;
template < typename T > template < typename T >
concept has_value_ostream_traits = requires(std::ostream& is, const T& v) { concept has_value_ostream_traits = requires(std::ostream& os, const T& v) {
{ value_ostream_traits<T>{}(is, v) } -> stdex::convertible_to<std::ostream&>; { value_ostream_traits<T>{}(os, v) } -> stdex::convertible_to<std::ostream&>;
}; };
} }
@@ -26,8 +27,8 @@ namespace meta_hpp::detail
{ os << v } -> stdex::convertible_to<std::ostream&>; { os << v } -> stdex::convertible_to<std::ostream&>;
} }
struct value_ostream_traits<T> { struct value_ostream_traits<T> {
std::ostream& operator()(std::ostream& is, const T& v) const { std::ostream& operator()(std::ostream& os, const T& v) const {
return is << v; return os << v;
} }
}; };
} }

View File

@@ -50,11 +50,11 @@ namespace
return {l.x + r.x, l.y + r.y}; return {l.x + r.x, l.y + r.y};
} }
bool operator<(const ivec2& l, const ivec2& r) noexcept { [[maybe_unused]] bool operator<(const ivec2& l, const ivec2& r) noexcept {
return (l.x < r.x) || (l.x == r.x && l.y < r.y); return (l.x < r.x) || (l.x == r.x && l.y < r.y);
} }
bool operator==(const ivec2& l, const ivec2& r) noexcept { [[maybe_unused]] bool operator==(const ivec2& l, const ivec2& r) noexcept {
return l.x == r.x && l.y == r.y; return l.x == r.x && l.y == r.y;
} }
} }
@@ -390,15 +390,15 @@ TEST_CASE("meta/meta_utilities/value") {
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_ctor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_ctor_counter == 0);
meta::value vv1{*vp}; [[maybe_unused]] meta::value vv1{*vp};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_ctor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_ctor_counter == 1);
meta::value vv2{*std::move(vp)}; [[maybe_unused]] meta::value vv2{*std::move(vp)};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_ctor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 2); CHECK(ivec2::copy_ctor_counter == 2);
meta::value vv3{*std::as_const(vp)}; [[maybe_unused]] meta::value vv3{*std::as_const(vp)};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_ctor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 3); CHECK(ivec2::copy_ctor_counter == 3);
} }