2013-11-20 13:04:11 +00:00
|
|
|
/*=============================================================================
|
2017-07-29 05:20:01 +00:00
|
|
|
Copyright (c) 2011-2017 Bolero MURAKAMI
|
2013-11-20 13:04:11 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
|
|
|
#ifndef SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|
|
|
|
#define SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|
|
|
|
|
2014-09-22 01:40:52 +00:00
|
|
|
#include <type_traits>
|
2013-11-20 13:04:11 +00:00
|
|
|
#include <sprout/config.hpp>
|
2014-09-22 01:40:52 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2013-11-20 13:04:11 +00:00
|
|
|
#include <sprout/type_traits/integral_constant.hpp>
|
2014-09-22 01:40:52 +00:00
|
|
|
#include <sprout/type/type_tuple.hpp>
|
2013-11-20 13:04:11 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace tpp {
|
|
|
|
namespace detail {
|
2014-09-22 01:40:52 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct max_value
|
|
|
|
: public std::conditional<(T::value < U::value), U, T>
|
2013-11-20 13:04:11 +00:00
|
|
|
{};
|
2014-09-22 01:40:52 +00:00
|
|
|
|
|
|
|
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
|
2013-11-20 13:04:11 +00:00
|
|
|
{};
|
2014-09-22 01:40:52 +00:00
|
|
|
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
|
2013-11-20 13:04:11 +00:00
|
|
|
{};
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// max_element
|
|
|
|
//
|
|
|
|
template<typename... Types>
|
|
|
|
struct max_element
|
2014-09-22 01:40:52 +00:00
|
|
|
: 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>...>
|
2013-11-20 13:04:11 +00:00
|
|
|
{};
|
|
|
|
} // namespace tpp
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|