Skip to content

Commit

Permalink
Make min function acting on values uniformly callable.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaxyM authored Aug 20, 2024
1 parent 1aa544a commit 069d95c
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions include/crap/algorithm.d/minvalue.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
#ifndef CRAP_ALGORITHM_MINVALUE
#define CRAP_ALGORITHM_MINVALUE

#include <type_traits>

#include "../numeric.d/reducevalue.h"
#include "../version.d/libintegralconstantcallable.h"

namespace crap
{
template <class Type, template <Type, Type> class, Type...> struct minValue;

template <class Type, template <Type, Type> class Operator, Type Value>
struct minValue<Type, Operator, Value>
{
constexpr const static Type value = Value;
using value_type = decltype(value);
constexpr operator value_type () const noexcept;
};
: std :: integral_constant<Type, Value> {};

template <class Type, template <Type, Type> class Operator, Type Value1, Type Value2>
struct minValue<Type, Operator, Value1, Value2>
{
constexpr const static Type value = ((Operator <Value1, Value2> :: value) ? Value1 : Value2);
using value_type = decltype(value);
constexpr operator value_type () const noexcept;
};
: std :: integral_constant<Type, ((Operator <Value1, Value2> :: value) ? Value1 : Value2)> {};

template <class Type, template <Type, Type> class Operator, Type ... Values>
struct minValue
Expand All @@ -33,27 +28,25 @@ namespace crap
constexpr const static Type value = reduceValue <Type, This, Values...> :: value;
using value_type = decltype(value);
constexpr operator value_type () const noexcept;
#if (crap_lib_integral_constant_callable >= 201304L)
constexpr value_type operator () () const noexcept;
#endif
};
}

template <class Type, template <Type, Type> class Operator, Type Value1>
inline constexpr crap :: minValue <Type, Operator, Value1> :: operator
typename crap :: minValue <Type, Operator, Value1> :: value_type () const noexcept
{
return crap :: minValue <Type, Operator, Value1> :: value;
}

template <class Type, template <Type, Type> class Operator, Type Value1, Type Value2>
inline constexpr crap :: minValue <Type, Operator, Value1, Value2> :: operator
typename crap :: minValue <Type, Operator, Value1, Value2> :: value_type () const noexcept
template <class Type, template <Type, Type> class Operator, Type ... Values>
inline constexpr crap :: minValue <Type, Operator, Values...> :: operator
typename crap :: minValue <Type, Operator, Values...> :: value_type () const noexcept
{
return crap :: minValue <Type, Operator, Value1, Value2> :: value;
return crap :: minValue <Type, Operator, Values...> :: value;
}
#if (crap_lib_integral_constant_callable >= 201304L)

template <class Type, template <Type, Type> class Operator, Type ... Values>
inline constexpr crap :: minValue <Type, Operator, Values...> :: operator
typename crap :: minValue <Type, Operator, Values...> :: value_type () const noexcept
inline constexpr typename crap :: minValue <Type, Operator, Values...> :: value_type
crap :: minValue <Type, Operator, Values...> :: operator () () const noexcept
{
return crap :: minValue <Type, Operator, Values...> :: value;
}
#endif
#endif

0 comments on commit 069d95c

Please sign in to comment.