mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-04 14:14:09 +00:00
fix index_tuple implementation: template aliases (if compiler supported)
This commit is contained in:
parent
bb36ef6e8b
commit
3ff1ffb4d9
8 changed files with 78 additions and 21 deletions
|
@ -2,6 +2,7 @@
|
||||||
#define SPROUT_INDEX_TUPLE_CLASS_HPP
|
#define SPROUT_INDEX_TUPLE_CLASS_HPP
|
||||||
|
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/index_tuple/index_t.hpp>
|
||||||
#include <sprout/index_tuple/integer_sequence.hpp>
|
#include <sprout/index_tuple/integer_sequence.hpp>
|
||||||
#include <sprout/index_tuple/index_tuple.hpp>
|
#include <sprout/index_tuple/index_tuple.hpp>
|
||||||
#include <sprout/index_tuple/index_sequence.hpp>
|
#include <sprout/index_tuple/index_sequence.hpp>
|
||||||
|
|
|
@ -10,7 +10,15 @@
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
// index_n
|
// index_n
|
||||||
|
// uindex_n
|
||||||
//
|
//
|
||||||
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<sprout::index_t I, std::size_t N>
|
||||||
|
using index_n = sprout::integer_n<sprout::index_t, I, N>;
|
||||||
|
|
||||||
|
template<sprout::uindex_t I, std::size_t N>
|
||||||
|
using uindex_n = sprout::integer_n<sprout::uindex_t, I, N>;
|
||||||
|
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
template<sprout::index_t I, std::size_t N>
|
template<sprout::index_t I, std::size_t N>
|
||||||
struct index_n
|
struct index_n
|
||||||
: public sprout::enable_make_indexes<
|
: public sprout::enable_make_indexes<
|
||||||
|
@ -18,9 +26,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::index_tuple<> >
|
::template transfer<sprout::index_tuple<> >
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
//
|
|
||||||
// uindex_n
|
|
||||||
//
|
|
||||||
template<sprout::uindex_t I, std::size_t N>
|
template<sprout::uindex_t I, std::size_t N>
|
||||||
struct uindex_n
|
struct uindex_n
|
||||||
: public sprout::enable_make_indexes<
|
: public sprout::enable_make_indexes<
|
||||||
|
@ -28,6 +34,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::uindex_tuple<> >
|
::template transfer<sprout::uindex_tuple<> >
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_N_HPP
|
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_N_HPP
|
||||||
|
|
|
@ -9,7 +9,15 @@
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
// index_pack
|
// index_pack
|
||||||
|
// uindex_pack
|
||||||
//
|
//
|
||||||
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<typename... Ts>
|
||||||
|
using index_pack = sprout::integer_pack<sprout::index_t, Ts...>;
|
||||||
|
|
||||||
|
template<typename... Ts>
|
||||||
|
using uindex_pack = sprout::integer_pack<sprout::uindex_t, Ts...>;
|
||||||
|
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
struct index_pack
|
struct index_pack
|
||||||
: public sprout::enable_make_indexes<
|
: public sprout::enable_make_indexes<
|
||||||
|
@ -17,9 +25,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::index_tuple<> >
|
::template transfer<sprout::index_tuple<> >
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
//
|
|
||||||
// uindex_pack
|
|
||||||
//
|
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
struct uindex_pack
|
struct uindex_pack
|
||||||
: public sprout::enable_make_indexes<
|
: public sprout::enable_make_indexes<
|
||||||
|
@ -27,6 +33,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::uindex_tuple<> >
|
::template transfer<sprout::uindex_tuple<> >
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_PACK_HPP
|
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_PACK_HPP
|
||||||
|
|
|
@ -9,7 +9,21 @@
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
// index_range
|
// index_range
|
||||||
|
// uindex_range
|
||||||
//
|
//
|
||||||
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<
|
||||||
|
sprout::index_t First, sprout::index_t Last,
|
||||||
|
typename std::make_signed<sprout::index_t>::type Step = sprout::detail::integer_range_default_step<sprout::index_t, First, Last>::value
|
||||||
|
>
|
||||||
|
using index_range = sprout::integer_range<sprout::index_t, First, Last, Step>;
|
||||||
|
|
||||||
|
template<
|
||||||
|
sprout::uindex_t First, sprout::uindex_t Last,
|
||||||
|
typename std::make_signed<sprout::uindex_t>::type Step = sprout::detail::integer_range_default_step<sprout::uindex_t, First, Last>::value
|
||||||
|
>
|
||||||
|
using uindex_range = sprout::integer_range<sprout::uindex_t, First, Last, Step>;
|
||||||
|
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
template<
|
template<
|
||||||
sprout::index_t First, sprout::index_t Last,
|
sprout::index_t First, sprout::index_t Last,
|
||||||
typename std::make_signed<sprout::index_t>::type Step = sprout::detail::integer_range_default_step<sprout::index_t, First, Last>::value
|
typename std::make_signed<sprout::index_t>::type Step = sprout::detail::integer_range_default_step<sprout::index_t, First, Last>::value
|
||||||
|
@ -20,9 +34,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::index_tuple<> >
|
::template transfer<sprout::index_tuple<> >
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
//
|
|
||||||
// uindex_range
|
|
||||||
//
|
|
||||||
template<
|
template<
|
||||||
sprout::uindex_t First, sprout::uindex_t Last,
|
sprout::uindex_t First, sprout::uindex_t Last,
|
||||||
typename std::make_signed<sprout::uindex_t>::type Step = sprout::detail::integer_range_default_step<sprout::uindex_t, First, Last>::value
|
typename std::make_signed<sprout::uindex_t>::type Step = sprout::detail::integer_range_default_step<sprout::uindex_t, First, Last>::value
|
||||||
|
@ -33,6 +45,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::uindex_tuple<> >
|
::template transfer<sprout::uindex_tuple<> >
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_RANGE_HPP
|
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_RANGE_HPP
|
||||||
|
|
16
sprout/index_tuple/index_t.hpp
Normal file
16
sprout/index_tuple/index_t.hpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef SPROUT_INDEX_TUPLE_INDEX_T_HPP
|
||||||
|
#define SPROUT_INDEX_TUPLE_INDEX_T_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// index_t
|
||||||
|
// uindex_t
|
||||||
|
//
|
||||||
|
typedef std::ptrdiff_t index_t;
|
||||||
|
typedef std::size_t uindex_t;
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_T_HPP
|
|
@ -1,16 +1,22 @@
|
||||||
#ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
#ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
||||||
#define SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
#define SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/index_tuple/index_t.hpp>
|
||||||
#include <sprout/index_tuple/integer_sequence.hpp>
|
#include <sprout/index_tuple/integer_sequence.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
// index_t
|
|
||||||
// index_tuple
|
// index_tuple
|
||||||
|
// uindex_tuple
|
||||||
//
|
//
|
||||||
typedef std::ptrdiff_t index_t;
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<sprout::index_t... Indexes>
|
||||||
|
using index_tuple = sprout::integer_sequence<sprout::index_t, Indexes...>;
|
||||||
|
|
||||||
|
template<sprout::uindex_t... Indexes>
|
||||||
|
using uindex_tuple = sprout::integer_sequence<sprout::uindex_t, Indexes...>;
|
||||||
|
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
template<sprout::index_t... Indexes>
|
template<sprout::index_t... Indexes>
|
||||||
struct index_tuple
|
struct index_tuple
|
||||||
: public sprout::integer_sequence<sprout::index_t, Indexes...>
|
: public sprout::integer_sequence<sprout::index_t, Indexes...>
|
||||||
|
@ -23,11 +29,6 @@ namespace sprout {
|
||||||
{};
|
{};
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
|
||||||
// uindex_t
|
|
||||||
// uindex_tuple
|
|
||||||
//
|
|
||||||
typedef std::size_t uindex_t;
|
|
||||||
template<sprout::uindex_t... Indexes>
|
template<sprout::uindex_t... Indexes>
|
||||||
struct uindex_tuple
|
struct uindex_tuple
|
||||||
: public sprout::integer_sequence<sprout::uindex_t, Indexes...>
|
: public sprout::integer_sequence<sprout::uindex_t, Indexes...>
|
||||||
|
@ -39,6 +40,7 @@ namespace sprout {
|
||||||
: public uindex_tuple<J...>
|
: public uindex_tuple<J...>
|
||||||
{};
|
{};
|
||||||
};
|
};
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
#endif // #ifndef SPROUT_INDEX_TUPLE_INDEX_TUPLE_HPP
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
|
#ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
|
||||||
#define SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
|
#define SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/index_tuple/index_tuple.hpp>
|
#include <sprout/index_tuple/index_tuple.hpp>
|
||||||
#include <sprout/index_tuple/make_integer_sequence.hpp>
|
#include <sprout/index_tuple/make_integer_sequence.hpp>
|
||||||
|
@ -10,7 +9,15 @@
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
// make_index_tuple
|
// make_index_tuple
|
||||||
|
// make_uindex_tuple
|
||||||
//
|
//
|
||||||
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<sprout::index_t N>
|
||||||
|
using make_index_tuple = sprout::make_integer_sequence<sprout::index_t, N>;
|
||||||
|
|
||||||
|
template<sprout::uindex_t N>
|
||||||
|
using make_uindex_tuple = sprout::make_integer_sequence<sprout::uindex_t, N>;
|
||||||
|
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
template<sprout::index_t N>
|
template<sprout::index_t N>
|
||||||
struct make_index_tuple
|
struct make_index_tuple
|
||||||
: public sprout::enable_make_indexes<
|
: public sprout::enable_make_indexes<
|
||||||
|
@ -18,9 +25,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::index_tuple<> >::type
|
::template transfer<sprout::index_tuple<> >::type
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
//
|
|
||||||
// make_uindex_tuple
|
|
||||||
//
|
|
||||||
template<sprout::uindex_t N>
|
template<sprout::uindex_t N>
|
||||||
struct make_uindex_tuple
|
struct make_uindex_tuple
|
||||||
: public sprout::enable_make_indexes<
|
: public sprout::enable_make_indexes<
|
||||||
|
@ -28,6 +33,7 @@ namespace sprout {
|
||||||
::template transfer<sprout::uindex_tuple<> >::type
|
::template transfer<sprout::uindex_tuple<> >::type
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
|
#endif // #ifndef SPROUT_INDEX_TUPLE_MAKE_INDEX_TUPLE_HPP
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace std {
|
||||||
typedef typename sprout::tppack_c_at<I, T, Is...>::type type;
|
typedef typename sprout::tppack_c_at<I, T, Is...>::type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !SPROUT_USE_TEMPLATE_ALIASES
|
||||||
//
|
//
|
||||||
// tuple_size
|
// tuple_size
|
||||||
//
|
//
|
||||||
|
@ -60,6 +61,8 @@ namespace std {
|
||||||
struct tuple_element<I, sprout::uindex_tuple<Indexes...> >
|
struct tuple_element<I, sprout::uindex_tuple<Indexes...> >
|
||||||
: public std::tuple_element<I, sprout::integer_sequence<sprout::uindex_t, Indexes...> >
|
: public std::tuple_element<I, sprout::integer_sequence<sprout::uindex_t, Indexes...> >
|
||||||
{};
|
{};
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
# pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
@ -77,6 +80,7 @@ namespace sprout {
|
||||||
return type();
|
return type();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !SPROUT_USE_TEMPLATE_ALIASES
|
||||||
//
|
//
|
||||||
// tuple_get
|
// tuple_get
|
||||||
//
|
//
|
||||||
|
@ -98,6 +102,7 @@ namespace sprout {
|
||||||
typedef typename std::tuple_element<I, sprout::uindex_tuple<Indexes...> >::type type;
|
typedef typename std::tuple_element<I, sprout::uindex_tuple<Indexes...> >::type type;
|
||||||
return type();
|
return type();
|
||||||
}
|
}
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_INDEX_TUPLE_TUPLE_HPP
|
#endif // #ifndef SPROUT_INDEX_TUPLE_TUPLE_HPP
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue