mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +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
|
#ifndef SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|
||||||
#define SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|
#define SPROUT_TPP_ALGORITHM_MAX_ELEMENT_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/workaround/std/cstddef.hpp>
|
||||||
#include <sprout/type_traits/integral_constant.hpp>
|
#include <sprout/type_traits/integral_constant.hpp>
|
||||||
#include <sprout/type_traits/common_decay.hpp>
|
#include <sprout/type/type_tuple.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace tpp {
|
namespace tpp {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T, T... Values>
|
template<typename T, typename U>
|
||||||
struct max_element_impl;
|
struct max_value
|
||||||
template<typename T, T Value>
|
: public std::conditional<(T::value < U::value), U, T>
|
||||||
struct max_element_impl<T, Value>
|
|
||||||
: public sprout::integral_constant<T, Value>
|
|
||||||
{};
|
{};
|
||||||
template<typename T, T Value1, T Value2>
|
|
||||||
struct max_element_impl<T, Value1, Value2>
|
template<typename Tup, std::size_t First, std::size_t Last, bool = (Last - First == 1)>
|
||||||
: public sprout::integral_constant<T, (Value1 < Value2 ? Value2 : Value1)>
|
struct max_element_impl
|
||||||
|
: public std::tuple_element<First, Tup>::type
|
||||||
{};
|
{};
|
||||||
template<typename T, T Value1, T Value2, T... Tail>
|
template<typename Tup, std::size_t First, std::size_t Last>
|
||||||
struct max_element_impl<T, Value1, Value2, Tail...>
|
struct max_element_impl<Tup, First, Last, false>
|
||||||
: public sprout::tpp::detail::max_element_impl<T, sprout::tpp::detail::max_element_impl<T, Value1, Value2>::value, Tail...>
|
: 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
|
} // 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
|
// max_element
|
||||||
//
|
//
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
struct max_element
|
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 tpp
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
|
@ -8,41 +8,45 @@
|
||||||
#ifndef SPROUT_TPP_ALGORITHM_MIN_ELEMENT_HPP
|
#ifndef SPROUT_TPP_ALGORITHM_MIN_ELEMENT_HPP
|
||||||
#define SPROUT_TPP_ALGORITHM_MIN_ELEMENT_HPP
|
#define SPROUT_TPP_ALGORITHM_MIN_ELEMENT_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/type_traits/common_decay.hpp>
|
#include <sprout/workaround/std/cstddef.hpp>
|
||||||
#include <sprout/type_traits/integral_constant.hpp>
|
#include <sprout/type_traits/integral_constant.hpp>
|
||||||
|
#include <sprout/type/type_tuple.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace tpp {
|
namespace tpp {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T, T... Values>
|
template<typename T, typename U>
|
||||||
struct min_element_impl;
|
struct min_value
|
||||||
template<typename T, T Value>
|
: public std::conditional<(U::value < T::value), U, T>
|
||||||
struct min_element_impl<T, Value>
|
|
||||||
: public sprout::integral_constant<T, Value>
|
|
||||||
{};
|
{};
|
||||||
template<typename T, T Value1, T Value2>
|
|
||||||
struct min_element_impl<T, Value1, Value2>
|
template<typename Tup, std::size_t First, std::size_t Last, bool = (Last - First == 1)>
|
||||||
: public sprout::integral_constant<T, (Value2 < Value1 ? Value2 : Value1)>
|
struct min_element_impl
|
||||||
|
: public std::tuple_element<First, Tup>::type
|
||||||
{};
|
{};
|
||||||
template<typename T, T Value1, T Value2, T... Tail>
|
template<typename Tup, std::size_t First, std::size_t Last>
|
||||||
struct min_element_impl<T, Value1, Value2, Tail...>
|
struct min_element_impl<Tup, First, Last, false>
|
||||||
: public sprout::tpp::detail::min_element_impl<T, sprout::tpp::detail::min_element_impl<T, Value1, Value2>::value, Tail...>
|
: public sprout::tpp::detail::min_value<
|
||||||
|
typename sprout::tpp::detail::min_element_impl<Tup, First, (First + Last) / 2>::type,
|
||||||
|
typename sprout::tpp::detail::min_element_impl<Tup, (First + Last) / 2, Last>::type
|
||||||
|
>::type
|
||||||
{};
|
{};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
//
|
//
|
||||||
// min_element_c
|
|
||||||
//
|
|
||||||
template<typename T, T... Values>
|
|
||||||
struct min_element_c
|
|
||||||
: public sprout::tpp::detail::min_element_impl<T, Values...>
|
|
||||||
{};
|
|
||||||
//
|
|
||||||
// min_element
|
// min_element
|
||||||
//
|
//
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
struct min_element
|
struct min_element
|
||||||
: public sprout::tpp::min_element_c<typename sprout::common_decay<decltype(Types::value)...>::type, Types::value...>
|
: public sprout::tpp::detail::min_element_impl<sprout::types::type_tuple<Types...>, 0, sizeof...(Types)>
|
||||||
|
{};
|
||||||
|
//
|
||||||
|
// min_element_c
|
||||||
|
//
|
||||||
|
template<typename T, T... Values>
|
||||||
|
struct min_element_c
|
||||||
|
: public sprout::tpp::min_element<sprout::integral_constant<T, Values>...>
|
||||||
{};
|
{};
|
||||||
} // namespace tpp
|
} // namespace tpp
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
27
sprout/tuple/default_construct.hpp
Normal file
27
sprout/tuple/default_construct.hpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||||
|
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_TUPLE_DEFAULT_CONSTRUCT_HPP
|
||||||
|
#define SPROUT_TUPLE_DEFAULT_CONSTRUCT_HPP
|
||||||
|
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
namespace tuples {
|
||||||
|
//
|
||||||
|
// default_construct_t
|
||||||
|
// default_construct
|
||||||
|
//
|
||||||
|
struct default_construct_t {};
|
||||||
|
SPROUT_STATIC_CONSTEXPR sprout::tuples::default_construct_t default_construct = {};
|
||||||
|
} // namespace tuples
|
||||||
|
|
||||||
|
using sprout::tuples::default_construct_t;
|
||||||
|
using sprout::tuples::default_construct;
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_TUPLE_DEFAULT_CONSTRUCT_HPP
|
|
@ -22,5 +22,6 @@
|
||||||
#include <sprout/tuple/tuple/type_traits.hpp>
|
#include <sprout/tuple/tuple/type_traits.hpp>
|
||||||
#include <sprout/tuple/tuple/traits.hpp>
|
#include <sprout/tuple/tuple/traits.hpp>
|
||||||
#include <sprout/tuple/flexibly_construct.hpp>
|
#include <sprout/tuple/flexibly_construct.hpp>
|
||||||
|
#include <sprout/tuple/default_construct.hpp>
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_TUPLE_TUPLE_HPP
|
#endif // #ifndef SPROUT_TUPLE_TUPLE_HPP
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include <sprout/functional/ref.hpp>
|
#include <sprout/functional/ref.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple.hpp>
|
#include <sprout/tuple/tuple/tuple.hpp>
|
||||||
#include <sprout/tuple/tuple/get.hpp>
|
#include <sprout/tuple/tuple/get.hpp>
|
||||||
//#include <sprout/tuple/indexes.hpp>
|
|
||||||
#include <sprout/type/operation/tuple_cat.hpp>
|
#include <sprout/type/operation/tuple_cat.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
|
@ -81,76 +80,8 @@ namespace sprout {
|
||||||
typedef sprout::tuples::detail::tuple_cat_indexes<Tuples...> indexes;
|
typedef sprout::tuples::detail::tuple_cat_indexes<Tuples...> indexes;
|
||||||
return sprout::tuples::detail::tuple_cat_impl<type>(indexes::for_pack::make(), indexes::for_element::make(), SPROUT_FORWARD(Tuples, tuples)...);
|
return sprout::tuples::detail::tuple_cat_impl<type>(indexes::for_pack::make(), indexes::for_element::make(), SPROUT_FORWARD(Tuples, tuples)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// namespace results {
|
|
||||||
// //
|
|
||||||
// // tuple_cat
|
|
||||||
// //
|
|
||||||
// template<typename... Tuples>
|
|
||||||
// struct tuple_cat
|
|
||||||
// : public sprout::types::tuple_cat<typename std::decay<Tuples>::type...>
|
|
||||||
// {};
|
|
||||||
// } // namespace results
|
|
||||||
//
|
|
||||||
// namespace detail {
|
|
||||||
// template<typename... Tuples>
|
|
||||||
// struct tuple_cat_1st_indexes;
|
|
||||||
// template<>
|
|
||||||
// struct tuple_cat_1st_indexes<> {
|
|
||||||
// public:
|
|
||||||
// typedef sprout::index_tuple<> type;
|
|
||||||
// };
|
|
||||||
// template<typename Head, typename... Tail>
|
|
||||||
// struct tuple_cat_1st_indexes<Head, Tail...>
|
|
||||||
// : public sprout::tuple_indexes<typename std::remove_reference<Head>::type>
|
|
||||||
// {};
|
|
||||||
//
|
|
||||||
// template<typename Result, typename IndexTuple, typename... Tuples>
|
|
||||||
// struct tuple_cat_impl;
|
|
||||||
// template<typename Result>
|
|
||||||
// struct tuple_cat_impl<Result, sprout::index_tuple<> > {
|
|
||||||
// public:
|
|
||||||
// template<typename... Args>
|
|
||||||
// static SPROUT_CONSTEXPR Result
|
|
||||||
// call(Args&&... args) {
|
|
||||||
// return Result(SPROUT_FORWARD(Args, args)...);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// template<typename Result, sprout::index_t... Indexes, typename Head, typename... Tail>
|
|
||||||
// struct tuple_cat_impl<Result, sprout::index_tuple<Indexes...>, Head, Tail...> {
|
|
||||||
// public:
|
|
||||||
// template<typename T, typename... Args>
|
|
||||||
// static SPROUT_CONSTEXPR Result
|
|
||||||
// call(T&& t, Args&&... args) {
|
|
||||||
// return sprout::tuples::detail::tuple_cat_impl<
|
|
||||||
// Result,
|
|
||||||
// typename sprout::tuples::detail::tuple_cat_1st_indexes<Tail...>::type,
|
|
||||||
// Tail...
|
|
||||||
// >::call(
|
|
||||||
// SPROUT_FORWARD(Args, args)...,
|
|
||||||
// sprout::tuples::get<Indexes>(SPROUT_FORWARD(T, t))...
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// } // namespace detail
|
|
||||||
// //
|
|
||||||
// // tuple_cat
|
|
||||||
// //
|
|
||||||
// template<typename... Tuples>
|
|
||||||
// inline SPROUT_CONSTEXPR typename sprout::tuples::results::tuple_cat<Tuples...>::type
|
|
||||||
// tuple_cat(Tuples&&... tuples) {
|
|
||||||
// return sprout::tuples::detail::tuple_cat_impl<
|
|
||||||
// typename sprout::tuples::results::tuple_cat<Tuples...>::type,
|
|
||||||
// typename sprout::tuples::detail::tuple_cat_1st_indexes<Tuples...>::type,
|
|
||||||
// Tuples...
|
|
||||||
// >::call(SPROUT_FORWARD(Tuples, tuples)...);
|
|
||||||
// }
|
|
||||||
} // namespace tuples
|
} // namespace tuples
|
||||||
|
|
||||||
// namespace results {
|
|
||||||
// using sprout::tuples::results::tuple_cat;
|
|
||||||
// } // namespace results
|
|
||||||
|
|
||||||
using sprout::tuples::make_tuple;
|
using sprout::tuples::make_tuple;
|
||||||
using sprout::tuples::forward_as_tuple;
|
using sprout::tuples::forward_as_tuple;
|
||||||
using sprout::tuples::tie;
|
using sprout::tuples::tie;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <sprout/tpp/algorithm/all_of.hpp>
|
#include <sprout/tpp/algorithm/all_of.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
||||||
#include <sprout/tuple/flexibly_construct.hpp>
|
#include <sprout/tuple/flexibly_construct.hpp>
|
||||||
|
#include <sprout/tuple/default_construct.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace tuples {
|
namespace tuples {
|
||||||
|
@ -35,8 +36,6 @@ namespace sprout {
|
||||||
class tuple_access;
|
class tuple_access;
|
||||||
|
|
||||||
struct from_tuple_construct_t {};
|
struct from_tuple_construct_t {};
|
||||||
struct few_construct_t {};
|
|
||||||
struct excess_construct_t {};
|
|
||||||
|
|
||||||
template<sprout::index_t I, typename IdentityType>
|
template<sprout::index_t I, typename IdentityType>
|
||||||
struct element_holder {
|
struct element_holder {
|
||||||
|
@ -54,6 +53,9 @@ namespace sprout {
|
||||||
explicit SPROUT_CONSTEXPR element_holder(T&& value)
|
explicit SPROUT_CONSTEXPR element_holder(T&& value)
|
||||||
: value_(SPROUT_FORWARD(T, value))
|
: value_(SPROUT_FORWARD(T, value))
|
||||||
{}
|
{}
|
||||||
|
explicit SPROUT_CONSTEXPR element_holder(sprout::tuples::default_construct_t)
|
||||||
|
: value_()
|
||||||
|
{}
|
||||||
protected:
|
protected:
|
||||||
static SPROUT_CONSTEXPR value_type&
|
static SPROUT_CONSTEXPR value_type&
|
||||||
get(element_holder& t) {
|
get(element_holder& t) {
|
||||||
|
|
Loading…
Reference in a new issue