mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
fix value deref
This commit is contained in:
@@ -57,7 +57,7 @@ namespace meta_hpp
|
||||
|
||||
.deref = +[]([[maybe_unused]] const value& v) -> value {
|
||||
if constexpr ( detail::has_value_deref_traits<T> ) {
|
||||
return value{*v.cast<T>()};
|
||||
return detail::value_deref_traits<T>{}(v.cast<T>());
|
||||
} else {
|
||||
throw std::logic_error("value type doesn't have value deref traits");
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../meta_base.hpp"
|
||||
#include "../../meta_utilities.hpp"
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
@@ -14,16 +15,16 @@ namespace meta_hpp::detail
|
||||
struct value_equals_traits;
|
||||
|
||||
template < typename T >
|
||||
concept has_value_equals_traits = requires(const T& v) {
|
||||
{ value_equals_traits<T>{}(v, v) } -> stdex::convertible_to<bool>;
|
||||
concept has_value_equals_traits = requires(const T& l, const T& r) {
|
||||
{ value_equals_traits<T>{}(l, r) } -> stdex::convertible_to<bool>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
requires requires(const T& v) {
|
||||
{ v == v } -> stdex::convertible_to<bool>;
|
||||
requires requires(const T& l, const T& r) {
|
||||
{ l == r } -> stdex::convertible_to<bool>;
|
||||
}
|
||||
struct value_equals_traits<T> {
|
||||
bool operator()(const T& l, const T& r) const {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../meta_base.hpp"
|
||||
#include "../../meta_utilities.hpp"
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../meta_base.hpp"
|
||||
#include "../../meta_utilities.hpp"
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
@@ -14,16 +15,16 @@ namespace meta_hpp::detail
|
||||
struct value_less_traits;
|
||||
|
||||
template < typename T >
|
||||
concept has_value_less_traits = requires(const T& v) {
|
||||
{ value_less_traits<T>{}(v, v) } -> stdex::convertible_to<bool>;
|
||||
concept has_value_less_traits = requires(const T& l, const T& r) {
|
||||
{ value_less_traits<T>{}(l, r) } -> stdex::convertible_to<bool>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
requires requires(const T& v) {
|
||||
{ v < v } -> stdex::convertible_to<bool>;
|
||||
requires requires(const T& l, const T& r) {
|
||||
{ l < r } -> stdex::convertible_to<bool>;
|
||||
}
|
||||
struct value_less_traits<T> {
|
||||
bool operator()(const T& l, const T& r) const {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../meta_base.hpp"
|
||||
#include "../../meta_utilities.hpp"
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
@@ -14,8 +15,8 @@ namespace meta_hpp::detail
|
||||
struct value_ostream_traits;
|
||||
|
||||
template < typename T >
|
||||
concept has_value_ostream_traits = requires(std::ostream& is, const T& v) {
|
||||
{ value_ostream_traits<T>{}(is, v) } -> stdex::convertible_to<std::ostream&>;
|
||||
concept has_value_ostream_traits = requires(std::ostream& os, const T& v) {
|
||||
{ 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&>;
|
||||
}
|
||||
struct value_ostream_traits<T> {
|
||||
std::ostream& operator()(std::ostream& is, const T& v) const {
|
||||
return is << v;
|
||||
std::ostream& operator()(std::ostream& os, const T& v) const {
|
||||
return os << v;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ namespace
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -390,15 +390,15 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
CHECK(ivec2::move_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::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::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::copy_ctor_counter == 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user