From 52c73817c8cb0ba016bfae9a56ecee40493981d7 Mon Sep 17 00:00:00 2001 From: sabudilovskiy Date: Thu, 12 Oct 2023 14:01:08 +0000 Subject: [PATCH] fix min and max --- src/openapi/base/array_traits.hpp | 16 ++++++++-------- src/openapi/base/preferences.hpp | 5 +++-- src/openapi/types/array_type.hpp | 12 ++++++------ src/utils/constexpr_string.hpp | 4 +++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/openapi/base/array_traits.hpp b/src/openapi/base/array_traits.hpp index 3333a5f1..ef2b4b16 100644 --- a/src/openapi/base/array_traits.hpp +++ b/src/openapi/base/array_traits.hpp @@ -16,7 +16,7 @@ concept HasMin = requires { T::kMin } - ->std::convertible_to>; + ->std::convertible_to>; }; template @@ -25,7 +25,7 @@ concept HasMax = requires { T::kMax } - ->std::convertible_to>; + ->std::convertible_to>; }; template @@ -58,7 +58,7 @@ constexpr auto _getMin() template constexpr auto _getMin() { - return utils::ConstexprOptional{utils::kNull}; + return utils::ConstexprOptional{utils::kNull}; } template @@ -70,7 +70,7 @@ constexpr auto _getMax() template constexpr auto _getMax() { - return utils::ConstexprOptional{utils::kNull}; + return utils::ConstexprOptional{utils::kNull}; } template @@ -89,12 +89,12 @@ constexpr auto _getUniqueItems() namespace traits { template -constexpr utils::ConstexprOptional GetMin() +constexpr utils::ConstexprOptional GetMin() { return detail::_getMin(); } template -constexpr utils::ConstexprOptional GetMax() +constexpr utils::ConstexprOptional GetMax() { return detail::_getMax(); } @@ -107,9 +107,9 @@ constexpr utils::ConstexprOptional GetUniqueItems() template struct ArrayHelperTraits : NamedHelperTraits { - static constexpr utils::ConstexprOptional min = + static constexpr utils::ConstexprOptional min = traits::GetMin(); - static constexpr utils::ConstexprOptional max = + static constexpr utils::ConstexprOptional max = traits::GetMax(); static constexpr utils::ConstexprOptional unique_items = traits::GetUniqueItems(); diff --git a/src/openapi/base/preferences.hpp b/src/openapi/base/preferences.hpp index 97670ea5..8da18e7c 100644 --- a/src/openapi/base/preferences.hpp +++ b/src/openapi/base/preferences.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include namespace openapi::preferences @@ -9,12 +10,12 @@ struct value_holder static auto constexpr kValue = value; }; -template +template struct Min : value_holder { }; -template +template struct Max : value_holder { }; diff --git a/src/openapi/types/array_type.hpp b/src/openapi/types/array_type.hpp index 16f684cc..c3fe627c 100644 --- a/src/openapi/types/array_type.hpp +++ b/src/openapi/types/array_type.hpp @@ -10,8 +10,8 @@ namespace openapi namespace detail { template Min = utils::kNull, - utils::ConstexprOptional Max = utils::kNull, + utils::ConstexprOptional Min = utils::kNull, + utils::ConstexprOptional Max = utils::kNull, utils::ConstexprOptional UniqueItems = utils::kNull> struct ArrayTraits : NamedTraits { @@ -31,9 +31,9 @@ struct ArrayTraitsHolder { std::array Name{}; size_t Name_was_changed = 0; - utils::ConstexprOptional Min = utils::kNull; + utils::ConstexprOptional Min = utils::kNull; size_t Min_was_changed = 0; - utils::ConstexprOptional Max = utils::kNull; + utils::ConstexprOptional Max = utils::kNull; size_t Max_was_changed = 0; utils::ConstexprOptional UniqueItems = utils::kNull; size_t UniqueItems_was_changed = 0; @@ -61,14 +61,14 @@ void consteval Apply(ArrayTraitsHolder&, const T&) ![] {}, "You are used unknown option"); } -template +template void consteval Apply(ArrayTraitsHolder& traits, preferences::Min) { traits.Min = value; traits.Min_was_changed++; } -template +template void consteval Apply(ArrayTraitsHolder& traits, preferences::Max) { traits.Max = value; diff --git a/src/utils/constexpr_string.hpp b/src/utils/constexpr_string.hpp index 88ea192e..d102d617 100644 --- a/src/utils/constexpr_string.hpp +++ b/src/utils/constexpr_string.hpp @@ -72,7 +72,9 @@ struct ConstexprString template ConstexprString(char const (&)[n]) -> ConstexprString; -template arr_> +using FixedString = std::array; + +template auto consteval MakeConstexprString() { constexpr auto real_end_it = std::find(begin(arr_), end(arr_), '\0');