Skip to content

Commit

Permalink
Make max 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 d720ef5 commit 1aa544a
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions include/crap/algorithm.d/maxvalue.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
#ifndef CRAP_ALGORITHM_MAXVALUE
#define CRAP_ALGORITHM_MAXVALUE

#include <type_traits>

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

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

template <class Type, template <Type, Type> class Operator, Type Value>
struct maxValue<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 maxValue<Type, Operator, Value1, Value2>
{
constexpr const static Type value = ((Operator <Value2, Value1> :: value) ? Value1 : Value2);
using value_type = decltype(value);
constexpr operator value_type () const noexcept;
};
: std :: integral_constant<Type, ((Operator <Value2, Value1> :: value) ? Value1 : Value2)> {};

template <class Type, template <Type, Type> class Operator, Type ... Values>
struct maxValue
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 :: maxValue <Type, Operator, Value1> :: operator
typename crap :: maxValue <Type, Operator, Value1> :: value_type () const noexcept
{
return crap :: maxValue <Type, Operator, Value1> :: value;
}

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

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

0 comments on commit 1aa544a

Please sign in to comment.