1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

add enable_make_indexes

This commit is contained in:
bolero-MURAKAMI 2013-04-06 13:06:51 +09:00
parent bc2e3e245b
commit 410c369a6a
100 changed files with 237 additions and 156 deletions

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_INDEX_TUPLE_CLASS_HPP
#define SPROUT_INDEX_TUPLE_CLASS_HPP
#include <sprout/config.hpp>
#include <sprout/index_tuple/integer_seq.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#endif // #ifndef SPROUT_INDEX_TUPLE_CLASS_HPP

View file

@ -1,22 +0,0 @@
#ifndef SPROUT_INDEX_TUPLE_DETAIL_MAKE_INDEXES_HELPER_HPP
#define SPROUT_INDEX_TUPLE_DETAIL_MAKE_INDEXES_HELPER_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace detail {
template<typename IndexTupleType>
struct make_indexes_helper
: public IndexTupleType::type
{
public:
typedef typename IndexTupleType::type type;
public:
static SPROUT_CONSTEXPR type make() {
return type();
}
};
} // namespace detail
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_DETAIL_MAKE_INDEXES_HELPER_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_INDEX_TUPLE_ENABLE_MAKE_INDEXES_HPP
#define SPROUT_INDEX_TUPLE_ENABLE_MAKE_INDEXES_HPP
#include <sprout/config.hpp>
namespace sprout {
//
// enable_make_indexes
//
template<typename IndexTupleType>
struct enable_make_indexes
: public IndexTupleType::type
{
public:
typedef typename IndexTupleType::type type;
public:
static SPROUT_CONSTEXPR type make() {
return type();
}
};
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_ENABLE_MAKE_INDEXES_HPP

View file

@ -4,7 +4,7 @@
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/index_tuple/integer_n.hpp>
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
#include <sprout/index_tuple/enable_make_indexes.hpp>
namespace sprout {
//
@ -12,9 +12,9 @@ namespace sprout {
//
template<sprout::index_t I, std::size_t N>
struct index_n
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
typename sprout::integer_n<sprout::index_t, I, N>::type
::template transfer<sprout::index_tuple<> >::type
::template transfer<sprout::index_tuple<> >
>
{};
//
@ -22,9 +22,9 @@ namespace sprout {
//
template<sprout::uindex_t I, std::size_t N>
struct uindex_n
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
typename sprout::integer_n<sprout::uindex_t, I, N>::type
::template transfer<sprout::uindex_tuple<> >::type
::template transfer<sprout::uindex_tuple<> >
>
{};
} // namespace sprout

View file

@ -4,7 +4,7 @@
#include <sprout/config.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#include <sprout/index_tuple/integer_range.hpp>
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
#include <sprout/index_tuple/enable_make_indexes.hpp>
namespace sprout {
//
@ -15,9 +15,9 @@ namespace sprout {
typename std::make_signed<sprout::index_t>::type Step = sprout::detail::integer_range_default_step<sprout::index_t, First, Last>::value
>
struct index_range
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
typename sprout::integer_range<sprout::index_t, First, Last, Step>::type
::template transfer<sprout::index_tuple<> >::type
::template transfer<sprout::index_tuple<> >
>
{};
//
@ -28,9 +28,9 @@ namespace sprout {
typename std::make_signed<sprout::uindex_t>::type Step = sprout::detail::integer_range_default_step<sprout::uindex_t, First, Last>::value
>
struct uindex_range
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
typename sprout::integer_range<sprout::uindex_t, First, Last, Step>::type
::template transfer<sprout::uindex_tuple<> >::type
::template transfer<sprout::uindex_tuple<> >
>
{};
} // namespace sprout

View file

@ -5,7 +5,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/index_tuple/integer_seq.hpp>
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
#include <sprout/index_tuple/enable_make_indexes.hpp>
namespace sprout {
//
@ -64,7 +64,7 @@ namespace sprout {
} // namespace detail
template<typename T, T I, std::size_t N>
struct integer_n
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
sprout::detail::integer_n_impl<T, I, N>
>
{};

View file

@ -4,7 +4,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/index_tuple/integer_seq.hpp>
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
#include <sprout/index_tuple/enable_make_indexes.hpp>
namespace sprout {
namespace detail {
@ -86,7 +86,7 @@ namespace sprout {
typename std::make_signed<T>::type Step = sprout::detail::integer_range_default_step<T, First, Last>::value
>
struct integer_range
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
sprout::detail::integer_range<T, First, Last, Step>
>
{

View file

@ -5,7 +5,7 @@
#include <sprout/config.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#include <sprout/index_tuple/make_integer_seq.hpp>
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
#include <sprout/index_tuple/enable_make_indexes.hpp>
namespace sprout {
//
@ -13,7 +13,7 @@ namespace sprout {
//
template<sprout::index_t N>
struct make_index_tuple
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
typename sprout::make_integer_seq<sprout::index_t, N>::type
::template transfer<sprout::index_tuple<> >::type
>
@ -23,7 +23,7 @@ namespace sprout {
//
template<sprout::uindex_t N>
struct make_uindex_tuple
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
typename sprout::make_integer_seq<sprout::uindex_t, N>::type
::template transfer<sprout::uindex_tuple<> >::type
>

View file

@ -3,7 +3,7 @@
#include <sprout/config.hpp>
#include <sprout/index_tuple/integer_range.hpp>
#include <sprout/index_tuple/detail/make_indexes_helper.hpp>
#include <sprout/index_tuple/enable_make_indexes.hpp>
namespace sprout {
//
@ -11,7 +11,7 @@ namespace sprout {
//
template<typename T, T N>
struct make_integer_seq
: public sprout::detail::make_indexes_helper<
: public sprout::enable_make_indexes<
sprout::integer_range<T, 0, N>
>
{};

View file

@ -0,0 +1,12 @@
#ifndef SPROUT_INDEX_TUPLE_METAFUNCTION_HPP
#define SPROUT_INDEX_TUPLE_METAFUNCTION_HPP
#include <sprout/config.hpp>
#include <sprout/index_tuple/make_integer_seq.hpp>
#include <sprout/index_tuple/make_index_tuple.hpp>
#include <sprout/index_tuple/integer_range.hpp>
#include <sprout/index_tuple/index_range.hpp>
#include <sprout/index_tuple/integer_n.hpp>
#include <sprout/index_tuple/index_n.hpp>
#endif // #ifndef SPROUT_INDEX_TUPLE_METAFUNCTION_HPP

View file

@ -7,6 +7,7 @@
#include <sprout/config.hpp>
#include <sprout/index_tuple/integer_seq.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#include <sprout/utility/pack.hpp>
namespace std {
#if defined(__clang__)
@ -27,7 +28,7 @@ namespace std {
struct tuple_element<I, sprout::integer_seq<T, Is...> > {
static_assert(I < sizeof...(Is), "tuple_element<>: index out of range");
public:
typedef T type;
typedef typename sprout::tppack_c_at<I, T, Is...>::type type;
};
//
@ -64,4 +65,39 @@ namespace std {
#endif
} // namespace std
namespace sprout {
//
// tuple_get
//
template<std::size_t I, typename T, T... Is>
inline SPROUT_CONSTEXPR typename std::tuple_element<I, sprout::integer_seq<T, Is...> >::type
tuple_get(sprout::integer_seq<T, Is...>) SPROUT_NOEXCEPT {
static_assert(I < sizeof...(Is), "tuple_get: index out of range");
typedef typename std::tuple_element<I, sprout::integer_seq<T, Is...> >::type type;
return type();
}
//
// tuple_get
//
template<std::size_t I, sprout::index_t... Indexes>
inline SPROUT_CONSTEXPR typename std::tuple_element<I, sprout::index_tuple<Indexes...> >::type
tuple_get(sprout::index_tuple<Indexes...>) SPROUT_NOEXCEPT {
static_assert(I < sizeof...(Indexes), "tuple_get: index out of range");
typedef typename std::tuple_element<I, sprout::index_tuple<Indexes...> >::type type;
return type();
}
//
// tuple_get
//
template<std::size_t I, sprout::uindex_t... Indexes>
inline SPROUT_CONSTEXPR typename std::tuple_element<I, sprout::uindex_tuple<Indexes...> >::type
tuple_get(sprout::uindex_tuple<Indexes...>) SPROUT_NOEXCEPT {
static_assert(I < sizeof...(Indexes), "tuple_get: index out of range");
typedef typename std::tuple_element<I, sprout::uindex_tuple<Indexes...> >::type type;
return type();
}
} // namespace sprout
#endif // #ifndef SPROUT_INDEX_TUPLE_TUPLE_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_INDEX_TUPLE_UTILITY_HPP
#define SPROUT_INDEX_TUPLE_UTILITY_HPP
#include <sprout/config.hpp>
#include <sprout/index_tuple/make_indexes.hpp>
#include <sprout/index_tuple/enable_make_indexes.hpp>
#endif // #ifndef SPROUT_INDEX_TUPLE_UTILITY_HPP