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

fix tuple_element order

This commit is contained in:
bolero-MURAKAMI 2013-11-29 22:21:07 +09:00
parent 403e83eaf0
commit c9610b5ae5
9 changed files with 70 additions and 63 deletions

View file

@ -35,7 +35,7 @@ namespace std {
struct tuple_element<I, sprout::integer_sequence<T, Is...> > { struct tuple_element<I, sprout::integer_sequence<T, Is...> > {
static_assert(I < sizeof...(Is), "tuple_element<>: index out of range"); static_assert(I < sizeof...(Is), "tuple_element<>: index out of range");
public: public:
typedef typename sprout::tppack_c_at<I, T, Is...>::type type; typedef typename sprout::pack_element_c<I, T, Is...>::type type;
}; };
#if !SPROUT_USE_TEMPLATE_ALIASES #if !SPROUT_USE_TEMPLATE_ALIASES

View file

@ -17,6 +17,7 @@
#include <sprout/utility/swap.hpp> #include <sprout/utility/swap.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/utility/move.hpp> #include <sprout/utility/move.hpp>
#include <sprout/type_traits/std_type_traits.hpp>
#include <sprout/type_traits/is_convert_constructible.hpp> #include <sprout/type_traits/is_convert_constructible.hpp>
#include <sprout/none.hpp> #include <sprout/none.hpp>
#include <sprout/optional/nullopt.hpp> #include <sprout/optional/nullopt.hpp>
@ -53,7 +54,7 @@ namespace sprout {
public: public:
template<typename... Args> template<typename... Args>
struct is_constructible_args struct is_constructible_args
: public std::is_constructible<T, Args&&...> : public sprout::is_constructible<T, Args&&...>
{}; {};
public: public:
static SPROUT_CONSTEXPR reference_type get(optional& t) SPROUT_NOEXCEPT { static SPROUT_CONSTEXPR reference_type get(optional& t) SPROUT_NOEXCEPT {

View file

@ -267,8 +267,8 @@ namespace sprout {
struct is_flexibly_convert_constructible_impl<sprout::index_tuple<Indexes...>, Utypes...> struct is_flexibly_convert_constructible_impl<sprout::index_tuple<Indexes...>, Utypes...>
: public sprout::tpp::all_of< : public sprout::tpp::all_of<
sprout::is_convert_constructible< sprout::is_convert_constructible<
typename sprout::tppack_at<Indexes, Types...>::type, typename sprout::pack_element<Indexes, Types...>::type,
typename sprout::tppack_at<Indexes, Utypes...>::type typename sprout::pack_element<Indexes, Utypes...>::type
>... >...
> >
{}; {};
@ -466,20 +466,6 @@ namespace sprout {
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
template<typename Head, typename... Tail>
struct tuple_element_impl<0, sprout::tuples::tuple<Head, Tail...> > {
public:
typedef Head type;
};
template<std::size_t I, typename Head, typename... Tail>
struct tuple_element_impl<I, sprout::tuples::tuple<Head, Tail...> >
: public sprout::tuples::detail::tuple_element_impl<I - 1, sprout::tuples::tuple<Tail...> >
{};
} // namespace detail
} // namespace tuples } // namespace tuples
using sprout::tuples::tuple; using sprout::tuples::tuple;
@ -504,7 +490,7 @@ namespace std {
// //
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
struct tuple_element<I, sprout::tuples::tuple<Types...> > struct tuple_element<I, sprout::tuples::tuple<Types...> >
: public sprout::tuples::detail::tuple_element_impl<I, sprout::tuples::tuple<Types...> > : public sprout::pack_element<I, Types...>
{}; {};
#if defined(__clang__) #if defined(__clang__)
# pragma clang diagnostic pop # pragma clang diagnostic pop

View file

@ -10,6 +10,7 @@
#include <tuple> #include <tuple>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
namespace sprout { namespace sprout {
namespace tuples { namespace tuples {
@ -18,7 +19,7 @@ namespace sprout {
// //
template<typename T> template<typename T>
struct tuple_size struct tuple_size
: public std::tuple_size<T> : public sprout::detail::type_traits_wrapper<std::tuple_size<T> >
{}; {};
template<typename T> template<typename T>
struct tuple_size<T const> struct tuple_size<T const>

View file

@ -11,6 +11,7 @@
#include <cstddef> #include <cstddef>
#include <tuple> #include <tuple>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
namespace sprout { namespace sprout {
namespace types { namespace types {
@ -34,7 +35,7 @@ namespace sprout {
// //
template<typename T, typename Enable = void> template<typename T, typename Enable = void>
struct tuple_size struct tuple_size
: public std::tuple_size<T> : public sprout::detail::type_traits_wrapper<std::tuple_size<T> >
{}; {};
// //
// tuple_element // tuple_element

View file

@ -10,12 +10,14 @@
#include <cstddef> #include <cstddef>
#include <tuple> #include <tuple>
#include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type/tuple.hpp> #include <sprout/type/tuple.hpp>
#include <sprout/type/iterator.hpp> #include <sprout/type/iterator.hpp>
#include <sprout/type/iterator/index_iterator.hpp> #include <sprout/type/iterator/index_iterator.hpp>
#include <sprout/type/rebind_types.hpp> #include <sprout/type/rebind_types.hpp>
#include <sprout/type_traits/integral_constant.hpp> #include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout { namespace sprout {
namespace types { namespace types {
@ -48,16 +50,41 @@ namespace sprout {
}; };
namespace detail { namespace detail {
template<std::size_t I, typename T> template<typename T>
struct tuple_element_impl; struct tuple_head;
template<typename Head, typename... Tail> template<typename Head, typename... Tail>
struct tuple_element_impl<0, sprout::types::type_tuple<Head, Tail...> > { struct tuple_head<sprout::types::type_tuple<Head, Tail...> >
public: : public sprout::identity<Head>
typedef Head type; {};
};
template<std::size_t I, typename Head, typename... Tail> template<std::size_t I, std::size_t N, typename T, typename Enable = void>
struct tuple_element_impl<I, sprout::types::type_tuple<Head, Tail...> > struct tuple_skip;
: public sprout::types::detail::tuple_element_impl<I - 1, sprout::types::type_tuple<Tail...> > template<std::size_t I, std::size_t N, typename Head, typename... Tail>
struct tuple_skip<
I, N, sprout::types::type_tuple<Head, Tail...>,
typename std::enable_if<(I == 0)>::type
>
: public sprout::identity<sprout::types::type_tuple<Head, Tail...> >
{};
template<std::size_t I, std::size_t N, typename Head, typename... Tail>
struct tuple_skip<
I, N, sprout::types::type_tuple<Head, Tail...>,
typename std::enable_if<(I != 0 && I < N / 2)>::type
>
: public sprout::types::detail::tuple_skip<
I - 1, N / 2 - 1,
sprout::types::type_tuple<Tail...>
>
{};
template<std::size_t I, std::size_t N, typename Head, typename... Tail>
struct tuple_skip<
I, N, sprout::types::type_tuple<Head, Tail...>,
typename std::enable_if<(I != 0 && I >= N / 2)>::type
>
: public sprout::types::detail::tuple_skip<
I - N / 2, N - N / 2,
typename sprout::types::detail::tuple_skip<N / 2 - 1, N / 2, sprout::types::type_tuple<Tail...> >::type
>
{}; {};
} // namespace detail } // namespace detail
} // namespace types } // namespace types
@ -84,7 +111,9 @@ namespace std {
// //
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
struct tuple_element<I, sprout::types::type_tuple<Types...> > struct tuple_element<I, sprout::types::type_tuple<Types...> >
: public sprout::types::detail::tuple_element_impl<I, sprout::types::type_tuple<Types...> > : public sprout::types::detail::tuple_head<
typename sprout::types::detail::tuple_skip<I, sizeof...(Types), sprout::types::type_tuple<Types...> >::type
>
{}; {};
#if defined(__clang__) #if defined(__clang__)
# pragma clang diagnostic pop # pragma clang diagnostic pop

View file

@ -27,6 +27,10 @@ namespace sprout {
operator value_type() const SPROUT_NOEXCEPT { operator value_type() const SPROUT_NOEXCEPT {
return std::integral_constant<T, v>::value; return std::integral_constant<T, v>::value;
} }
SPROUT_CONSTEXPR bool
operator!() const SPROUT_NOEXCEPT {
return !std::integral_constant<T, v>::value;
}
SPROUT_CONSTEXPR value_type SPROUT_CONSTEXPR value_type
operator()() const SPROUT_NOEXCEPT { operator()() const SPROUT_NOEXCEPT {
return std::integral_constant<T, v>::value; return std::integral_constant<T, v>::value;

View file

@ -11,45 +11,29 @@
#include <cstddef> #include <cstddef>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type/type_tuple.hpp>
#include <sprout/type_traits/integral_constant.hpp> #include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
namespace sprout { namespace sprout {
// //
// tppack_at // pack_element
// //
namespace detail {
template<std::size_t I, typename Head, typename... Tail>
struct tppack_at_impl_1
: public sprout::detail::tppack_at_impl_1<I - 1, Tail...>
{};
template<typename Head, typename... Tail>
struct tppack_at_impl_1<0, Head, Tail...> {
public:
typedef Head type;
};
template<std::size_t I, typename... Args>
struct tppack_at_impl
: public sprout::detail::tppack_at_impl_1<I, Args...>
{
static_assert(I < sizeof...(Args), "I < sizeof...(Args)");
};
} // namespace detail
template<std::size_t I, typename... Args> template<std::size_t I, typename... Args>
struct tppack_at struct pack_element
: public sprout::detail::tppack_at_impl<I, Args...> : public std::tuple_element<I, sprout::types::type_tuple<Args...> >
{}; {};
// //
// tppack_c_at // pack_element_c
// //
template<std::size_t I, typename T, T... Args> template<std::size_t I, typename T, T... Args>
struct tppack_c_at struct pack_element_c
: public sprout::tppack_at<I, sprout::integral_constant<T, Args>...>::type : public sprout::pack_element<I, sprout::integral_constant<T, Args>...>::type
{}; {};
// //
// fppack_at // pack_get
// //
namespace detail { namespace detail {
template< template<
@ -57,7 +41,7 @@ namespace sprout {
typename sprout::enabler_if<I == 0>::type = sprout::enabler typename sprout::enabler_if<I == 0>::type = sprout::enabler
> >
inline SPROUT_CONSTEXPR R inline SPROUT_CONSTEXPR R
fppack_at_impl(Head&& head, Tail&&...) { pack_get_impl(Head&& head, Tail&&...) {
return sprout::forward<Head>(head); return sprout::forward<Head>(head);
} }
template< template<
@ -65,16 +49,16 @@ namespace sprout {
typename sprout::enabler_if<I != 0>::type = sprout::enabler typename sprout::enabler_if<I != 0>::type = sprout::enabler
> >
inline SPROUT_CONSTEXPR R inline SPROUT_CONSTEXPR R
fppack_at_impl(Head&&, Tail&&... tail) { pack_get_impl(Head&&, Tail&&... tail) {
return sprout::detail::fppack_at_impl<I - 1, R>(sprout::forward<Tail>(tail)...); return sprout::detail::pack_get_impl<I - 1, R>(sprout::forward<Tail>(tail)...);
} }
} // namespace detail } // namespace detail
template<std::size_t I, typename... Args> template<std::size_t I, typename... Args>
inline SPROUT_CONSTEXPR typename sprout::tppack_at<I, Args&&...>::type inline SPROUT_CONSTEXPR typename sprout::pack_element<I, Args&&...>::type
fppack_at(Args&&... args) { pack_get(Args&&... args) {
return sprout::detail::fppack_at_impl< return sprout::detail::pack_get_impl<
I, I,
typename sprout::tppack_at<I, Args&&...>::type typename sprout::pack_element<I, Args&&...>::type
>(sprout::forward<Args>(args)...); >(sprout::forward<Args>(args)...);
} }
} // namespace sprout } // namespace sprout

View file

@ -14,6 +14,7 @@
#include <sprout/utility/swap.hpp> #include <sprout/utility/swap.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/utility/move.hpp> #include <sprout/utility/move.hpp>
#include <sprout/type_traits/std_type_traits.hpp>
#include <sprout/optional/in_place.hpp> #include <sprout/optional/in_place.hpp>
namespace sprout { namespace sprout {
@ -184,7 +185,7 @@ namespace sprout {
public: public:
template<typename... Args> template<typename... Args>
struct is_constructible_args struct is_constructible_args
: public std::is_constructible<T, Args&&...> : public sprout::is_constructible<T, Args&&...>
{}; {};
public: public:
static SPROUT_CONSTEXPR reference get(value_holder& t) SPROUT_NOEXCEPT { static SPROUT_CONSTEXPR reference get(value_holder& t) SPROUT_NOEXCEPT {