1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

fix tuple_element: support SFINAE-friendly

This commit is contained in:
bolero-MURAKAMI 2014-05-29 00:25:37 +09:00
parent f42e92b448
commit c15de6136b
64 changed files with 984 additions and 113 deletions

View file

@ -8,6 +8,7 @@
#ifndef SPROUT_ARRAY_TUPLE_HPP
#define SPROUT_ARRAY_TUPLE_HPP
#include <type_traits>
#include <tuple>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
@ -15,6 +16,8 @@
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
//
@ -56,11 +59,9 @@ namespace std {
// tuple_element
//
template<std::size_t I, typename T, std::size_t N>
struct tuple_element<I, sprout::array<T, N> > {
static_assert(I < N, "tuple_element<>: index out of range");
public:
typedef T type;
};
struct tuple_element<I, sprout::array<T, N> >
: public std::conditional<(I < N), sprout::identity<T>, sprout::detail::nil_base>::type
{};
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View file

@ -21,7 +21,7 @@ namespace sprout {
Integral
>::type
flipbitsge(Integral x, int b) SPROUT_NOEXCEPT {
return x ^ ~((Integral(1) << b)-1);
return x ^ ~((Integral(1) << b) - 1);
}
} // namespace sprout

View file

@ -21,7 +21,7 @@ namespace sprout {
Integral
>::type
flipbitsle(Integral x, int b) SPROUT_NOEXCEPT {
return x ^ ((Integral(1) << (b+1))-1);
return x ^ ((Integral(1) << (b + 1)) - 1);
}
} // namespace sprout

View file

@ -21,7 +21,7 @@ namespace sprout {
Integral
>::type
rstbitsge(Integral x, int b) SPROUT_NOEXCEPT {
return x & ((Integral(1) << b)-1);
return x & ((Integral(1) << b) - 1);
}
} // namespace sprout

View file

@ -21,7 +21,7 @@ namespace sprout {
Integral
>::type
rstbitsle(Integral x, int b) SPROUT_NOEXCEPT {
return x & ~((Integral(1) << (b+1))-1);
return x & ~((Integral(1) << (b + 1)) - 1);
}
} // namespace sprout

View file

@ -21,7 +21,7 @@ namespace sprout {
Integral
>::type
setbitsge(Integral x, int b) SPROUT_NOEXCEPT {
return x | ~((Integral(1) << b)-1);
return x | ~((Integral(1) << b) - 1);
}
} // namespace sprout

View file

@ -21,7 +21,7 @@ namespace sprout {
Integral
>::type
setbitsle(Integral x, int b) SPROUT_NOEXCEPT {
return x | ((Integral(1) << (b+1))-1);
return x | ((Integral(1) << (b + 1)) - 1);
}
} // namespace sprout

View file

@ -0,0 +1,19 @@
/*=============================================================================
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_DETAIL_NIL_BASE_HPP
#define SPROUT_DETAIL_NIL_BASE_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace detail {
struct nil_base {};
} // namespace detail
} // namespace sprout
#endif // #ifndef SPROUT_DETAIL_NIL_BASE_HPP

View file

@ -25,12 +25,18 @@ namespace sprout {
public:
typedef T type;
public:
static SPROUT_CONSTEXPR std::size_t size() {
static SPROUT_CONSTEXPR std::size_t
size() {
return sizeof(type);
}
static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t) {
static SPROUT_CONSTEXPR unsigned char
get_byte(type const& t, std::size_t) {
return static_cast<unsigned char>(t);
}
static SPROUT_CXX14_CONSTEXPR void
set_byte(type& t, std::size_t, unsigned char value) {
t = static_cast<type>(value);
}
};
template<typename T>
class default_big_endian_traits<
@ -40,15 +46,22 @@ namespace sprout {
public:
typedef T type;
public:
static SPROUT_CONSTEXPR std::size_t size() {
static SPROUT_CONSTEXPR std::size_t
size() {
return sizeof(type);
}
static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t i) {
static SPROUT_CONSTEXPR unsigned char
get_byte(type const& t, std::size_t i) {
return static_cast<unsigned char>(
(t & (UCHAR_MAX << CHAR_BIT * ((size() - 1) - i)))
>> CHAR_BIT * ((size() - 1) - i)
);
}
static SPROUT_CXX14_CONSTEXPR void
set_byte(type& t, std::size_t i, unsigned char value) {
t &= ~(UCHAR_MAX << CHAR_BIT * ((size() - 1) - i));
t |= (value << CHAR_BIT * ((size() - 1) - i));
}
};
template<typename T, typename Enable = void>
@ -67,6 +80,10 @@ namespace sprout {
static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t) {
return static_cast<unsigned char>(t);
}
static SPROUT_CXX14_CONSTEXPR void
set_byte(type& t, std::size_t, unsigned char value) {
t = static_cast<type>(value);
}
};
template<typename T>
class default_little_endian_traits<
@ -85,6 +102,11 @@ namespace sprout {
>> CHAR_BIT * i
);
}
static SPROUT_CXX14_CONSTEXPR void
set_byte(type& t, std::size_t i, unsigned char value) {
t &= ~(UCHAR_MAX << CHAR_BIT * i);
t |= (value << CHAR_BIT * i);
}
};
} // namespace detail

View file

@ -32,11 +32,9 @@ namespace std {
// tuple_element
//
template<std::size_t I, typename T, T... Is>
struct tuple_element<I, sprout::integer_sequence<T, Is...> > {
static_assert(I < sizeof...(Is), "tuple_element<>: index out of range");
public:
typedef typename sprout::pack_element_c<I, T, Is...>::type type;
};
struct tuple_element<I, sprout::integer_sequence<T, Is...> >
: public sprout::pack_element_c<I, T, Is...>
{};
#if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES))
//

View file

@ -14,6 +14,7 @@
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout {
@ -59,7 +60,7 @@ namespace std {
//
template<std::size_t I, typename Container>
struct tuple_element<I, sprout::pit<Container> >
: public std::tuple_element<I, Container>
: public sprout::tuples::tuple_element<I, Container>
{};
#if defined(__clang__)
# pragma clang diagnostic pop

View file

@ -21,6 +21,8 @@
#include <sprout/utility/swap.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace random {
@ -65,14 +67,12 @@ namespace sprout {
generator_type generator_;
public:
SPROUT_CONSTEXPR random_result()
: result_()
, generator_()
: result_(), generator_()
{}
random_result(random_result const&) = default;
SPROUT_CONSTEXPR random_result(
result_type result,
engine_type const& engine,
distribution_type const& distribution
engine_type const& engine, distribution_type const& distribution
)
: result_(result)
, generator_(engine, distribution)
@ -199,16 +199,11 @@ namespace sprout {
generator_type generator_;
public:
SPROUT_CONSTEXPR random_result()
: result_()
, generator_()
: result_(), generator_()
{}
random_result(random_result const&) = default;
SPROUT_CONSTEXPR random_result(
result_type result,
engine_type const& engine
)
: result_(result)
, generator_(engine)
SPROUT_CONSTEXPR random_result(result_type result, engine_type const& engine)
: result_(result), generator_(engine)
{}
SPROUT_CONSTEXPR random_result operator()() const {
return generator_();
@ -316,16 +311,18 @@ namespace sprout {
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
template<std::size_t I, typename Engine, typename Distribution>
struct tuple_element_impl<I, sprout::random::random_result<Engine, Distribution> >
: public sprout::detail::nil_base
{};
template<typename Engine, typename Distribution>
struct tuple_element_impl<0, sprout::random::random_result<Engine, Distribution> > {
public:
typedef typename sprout::random::random_result<Engine, Distribution>::result_type type;
};
struct tuple_element_impl<0, sprout::random::random_result<Engine, Distribution> >
: public sprout::identity<typename sprout::random::random_result<Engine, Distribution>::result_type>
{};
template<typename Engine, typename Distribution>
struct tuple_element_impl<1, sprout::random::random_result<Engine, Distribution> > {
public:
typedef typename sprout::random::random_result<Engine, Distribution>::generator_type type;
};
struct tuple_element_impl<1, sprout::random::random_result<Engine, Distribution> >
: public sprout::identity<typename sprout::random::random_result<Engine, Distribution>::generator_type>
{};
template<std::size_t I, typename T>
struct get_impl;

View file

@ -15,6 +15,8 @@
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
//
@ -56,11 +58,9 @@ namespace std {
// tuple_element
//
template<std::size_t I, typename T, std::size_t N, typename Traits>
struct tuple_element<I, sprout::basic_string<T, N, Traits> > {
static_assert(I < N, "tuple_element<>: index out of range");
public:
typedef T type;
};
struct tuple_element<I, sprout::basic_string<T, N, Traits> >
: public std::conditional<(I < N), sprout::identity<T>, sprout::detail::nil_base>::type
{};
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View file

@ -17,6 +17,7 @@
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout {
@ -66,7 +67,7 @@ namespace std {
//
template<std::size_t I, typename Container>
struct tuple_element<I, sprout::sub_array<Container> >
: public std::tuple_element<I, typename std::remove_reference<Container>::type>
: public sprout::tuples::tuple_element<I, typename std::remove_reference<Container>::type>
{};
#if defined(__clang__)
# pragma clang diagnostic pop

View file

@ -14,6 +14,8 @@
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace tuples {
@ -28,16 +30,18 @@ namespace sprout {
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
template<std::size_t I, typename T1, typename T2>
struct tuple_element_impl<I, sscrisk::cel::pair<T1, T2> >
: public sprout::detail::nil_base
{};
template<typename T1, typename T2>
struct tuple_element_impl<0, sscrisk::cel::pair<T1, T2> > {
public:
typedef T1 type;
};
struct tuple_element_impl<0, sscrisk::cel::pair<T1, T2> >
: public sprout::identity<T1>
{};
template<typename T1, typename T2>
struct tuple_element_impl<1, sscrisk::cel::pair<T1, T2> > {
public:
typedef T2 type;
};
struct tuple_element_impl<1, sscrisk::cel::pair<T1, T2> >
: public sprout::identity<T2>
{};
} // namespace detail
//
// tuple_element

View file

@ -12,33 +12,61 @@
#include <tuple>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace tuples {
//
// tuple_element
//
namespace detail {
template<std::size_t I, typename T, bool = (I < std::tuple_size<T>::value)>
struct tuple_element_default;
template<std::size_t I, typename T>
struct tuple_element_default<I, T, false>
: public sprout::detail::nil_base
{};
template<std::size_t I, typename T>
struct tuple_element_default<I, T, true>
: public std::tuple_element<I, T>
{};
} // namespace detail
template<std::size_t I, typename T>
struct tuple_element
: public std::tuple_element<I, T>
: public sprout::tuples::detail::tuple_element_default<I, T>
{};
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_default<I, T const, true>
: public std::add_const<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
template<std::size_t I, typename T>
struct tuple_element_default<I, T volatile, true>
: public std::add_volatile<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
template<std::size_t I, typename T>
struct tuple_element_default<I, T const volatile, true>
: public std::add_cv<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
} // namespace detail
template<std::size_t I, typename T>
struct tuple_element<I, T const>
: public std::add_const<
typename sprout::tuples::tuple_element<I, T>::type
>
: public sprout::tuples::detail::tuple_element_default<I, T const>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T volatile>
: public std::add_volatile<
typename sprout::tuples::tuple_element<I, T>::type
>
: public sprout::tuples::detail::tuple_element_default<I, T volatile>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T const volatile>
: public std::add_cv<
typename sprout::tuples::tuple_element<I, T>::type
>
: public sprout::tuples::detail::tuple_element_default<I, T const volatile>
{};
} // namespace tuples

View file

@ -13,5 +13,10 @@
#include <sprout/type/algorithm/find_index_if.hpp>
#include <sprout/type/algorithm/lower_bound_index.hpp>
#include <sprout/type/algorithm/upper_bound_index.hpp>
#include <sprout/type/algorithm/fold.hpp>
#include <sprout/type/algorithm/transform.hpp>
#include <sprout/type/algorithm/contains.hpp>
#include <sprout/type/algorithm/accumulate.hpp>
#include <sprout/type/algorithm/partial_sum.hpp>
#endif // #ifndef SPROUT_TYPE_ALGORITHM_HPP

View file

@ -0,0 +1,32 @@
/*=============================================================================
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_TYPE_ALGORITHM_ACCUMLATE_HPP
#define SPROUT_TYPE_ALGORITHM_ACCUMLATE_HPP
#include <sprout/config.hpp>
#include <sprout/type/algorithm/fold.hpp>
#include <sprout/type/functional/plus.hpp>
namespace sprout {
namespace types {
//
// accumulate
//
template<typename Tuple, typename T, typename BinaryOp = sprout::types::plus_>
struct accumulate
: public sprout::types::fold<Tuple, T, BinaryOp>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename T, typename BinaryOp = sprout::types::plus_>
using accumulate_t = typename sprout::types::accumulate<Tuple, T, BinaryOp>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_ALGORITHM_ACCUMLATE_HPP

View file

@ -0,0 +1,41 @@
/*=============================================================================
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_TYPE_ALGORITHM_CONTAINTS_HPP
#define SPROUT_TYPE_ALGORITHM_CONTAINTS_HPP
#include <sprout/config.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type/algorithm/find_index.hpp>
#include <sprout/type_traits/integral_constant.hpp>
namespace sprout {
namespace types {
//
// contains
//
template<typename Tuple, typename T>
struct contains
: public sprout::integral_constant<
bool,
sprout::types::find_index<Tuple, T>::value != sprout::types::tuple_size<Tuple>::value
>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename T>
using contains_t = typename sprout::types::contains<Tuple, T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple, typename T>
SPROUT_STATIC_CONSTEXPR bool contains_v = sprout::types::contains<Tuple, T>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_ALGORITHM_CONTAINTS_HPP

View file

@ -47,6 +47,16 @@ namespace sprout {
struct find_index
: public sprout::types::detail::find_index_impl<Tuple, T, 0>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename T>
using find_index_t = typename sprout::types::find_index<Tuple, T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple, typename T>
SPROUT_STATIC_CONSTEXPR std::size_t find_index_v = sprout::types::find_index<Tuple, T>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout

View file

@ -47,6 +47,16 @@ namespace sprout {
struct find_index_if
: public sprout::types::detail::find_index_if_impl<Tuple, Predicate, 0>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename Predicate>
using find_index_if_t = typename sprout::types::find_index_if<Tuple, Predicate>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple, typename Predicate>
SPROUT_STATIC_CONSTEXPR std::size_t find_index_if_v = sprout::types::find_index_if<Tuple, Predicate>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout

View file

@ -0,0 +1,53 @@
/*=============================================================================
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_TYPE_ALGORITHM_FOLD_HPP
#define SPROUT_TYPE_ALGORITHM_FOLD_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout {
namespace types {
namespace detail {
template<
typename Tuple, typename T, typename BinaryOp, std::size_t I,
bool = (I == sprout::types::tuple_size<Tuple>::value)
>
struct fold_impl;
template<typename Tuple, typename T, typename BinaryOp, std::size_t I>
struct fold_impl<Tuple, T, BinaryOp, I, true>
: public sprout::identity<T>
{};
template<typename Tuple, typename T, typename BinaryOp, std::size_t I>
struct fold_impl<Tuple, T, BinaryOp, I, false>
: public sprout::types::detail::fold_impl<
Tuple,
typename BinaryOp::template apply<T, typename sprout::types::tuple_element<I, Tuple>::type>::type,
BinaryOp,
I + 1
>
{};
} // namespace detail
//
// fold
//
template<typename Tuple, typename T, typename BinaryOp>
struct fold
: public sprout::types::detail::fold_impl<Tuple, T, BinaryOp, 0>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename T, typename BinaryOp>
using fold_t = typename sprout::types::fold<Tuple, T, BinaryOp>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_ALGORITHM_FOLD_HPP

View file

@ -63,6 +63,16 @@ namespace sprout {
struct lower_bound_index
: public sprout::types::detail::lower_bound_index_impl<Tuple, T, Compare, 0, sprout::types::tuple_size<Tuple>::value>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename T, typename Compare = sprout::types::less_>
using lower_bound_index_t = typename sprout::types::lower_bound_index<Tuple, T, Compare>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple, typename T, typename Compare = sprout::types::less_>
SPROUT_STATIC_CONSTEXPR std::size_t lower_bound_index_v = sprout::types::lower_bound_index<Tuple, T, Compare>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout

View file

@ -0,0 +1,65 @@
/*=============================================================================
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_TYPE_ALGORITHM_PARTIAL_SUM_HPP
#define SPROUT_TYPE_ALGORITHM_PARTIAL_SUM_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type/rebind_types.hpp>
#include <sprout/type/functional/plus.hpp>
namespace sprout {
namespace types {
namespace detail {
template<
typename Tuple, typename BinaryOp, std::size_t I, std::size_t N, typename T, typename... Types
>
struct partial_sum_impl
: public sprout::types::detail::partial_sum_impl<
Tuple, BinaryOp, I + 1, N - 1,
typename BinaryOp::template apply<T, typename sprout::types::tuple_element<I, Tuple>::type>::type,
Types..., T
>
{};
template<typename Tuple, typename BinaryOp, std::size_t I, typename T, typename... Types>
struct partial_sum_impl<Tuple, BinaryOp, I, 0, T, Types...>
: public sprout::types::rebind_types<
Tuple
>::template apply<
Types..., T
>
{};
template<typename Tuple, typename BinaryOp, std::size_t N>
struct partial_sum
: public sprout::types::detail::partial_sum_impl<Tuple, BinaryOp, 1, N - 1, typename sprout::types::tuple_element<0, Tuple>::type>
{};
template<typename Tuple, typename BinaryOp>
struct partial_sum<Tuple, BinaryOp, 0>
: public sprout::types::rebind_types<
Tuple
>::template apply<>
{};
} // namespace detail
//
// partial_sum
//
template<typename Tuple, typename BinaryOp = sprout::types::plus_>
struct partial_sum
: public sprout::types::detail::partial_sum<Tuple, BinaryOp, sprout::types::tuple_size<Tuple>::value>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename BinaryOp = sprout::types::plus_>
using partial_sum_t = typename sprout::types::partial_sum<Tuple, BinaryOp>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_ALGORITHM_PARTIAL_SUM_HPP

View file

@ -0,0 +1,72 @@
/*=============================================================================
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_TYPE_ALGORITHM_TRANSFORM_HPP
#define SPROUT_TYPE_ALGORITHM_TRANSFORM_HPP
#include <sprout/config.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#include <sprout/tuple/indexes.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type/rebind_types.hpp>
namespace sprout {
namespace types {
namespace detail {
template<typename Tuple, typename UnaryOp, typename IndexTuple>
struct transform_impl;
template<typename Tuple, typename UnaryOp, sprout::index_t... Indexes>
struct transform_impl<Tuple, UnaryOp, sprout::index_tuple<Indexes...> >
: public sprout::types::rebind_types<
Tuple
>::template apply<
typename UnaryOp::template apply<
typename sprout::types::tuple_element<Indexes, Tuple>::type
>::type...
>
{};
template<typename Tuple1, typename Tuple2, typename BinaryOp, typename IndexTuple>
struct transform2_impl;
template<typename Tuple1, typename Tuple2, typename BinaryOp, sprout::index_t... Indexes>
struct transform2_impl<Tuple1, Tuple2, BinaryOp, sprout::index_tuple<Indexes...> >
: public sprout::types::rebind_types<
Tuple1
>::template apply<
typename BinaryOp::template apply<
typename sprout::types::tuple_element<Indexes, Tuple1>::type,
typename sprout::types::tuple_element<Indexes, Tuple2>::type
>::type...
>
{};
} // namespace detail
//
// transform
//
template<typename Tuple, typename Tuple2OrUnaryOp, typename BinaryOp = void>
struct transform
: public sprout::types::detail::transform2_impl<
Tuple, Tuple2OrUnaryOp, BinaryOp,
typename sprout::tuple_indexes<Tuple>::type
>
{};
template<typename Tuple, typename UnaryOp>
struct transform<Tuple, UnaryOp, void>
: public sprout::types::detail::transform_impl<
Tuple, UnaryOp,
typename sprout::tuple_indexes<Tuple>::type
>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename Tuple2OrUnaryOp, typename BinaryOp = void>
using transform_t = typename sprout::types::transform<Tuple, Tuple2OrUnaryOp, BinaryOp>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_ALGORITHM_TRANSFORM_HPP

View file

@ -63,6 +63,16 @@ namespace sprout {
struct upper_bound_index
: public sprout::types::detail::upper_bound_index_impl<Tuple, T, Compare, 0, sprout::types::tuple_size<Tuple>::value>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename T, typename Compare = sprout::types::less_>
using upper_bound_index_t = typename sprout::types::upper_bound_index<Tuple, T, Compare>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple, typename T, typename Compare = sprout::types::less_>
SPROUT_STATIC_CONSTEXPR std::size_t upper_bound_index_v = sprout::types::upper_bound_index<Tuple, T, Compare>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout

View file

@ -0,0 +1,34 @@
/*=============================================================================
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_TYPE_BOOST_MPL_DETAIL_TUPLE_ELEMENT_HPP
#define SPROUT_TYPE_BOOST_MPL_DETAIL_TUPLE_ELEMENT_HPP
#include <boost/mpl/size.hpp>
#include <boost/mpl/at.hpp>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace types {
namespace detail {
template<std::size_t I, typename T, bool = (I < boost::mpl::size<T>::value)>
struct mpl_tuple_element;
template<std::size_t I, typename T>
struct mpl_tuple_element<I, T, false>
: public sprout::detail::nil_base
{};
template<std::size_t I, typename T>
struct mpl_tuple_element<I, T, true>
: public boost::mpl::at_c<T, I>
{};
} // namespace detail
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_BOOST_MPL_DETAIL_TUPLE_ELEMENT_HPP

View file

@ -8,18 +8,20 @@
#ifndef SPROUT_TYPE_BOOST_MPL_STRING_HPP
#define SPROUT_TYPE_BOOST_MPL_STRING_HPP
#include <sprout/config.hpp>
#include <boost/mpl/string.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/next_prior.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/push_front.hpp>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type/iterator/next.hpp>
#include <sprout/type/iterator/prev.hpp>
#include <sprout/type/operation/push_back.hpp>
#include <sprout/type/operation/push_front.hpp>
#include <sprout/type/boost/mpl/detail/tuple_element.hpp>
namespace sprout {
namespace types {
@ -50,7 +52,7 @@ namespace sprout {
//
template<std::size_t I, int... Values>
struct tuple_element<I, boost::mpl::string<Values...> >
: public boost::mpl::at_c<boost::mpl::string<Values...>, I>
: public sprout::types::detail::mpl_tuple_element<I, boost::mpl::string<Values...> >
{};
//

View file

@ -8,10 +8,11 @@
#ifndef SPROUT_TYPE_BOOST_MPL_V_ITER_HPP
#define SPROUT_TYPE_BOOST_MPL_V_ITER_HPP
#include <sprout/config.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/next_prior.hpp>
#include <boost/mpl/advance.hpp>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/iterator/next.hpp>
#include <sprout/type/iterator/prev.hpp>
#include <sprout/type/iterator/advance.hpp>

View file

@ -8,12 +8,14 @@
#ifndef SPROUT_TYPE_BOOST_MPL_VECTOR_HPP
#define SPROUT_TYPE_BOOST_MPL_VECTOR_HPP
#include <sprout/config.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/at.hpp>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type/boost/mpl/v_iter.hpp>
#include <sprout/type/boost/mpl/detail/tuple_element.hpp>
namespace sprout {
namespace types {
@ -44,7 +46,7 @@ namespace sprout {
//
template<std::size_t I, typename... Types>
struct tuple_element<I, boost::mpl::vector<Types...> >
: public boost::mpl::at_c<boost::mpl::vector<Types...>, I>
: public sprout::types::detail::mpl_tuple_element<I, boost::mpl::vector<Types...> >
{};
} // namespace types
} // namespace sprout

View file

@ -8,12 +8,14 @@
#ifndef SPROUT_TYPE_BOOST_MPL_VECTOR_C_HPP
#define SPROUT_TYPE_BOOST_MPL_VECTOR_C_HPP
#include <sprout/config.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/at.hpp>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type/boost/mpl/v_iter.hpp>
#include <sprout/type/boost/mpl/detail/tuple_element.hpp>
namespace sprout {
namespace types {
@ -44,7 +46,7 @@ namespace sprout {
//
template<std::size_t I, typename T, T... Values>
struct tuple_element<I, boost::mpl::vector_c<T, Values...> >
: public boost::mpl::at_c<boost::mpl::vector_c<T, Values...>, I>
: public sprout::types::detail::mpl_tuple_element<I, boost::mpl::vector_c<T, Values...> >
{};
} // namespace types
} // namespace sprout

View file

@ -10,5 +10,6 @@
#include <sprout/config.hpp>
#include <sprout/type/functional/less.hpp>
#include <sprout/type/functional/plus.hpp>
#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_HPP

View file

@ -31,6 +31,11 @@ namespace sprout {
: public sprout::types::less<T, U>
{};
};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T, typename U>
SPROUT_STATIC_CONSTEXPR bool less_v = sprout::types::less<T, U>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout

View file

@ -0,0 +1,56 @@
/*=============================================================================
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_TYPE_FUNCTIONAL_PLUS_HPP
#define SPROUT_TYPE_FUNCTIONAL_PLUS_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/common_decay.hpp>
namespace sprout {
namespace types {
//
// plus
//
template<typename T, typename U, typename Result = void>
struct plus
: public sprout::integral_constant<Result, (T::value + U::value)>
{};
template<typename T, typename U>
struct plus<T, U, void>
: public sprout::integral_constant<
typename sprout::common_decay<typename T::value_type, typename U::value_type>::type,
(T::value + U::value)
>
{};
//
// plus_mf
//
template<typename Result = void>
struct plus_mf {
public:
template<typename T, typename U>
struct apply
: public sprout::types::plus<T, U, Result>
{};
};
//
// plus_
//
typedef sprout::types::plus_mf<> plus_;
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T, typename U, typename Result = void>
SPROUT_STATIC_CONSTEXPR typename sprout::types::plus<T, U, Result>::value_type plus_v = sprout::types::plus<T, U, Result>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_PLUS_HPP

View file

@ -50,7 +50,7 @@ namespace std {
//
template<std::size_t I, typename T, T... Values>
struct tuple_element<I, sprout::types::integral_array<T, Values...> >
: public std::tuple_element<I, sprout::types::type_tuple<sprout::integral_constant<T, Values>...> >
: public sprout::types::tuple_element<I, sprout::types::type_tuple<sprout::integral_constant<T, Values>...> >
{};
#if defined(__clang__)
# pragma clang diagnostic pop

View file

@ -9,6 +9,7 @@
#define SPROUT_TYPE_ITERATOR_ADVANCE_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
namespace sprout {
namespace types {
@ -32,6 +33,11 @@ namespace sprout {
struct advance<Iterator const volatile, Disatnce>
: public sprout::types::advance<Iterator, Disatnce>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Iterator, std::ptrdiff_t Disatnce>
using advance_t = typename sprout::types::advance<Iterator, Disatnce>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -19,6 +19,11 @@ namespace sprout {
struct deref
: public Iterator
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Iterator>
using deref_t = typename sprout::types::deref<Iterator>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -53,6 +53,16 @@ namespace sprout {
struct distance
: public sprout::types::detail::distance_impl<First, Last, 0>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename First, typename Last>
using distance_t = typename sprout::types::distance<First, Last>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename First, typename Last>
SPROUT_STATIC_CONSTEXPR std::size_t distance_v = sprout::types::distance<First, Last>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout

View file

@ -33,6 +33,11 @@ namespace sprout {
struct next<Iterator const volatile>
: public sprout::types::next<Iterator>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Iterator>
using next_t = typename sprout::types::next<Iterator>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -33,6 +33,11 @@ namespace sprout {
struct prev<Iterator const volatile>
: public sprout::types::prev<Iterator>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Iterator>
using prev_t = typename sprout::types::prev<Iterator>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -9,6 +9,11 @@
#define SPROUT_TYPE_OPERATION_HPP
#include <sprout/config.hpp>
#include <sprout/type/operation/size.hpp>
#include <sprout/type/operation/empty.hpp>
#include <sprout/type/operation/at.hpp>
#include <sprout/type/operation/back.hpp>
#include <sprout/type/operation/front.hpp>
#include <sprout/type/operation/append_back.hpp>
#include <sprout/type/operation/append_front.hpp>
#include <sprout/type/operation/push_back.hpp>

View file

@ -39,6 +39,11 @@ namespace sprout {
typename sprout::tuple_indexes<InputTuple>::type
>::type type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename InputTuple>
using append_back_t = typename sprout::types::append_back<Tuple, InputTuple>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -39,6 +39,11 @@ namespace sprout {
typename sprout::tuple_indexes<InputTuple>::type
>::type type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename InputTuple>
using append_front_t = typename sprout::types::append_front<Tuple, InputTuple>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -0,0 +1,32 @@
/*=============================================================================
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_TYPE_OPERATION_AT_HPP
#define SPROUT_TYPE_OPERATION_AT_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/tuple.hpp>
namespace sprout {
namespace types {
//
// at
//
template<typename Tuple, std::size_t I>
struct at
: public sprout::types::tuple_element<I, Tuple>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, std::size_t I>
using at_t = typename sprout::types::at<Tuple, I>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_OPERATION_AT_HPP

View file

@ -0,0 +1,32 @@
/*=============================================================================
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_TYPE_OPERATION_BACK_HPP
#define SPROUT_TYPE_OPERATION_BACK_HPP
#include <sprout/config.hpp>
#include <sprout/type/operation/size.hpp>
#include <sprout/type/operation/at.hpp>
namespace sprout {
namespace types {
//
// back
//
template<typename Tuple>
struct back
: public sprout::types::at<Tuple, (sprout::types::size<Tuple>::value - 1)>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple>
using back_t = typename sprout::types::back<Tuple>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_OPERATION_BACK_HPP

View file

@ -0,0 +1,35 @@
/*=============================================================================
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_TYPE_OPERATION_EMPTY_HPP
#define SPROUT_TYPE_OPERATION_EMPTY_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type/tuple.hpp>
namespace sprout {
namespace types {
//
// empty
//
template<typename Tuple>
struct empty
: public sprout::integral_constant<
bool,
(sprout::types::tuple_size<Tuple>::value == 0)
>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple>
SPROUT_STATIC_CONSTEXPR bool empty_v = sprout::types::empty<Tuple>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_OPERATION_EMPTY_HPP

View file

@ -0,0 +1,31 @@
/*=============================================================================
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_TYPE_OPERATION_FRONT_HPP
#define SPROUT_TYPE_OPERATION_FRONT_HPP
#include <sprout/config.hpp>
#include <sprout/type/operation/at.hpp>
namespace sprout {
namespace types {
//
// front
//
template<typename Tuple>
struct front
: public sprout::types::at<Tuple, 0>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple>
using front_t = typename sprout::types::front<Tuple>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_OPERATION_FRONT_HPP

View file

@ -36,6 +36,11 @@ namespace sprout {
typename sprout::make_index_tuple<sprout::types::tuple_size<Tuple>::value - 1>::type
>::type type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple>
using pop_back_t = typename sprout::types::pop_back<Tuple>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -36,6 +36,11 @@ namespace sprout {
typename sprout::index_range<1, sprout::types::tuple_size<Tuple>::value>::type
>::type type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple>
using pop_front_t = typename sprout::types::pop_front<Tuple>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -21,7 +21,6 @@ namespace sprout {
//
template<typename Tuple, typename... Ts>
struct push_back {
static_assert(sizeof...(Ts) >= 1, "sizeof...(Ts) >= 1");
private:
template<typename IndexTuple>
struct apply_impl;
@ -39,6 +38,11 @@ namespace sprout {
typename sprout::tuple_indexes<Tuple>::type
>::type type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename... Ts>
using push_back_t = typename sprout::types::push_back<Tuple, Ts...>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -21,7 +21,6 @@ namespace sprout {
//
template<typename Tuple, typename... Ts>
struct push_front {
static_assert(sizeof...(Ts) >= 1, "sizeof...(Ts) >= 1");
private:
template<typename IndexTuple>
struct apply_impl;
@ -39,6 +38,11 @@ namespace sprout {
typename sprout::tuple_indexes<Tuple>::type
>::type type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename Tuple, typename... Ts>
using push_front_t = typename sprout::types::push_front<Tuple, Ts...>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace types
} // namespace sprout

View file

@ -0,0 +1,32 @@
/*=============================================================================
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_TYPE_OPERATION_SIZE_HPP
#define SPROUT_TYPE_OPERATION_SIZE_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type/tuple.hpp>
namespace sprout {
namespace types {
//
// size
//
template<typename Tuple>
struct size
: public sprout::types::tuple_size<Tuple>
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple>
SPROUT_STATIC_CONSTEXPR std::size_t size_v = sprout::types::size<Tuple>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_OPERATION_SIZE_HPP

View file

@ -76,6 +76,11 @@ namespace sprout {
T
>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename ForwardSequence, typename T>
using find_t = typename sprout::types::seq::find<ForwardSequence, T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace seq
} // namespace types
} // namespace sprout

View file

@ -76,6 +76,11 @@ namespace sprout {
Predicate
>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename ForwardSequence, typename Predicate>
using find_if_t = typename sprout::types::seq::find_if<ForwardSequence, Predicate>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace seq
} // namespace types
} // namespace sprout

View file

@ -48,7 +48,7 @@ namespace std {
//
template<std::size_t I, typename T, T... Values>
struct tuple_element<I, sprout::types::basic_string<T, Values...> >
: public std::tuple_element<I, sprout::types::integral_array<T, Values...> >
: public sprout::types::tuple_element<I, sprout::types::integral_array<T, Values...> >
{};
#if defined(__clang__)
# pragma clang diagnostic pop

View file

@ -12,6 +12,7 @@
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
namespace sprout {
namespace types {
@ -42,8 +43,23 @@ namespace sprout {
//
template<std::size_t I, typename T, typename Enable = void>
struct tuple_element
: public std::tuple_element<I, T>
: public sprout::tuples::tuple_element<I, T>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using begin_t = typename sprout::types::begin<T>::type;
template<typename T>
using end_t = typename sprout::types::end<T>::type;
template<std::size_t I, typename T>
using tuple_element_t = typename sprout::types::tuple_element<I, T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename Tuple>
SPROUT_STATIC_CONSTEXPR std::size_t tuple_size_v = sprout::types::tuple_size<Tuple>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace types
} // namespace sprout

View file

@ -20,6 +20,7 @@
#include <sprout/type/rebind_types.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace types {
@ -54,6 +55,10 @@ namespace sprout {
namespace detail {
template<typename Tup>
struct head_element;
template<>
struct head_element<sprout::types::type_tuple<> >
: public sprout::detail::nil_base
{};
template<typename Head, typename... Tail>
struct head_element<sprout::types::type_tuple<Head, Tail...> >
: public sprout::identity<Head>
@ -61,6 +66,10 @@ namespace sprout {
template<typename Tup>
struct tuple_head;
template<>
struct tuple_head<sprout::types::type_tuple<> >
: public sprout::detail::nil_base
{};
template<typename Head, typename... Tail>
struct tuple_head<sprout::types::type_tuple<Head, Tail...> >
: public sprout::identity<sprout::types::type_tuple<Head> >
@ -68,6 +77,10 @@ namespace sprout {
template<typename Tup>
struct tuple_tail;
template<>
struct tuple_tail<sprout::types::type_tuple<> >
: public sprout::detail::nil_base
{};
template<typename Head, typename... Tail>
struct tuple_tail<sprout::types::type_tuple<Head, Tail...> >
: public sprout::identity<sprout::types::type_tuple<Tail...> >
@ -93,35 +106,49 @@ namespace sprout {
static sprout::types::type_tuple<typename Types::type...>
eval(typename sprout::types::detail::dummy_index<Indexes>::type*..., Types*...);
};
template<std::size_t I, typename Tup>
template<std::size_t I, typename Tup, bool = (I <= sprout::types::tuple_size<Tup>::value)>
struct tuple_drop_impl;
template<std::size_t I, typename Tup>
struct tuple_drop_impl<I, Tup, false>
: public sprout::detail::nil_base
{};
template<std::size_t I, typename... Types>
struct tuple_drop_impl<I, sprout::types::type_tuple<Types...> >
struct tuple_drop_impl<I, sprout::types::type_tuple<Types...>, true>
: public sprout::identity<decltype(
sprout::types::detail::tuple_drop_helper<typename sprout::index_n<0, I>::type>
::eval(static_cast<sprout::identity<Types>*>(0)...)
)>::type
{};
template<std::size_t I, typename Tup>
struct tuple_drop;
template<std::size_t I, typename... Types>
struct tuple_drop<I, sprout::types::type_tuple<Types...> >
: public sprout::types::detail::tuple_drop_impl<I, sprout::types::type_tuple<Types...> >
struct tuple_drop
: public sprout::types::detail::tuple_drop_impl<I, Tup>
{};
template<std::size_t I, typename Tup, bool = (I < sprout::types::tuple_size<Tup>::value)>
struct tuple_element_impl;
template<std::size_t I, typename Tup>
struct tuple_element;
struct tuple_element_impl<I, Tup, false>
: public sprout::detail::nil_base
{};
template<std::size_t I, typename... Types>
struct tuple_element<I, sprout::types::type_tuple<Types...> >
struct tuple_element_impl<I, sprout::types::type_tuple<Types...>, true>
: public sprout::types::detail::head_element<
typename sprout::types::detail::tuple_drop<I, sprout::types::type_tuple<Types...> >::type
>
{};
template<std::size_t I, typename Tup>
struct tuple_element
: public sprout::types::detail::tuple_element_impl<I, Tup>
{};
template<std::size_t I, typename Tup, typename IndexTuple>
template<std::size_t I, typename Tup, typename IndexTuple, bool = (I <= sprout::types::tuple_size<Tup>::value)>
struct tuple_take_impl;
template<std::size_t I, typename Tup, typename IndexTuple>
struct tuple_take_impl<I, Tup, IndexTuple, false>
: public sprout::detail::nil_base
{};
template<std::size_t I, typename... Types, sprout::index_t... Indexes>
struct tuple_take_impl<I, sprout::types::type_tuple<Types...>, sprout::index_tuple<Indexes...> >
struct tuple_take_impl<I, sprout::types::type_tuple<Types...>, sprout::index_tuple<Indexes...>, true>
: public sprout::identity<
sprout::types::type_tuple<
typename sprout::types::detail::tuple_element<Indexes, sprout::types::type_tuple<Types...> >::type...
@ -166,4 +193,64 @@ namespace std {
#endif
} // namespace std
namespace sprout {
namespace types {
//
// push_back
//
template<typename Tuple, typename... Ts>
struct push_back;
template<typename... Types, typename... Ts>
struct push_back<sprout::types::type_tuple<Types...>, Ts...>
: public sprout::identity<sprout::types::type_tuple<Types..., Ts...> >
{};
//
// push_front
//
template<typename Tuple, typename... Ts>
struct push_front;
template<typename... Types, typename... Ts>
struct push_front<sprout::types::type_tuple<Types...>, Ts...>
: public sprout::identity<sprout::types::type_tuple<Ts..., Types...> >
{};
//
// pop_back
//
template<typename Tuple>
struct pop_back;
template<typename... Types>
struct pop_back<sprout::types::type_tuple<Types...> >
: public sprout::types::detail::tuple_take<(sizeof...(Types) - 1), sprout::types::type_tuple<Types...> >
{};
//
// pop_front
//
template<typename Tuple>
struct pop_front;
template<typename Head, typename... Tail>
struct pop_front<sprout::types::type_tuple<Head, Tail...> >
: public sprout::identity<sprout::types::type_tuple<Tail...> >
{};
//
// append_back
//
template<typename Tuple, typename InputTuple>
struct append_back;
template<typename Tuple, typename... InputTypes>
struct append_back<Tuple, sprout::types::type_tuple<InputTypes...> >
: public sprout::types::push_back<Tuple, InputTypes...>
{};
//
// append_front
//
template<typename Tuple, typename InputTuple>
struct append_front;
template<typename Tuple, typename... InputTypes>
struct append_front<Tuple, sprout::types::type_tuple<InputTypes...> >
: public sprout::types::push_front<InputTypes..., Tuple>
{};
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TYPE_TUPLE_HPP

View file

@ -8,6 +8,7 @@
#ifndef SPROUT_TYPE_UNIFORM_TYPES_HPP
#define SPROUT_TYPE_UNIFORM_TYPES_HPP
#include <type_traits>
#include <tuple>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
@ -16,6 +17,8 @@
#include <sprout/type/iterator/index_iterator.hpp>
#include <sprout/type/rebind_types.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace types {
@ -69,11 +72,9 @@ namespace std {
// tuple_element
//
template<std::size_t I, typename T, std::size_t N>
struct tuple_element<I, sprout::types::uniform_types<T, N> > {
static_assert(I < N, "tuple_element<>: index out of range");
public:
typedef T type;
};
struct tuple_element<I, sprout::types::uniform_types<T, N> >
: public std::conditional<(I < N), sprout::identity<T>, sprout::detail::nil_base>::type
{};
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View file

@ -18,5 +18,6 @@
#include <sprout/utility/value_holder.hpp>
#include <sprout/utility/string_ref.hpp>
#include <sprout/utility/any_convertible.hpp>
#include <sprout/utility/use_default.hpp>
#endif // #ifndef SPROUT_UTILITY_HPP

View file

@ -15,6 +15,7 @@
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
//
@ -30,7 +31,7 @@ namespace sprout {
//
template<std::size_t I, typename T, T... Args>
struct pack_element_c
: public sprout::pack_element<I, sprout::integral_constant<T, Args>...>::type
: public sprout::pack_element<I, sprout::integral_constant<T, Args>...>
{};
//
@ -59,10 +60,16 @@ namespace sprout {
//
// head_element
//
template<typename... Args>
struct head_element;
template<typename Head, typename... Tail>
struct head_element
struct head_element<Head, Tail...>
: public sprout::identity<Head>
{};
template<>
struct head_element<>
: public sprout::detail::nil_base
{};
//
// head_get

View file

@ -13,22 +13,26 @@
#include <sprout/utility/pair/pair.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
namespace tuples {
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
template<std::size_t I, typename T1, typename T2>
struct tuple_element_impl<I, sprout::pair<T1, T2> >
: public sprout::detail::nil_base
{};
template<typename T1, typename T2>
struct tuple_element_impl<0, sprout::pair<T1, T2> > {
public:
typedef T1 type;
};
struct tuple_element_impl<0, sprout::pair<T1, T2> >
: public sprout::identity<T1>
{};
template<typename T1, typename T2>
struct tuple_element_impl<1, sprout::pair<T1, T2> > {
public:
typedef T2 type;
};
struct tuple_element_impl<1, sprout::pair<T1, T2> >
: public sprout::identity<T2>
{};
template<std::size_t I, typename T>
struct get_impl;

View file

@ -0,0 +1,37 @@
/*=============================================================================
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.sprout.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_UTILITY_USE_DEFAULT_HPP
#define SPROUT_UTILITY_USE_DEFAULT_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
//
// use_default
//
struct use_default;
//
// is_use_default
//
template<typename T>
struct is_use_default
: public sprout::is_same<T, sprout::use_default>
{};
//
// select_default
//
template<typename T, typename Default>
struct select_default
: public std::conditional<sprout::is_use_default<T>::value, Default, T>
{};
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_USE_DEFAULT_HPP

View file

@ -8,6 +8,7 @@
#ifndef SPROUT_UUID_TUPLE_HPP
#define SPROUT_UUID_TUPLE_HPP
#include <type_traits>
#include <tuple>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
@ -15,6 +16,8 @@
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/uuid/uuid.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
//
@ -48,21 +51,17 @@ namespace std {
// tuple_size
//
template<>
struct tuple_size<sprout::uuids::uuid> {
public:
typedef sprout::integral_constant<std::size_t, 16> type;
SPROUT_STATIC_CONSTEXPR std::size_t value = type::value;
};
struct tuple_size<sprout::uuids::uuid>
: public sprout::integral_constant<std::size_t, 16>
{};
//
// tuple_element
//
template<std::size_t I>
struct tuple_element<I, sprout::uuids::uuid> {
static_assert(I < 16, "tuple_element<>: index out of range");
public:
typedef sprout::uuids::uuid::value_type type;
};
struct tuple_element<I, sprout::uuids::uuid>
: public std::conditional<(I < 16), sprout::identity<sprout::uuids::uuid::value_type>, sprout::detail::nil_base>::type
{};
#if defined(__clang__)
# pragma clang diagnostic pop
#endif

View file

@ -13,6 +13,7 @@
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/variant/variant.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout {
@ -63,7 +64,7 @@ namespace std {
//
template<std::size_t I, typename... Types>
struct tuple_element<I, sprout::variant<Types...> >
: public std::tuple_element<I, typename sprout::variant<Types...>::tuple_type>
: public sprout::tuples::tuple_element<I, typename sprout::variant<Types...>::tuple_type>
{};
#if defined(__clang__)
# pragma clang diagnostic pop