remove fully dynamic less and equal uvalue's operators

This commit is contained in:
BlackMATov
2022-12-30 15:10:44 +07:00
parent 398d4012f9
commit 80c82b1027
10 changed files with 24 additions and 287 deletions

View File

@@ -1,34 +0,0 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021-2022, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "../../meta_base.hpp"
#include "../../meta_uvalue.hpp"
namespace meta_hpp::detail
{
template < typename T >
struct equals_traits;
template < typename T >
concept has_equals_traits = requires(const T& l, const T& r) {
{ equals_traits<T>{}(l, r) } -> std::convertible_to<bool>;
};
}
namespace meta_hpp::detail
{
template < typename T >
requires requires(const T& l, const T& r) {
{ std::equal_to<>{}(l, r) } -> std::convertible_to<bool>;
}
struct equals_traits<T> {
bool operator()(const T& l, const T& r) const {
return std::equal_to<>{}(l, r);
}
};
}

View File

@@ -1,34 +0,0 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021-2022, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "../../meta_base.hpp"
#include "../../meta_uvalue.hpp"
namespace meta_hpp::detail
{
template < typename T >
struct less_traits;
template < typename T >
concept has_less_traits = requires(const T& l, const T& r) {
{ less_traits<T>{}(l, r) } -> std::convertible_to<bool>;
};
}
namespace meta_hpp::detail
{
template < typename T >
requires requires(const T& l, const T& r) {
{ std::less<>{}(l, r) } -> std::convertible_to<bool>;
}
struct less_traits<T> {
bool operator()(const T& l, const T& r) const {
return std::less<>{}(l, r);
}
};
}

View File

@@ -270,8 +270,8 @@ namespace meta_hpp
[[nodiscard]] evalue get_evalue(std::string_view name) const noexcept;
template < typename Value >
[[nodiscard]] std::string_view value_to_name(Value&& value) const noexcept;
template < detail::enum_kind Enum >
[[nodiscard]] std::string_view value_to_name(Enum value) const noexcept;
[[nodiscard]] uvalue name_to_value(std::string_view name) const noexcept;
private:
detail::enum_type_data* data_{};

View File

@@ -69,11 +69,9 @@ namespace meta_hpp
return evalue{};
}
template < typename Value >
std::string_view enum_type::value_to_name(Value&& value) const noexcept {
const detail::uarg value_arg{std::forward<Value>(value)};
if ( value_arg.get_raw_type() != *this ) {
template < detail::enum_kind Enum >
std::string_view enum_type::value_to_name(Enum value) const noexcept {
if ( resolve_type<Enum>() != *this ) {
return std::string_view{};
}

View File

@@ -11,10 +11,8 @@
#include "../meta_uvalue.hpp"
#include "../meta_detail/value_traits/deref_traits.hpp"
#include "../meta_detail/value_traits/equals_traits.hpp"
#include "../meta_detail/value_traits/index_traits.hpp"
#include "../meta_detail/value_traits/istream_traits.hpp"
#include "../meta_detail/value_traits/less_traits.hpp"
#include "../meta_detail/value_traits/ostream_traits.hpp"
#include "../meta_detail/value_utilities/utraits.hpp"
@@ -34,9 +32,6 @@ namespace meta_hpp
uvalue (*const deref)(const uvalue& from);
uvalue (*const index)(const uvalue& from, std::size_t);
bool (*const less)(const uvalue&, const uvalue&);
bool (*const equals)(const uvalue&, const uvalue&);
std::istream& (*const istream)(std::istream&, uvalue&);
std::ostream& (*const ostream)(std::ostream&, const uvalue&);
@@ -200,22 +195,6 @@ namespace meta_hpp
}
},
.less = +[]([[maybe_unused]] const uvalue& l, [[maybe_unused]] const uvalue& r) -> bool {
if constexpr ( detail::has_less_traits<Tp> ) {
return detail::less_traits<Tp>{}(l.get_as<Tp>(), r.get_as<Tp>());
} else {
detail::throw_exception_with("value type doesn't have value less traits");
}
},
.equals = +[]([[maybe_unused]] const uvalue& l, [[maybe_unused]] const uvalue& r) -> bool {
if constexpr ( detail::has_equals_traits<Tp> ) {
return detail::equals_traits<Tp>{}(l.get_as<Tp>(), r.get_as<Tp>());
} else {
detail::throw_exception_with("value type doesn't have value equals traits");
}
},
.istream = +[]([[maybe_unused]] std::istream& is, [[maybe_unused]] uvalue& v) -> std::istream& {
if constexpr ( detail::has_istream_traits<Tp> && !detail::pointer_kind<Tp> ) {
return detail::istream_traits<Tp>{}(is, v.get_as<Tp>());
@@ -494,7 +473,7 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename T >
template < detail::decay_non_value_kind T >
[[nodiscard]] bool operator<(const uvalue& l, const T& r) {
if ( !static_cast<bool>(l) ) {
return true;
@@ -506,7 +485,7 @@ namespace meta_hpp
return (l_type < r_type) || (l_type == r_type && l.get_as<T>() < r);
}
template < typename T >
template < detail::decay_non_value_kind T >
[[nodiscard]] bool operator<(const T& l, const uvalue& r) {
if ( !static_cast<bool>(r) ) {
return false;
@@ -517,26 +496,11 @@ namespace meta_hpp
return (l_type < r_type) || (l_type == r_type && l < r.get_as<T>());
}
[[nodiscard]] inline bool operator<(const uvalue& l, const uvalue& r) {
if ( !static_cast<bool>(r) ) {
return false;
}
if ( !static_cast<bool>(l) ) {
return true;
}
const any_type& l_type = l.get_type();
const any_type& r_type = r.get_type();
return (l_type < r_type) || (l_type == r_type && l.vtable_->less(l, r));
}
}
namespace meta_hpp
{
template < typename T >
template < detail::decay_non_value_kind T >
[[nodiscard]] bool operator==(const uvalue& l, const T& r) {
if ( !static_cast<bool>(l) ) {
return false;
@@ -548,7 +512,7 @@ namespace meta_hpp
return l_type == r_type && l.get_as<T>() == r;
}
template < typename T >
template < detail::decay_non_value_kind T >
[[nodiscard]] bool operator==(const T& l, const uvalue& r) {
if ( !static_cast<bool>(r) ) {
return false;
@@ -559,21 +523,6 @@ namespace meta_hpp
return l_type == r_type && l == r.get_as<T>();
}
[[nodiscard]] inline bool operator==(const uvalue& l, const uvalue& r) {
if ( static_cast<bool>(l) != static_cast<bool>(r) ) {
return false;
}
if ( !static_cast<bool>(l) ) {
return true;
}
const any_type& l_type = l.get_type();
const any_type& r_type = r.get_type();
return l_type == r_type && l.vtable_->equals(l, r);
}
}
namespace meta_hpp