Skip to content

Commit

Permalink
fix min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Oct 12, 2023
1 parent aca9c71 commit 52c7381
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/openapi/base/array_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concept HasMin = requires
{
T::kMin
}
->std::convertible_to<utils::ConstexprOptional<size_t>>;
->std::convertible_to<utils::ConstexprOptional<std::int64_t>>;
};

template <typename T>
Expand All @@ -25,7 +25,7 @@ concept HasMax = requires
{
T::kMax
}
->std::convertible_to<utils::ConstexprOptional<size_t>>;
->std::convertible_to<utils::ConstexprOptional<std::int64_t>>;
};

template <typename T>
Expand Down Expand Up @@ -58,7 +58,7 @@ constexpr auto _getMin()
template <checks::HasNotMin T>
constexpr auto _getMin()
{
return utils::ConstexprOptional<size_t>{utils::kNull};
return utils::ConstexprOptional<std::int64_t>{utils::kNull};
}

template <checks::HasMax T>
Expand All @@ -70,7 +70,7 @@ constexpr auto _getMax()
template <checks::HasNotMax T>
constexpr auto _getMax()
{
return utils::ConstexprOptional<size_t>{utils::kNull};
return utils::ConstexprOptional<std::int64_t>{utils::kNull};
}

template <checks::HasUniqueItems T>
Expand All @@ -89,12 +89,12 @@ constexpr auto _getUniqueItems()
namespace traits
{
template <typename T>
constexpr utils::ConstexprOptional<size_t> GetMin()
constexpr utils::ConstexprOptional<std::int64_t> GetMin()
{
return detail::_getMin<T>();
}
template <typename T>
constexpr utils::ConstexprOptional<size_t> GetMax()
constexpr utils::ConstexprOptional<std::int64_t> GetMax()
{
return detail::_getMax<T>();
}
Expand All @@ -107,9 +107,9 @@ constexpr utils::ConstexprOptional<bool> GetUniqueItems()
template <typename Traits>
struct ArrayHelperTraits : NamedHelperTraits<Traits>
{
static constexpr utils::ConstexprOptional<size_t> min =
static constexpr utils::ConstexprOptional<std::int64_t> min =
traits::GetMin<Traits>();
static constexpr utils::ConstexprOptional<size_t> max =
static constexpr utils::ConstexprOptional<std::int64_t> max =
traits::GetMax<Traits>();
static constexpr utils::ConstexprOptional<bool> unique_items =
traits::GetUniqueItems<Traits>();
Expand Down
5 changes: 3 additions & 2 deletions src/openapi/base/preferences.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <cstdint>
#include <utils/constexpr_string.hpp>

namespace openapi::preferences
Expand All @@ -9,12 +10,12 @@ struct value_holder
static auto constexpr kValue = value;
};

template <size_t value>
template <std::int64_t value>
struct Min : value_holder<value>
{
};

template <size_t value>
template <std::int64_t value>
struct Max : value_holder<value>
{
};
Expand Down
12 changes: 6 additions & 6 deletions src/openapi/types/array_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace openapi
namespace detail
{
template <utils::ConstexprString Name,
utils::ConstexprOptional<size_t> Min = utils::kNull,
utils::ConstexprOptional<size_t> Max = utils::kNull,
utils::ConstexprOptional<std::int64_t> Min = utils::kNull,
utils::ConstexprOptional<std::int64_t> Max = utils::kNull,
utils::ConstexprOptional<bool> UniqueItems = utils::kNull>
struct ArrayTraits : NamedTraits<Name>
{
Expand All @@ -31,9 +31,9 @@ struct ArrayTraitsHolder
{
std::array<char, 256> Name{};
size_t Name_was_changed = 0;
utils::ConstexprOptional<size_t> Min = utils::kNull;
utils::ConstexprOptional<std::int64_t> Min = utils::kNull;
size_t Min_was_changed = 0;
utils::ConstexprOptional<size_t> Max = utils::kNull;
utils::ConstexprOptional<std::int64_t> Max = utils::kNull;
size_t Max_was_changed = 0;
utils::ConstexprOptional<bool> UniqueItems = utils::kNull;
size_t UniqueItems_was_changed = 0;
Expand Down Expand Up @@ -61,14 +61,14 @@ void consteval Apply(ArrayTraitsHolder&, const T&)
![] {}, "You are used unknown option");
}

template <size_t value>
template <std::int64_t value>
void consteval Apply(ArrayTraitsHolder& traits, preferences::Min<value>)
{
traits.Min = value;
traits.Min_was_changed++;
}

template <size_t value>
template <std::int64_t value>
void consteval Apply(ArrayTraitsHolder& traits, preferences::Max<value>)
{
traits.Max = value;
Expand Down
4 changes: 3 additions & 1 deletion src/utils/constexpr_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ struct ConstexprString
template <std::size_t n>
ConstexprString(char const (&)[n]) -> ConstexprString<n>;

template <std::array<char, 256> arr_>
using FixedString = std::array<char, 256>;

template <FixedString arr_>
auto consteval MakeConstexprString()
{
constexpr auto real_end_it = std::find(begin(arr_), end(arr_), '\0');
Expand Down

0 comments on commit 52c7381

Please sign in to comment.