mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-12 14:54:10 +00:00
add default_construct
This commit is contained in:
parent
3b0ab6f5fd
commit
2979248623
6 changed files with 80 additions and 111 deletions
|
@ -8,41 +8,45 @@
|
|||
#ifndef SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|
||||
#define SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/common_decay.hpp>
|
||||
#include <sprout/type/type_tuple.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tpp {
|
||||
namespace detail {
|
||||
template<typename T, T... Values>
|
||||
struct max_element_impl;
|
||||
template<typename T, T Value>
|
||||
struct max_element_impl<T, Value>
|
||||
: public sprout::integral_constant<T, Value>
|
||||
template<typename T, typename U>
|
||||
struct max_value
|
||||
: public std::conditional<(T::value < U::value), U, T>
|
||||
{};
|
||||
template<typename T, T Value1, T Value2>
|
||||
struct max_element_impl<T, Value1, Value2>
|
||||
: public sprout::integral_constant<T, (Value1 < Value2 ? Value2 : Value1)>
|
||||
|
||||
template<typename Tup, std::size_t First, std::size_t Last, bool = (Last - First == 1)>
|
||||
struct max_element_impl
|
||||
: public std::tuple_element<First, Tup>::type
|
||||
{};
|
||||
template<typename T, T Value1, T Value2, T... Tail>
|
||||
struct max_element_impl<T, Value1, Value2, Tail...>
|
||||
: public sprout::tpp::detail::max_element_impl<T, sprout::tpp::detail::max_element_impl<T, Value1, Value2>::value, Tail...>
|
||||
template<typename Tup, std::size_t First, std::size_t Last>
|
||||
struct max_element_impl<Tup, First, Last, false>
|
||||
: public sprout::tpp::detail::max_value<
|
||||
typename sprout::tpp::detail::max_element_impl<Tup, First, (First + Last) / 2>::type,
|
||||
typename sprout::tpp::detail::max_element_impl<Tup, (First + Last) / 2, Last>::type
|
||||
>::type
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// max_element_c
|
||||
//
|
||||
template<typename T, T... Values>
|
||||
struct max_element_c
|
||||
: public sprout::tpp::detail::max_element_impl<T, Values...>
|
||||
{};
|
||||
//
|
||||
// max_element
|
||||
//
|
||||
template<typename... Types>
|
||||
struct max_element
|
||||
: public sprout::tpp::max_element_c<typename sprout::common_decay<decltype(Types::value)...>::type, Types::value...>
|
||||
: public sprout::tpp::detail::max_element_impl<sprout::types::type_tuple<Types...>, 0, sizeof...(Types)>
|
||||
{};
|
||||
//
|
||||
// max_element_c
|
||||
//
|
||||
template<typename T, T... Values>
|
||||
struct max_element_c
|
||||
: public sprout::tpp::max_element<sprout::integral_constant<T, Values>...>
|
||||
{};
|
||||
} // namespace tpp
|
||||
} // namespace sprout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue