Split c++14 like index_sequence into support/detail.

This commit is contained in:
Kohei Takahashi
2015-06-22 21:58:54 +09:00
parent 973f2d3940
commit 2b14951660
4 changed files with 101 additions and 26 deletions

View File

@ -7,26 +7,26 @@
#if !defined(BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100)
#define BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/fusion/support/config.hpp>
#include <boost/fusion/support/detail/index_sequence.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/value_of.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <tuple>
#include <cstddef>
namespace boost { namespace fusion { namespace detail
{
template <typename First, typename Last
, bool is_empty = result_of::equal_to<First, Last>::value
>
template <typename First, typename Last,
bool is_empty = result_of::equal_to<First, Last>::value>
struct build_std_tuple;
template <typename First, typename Last>
struct build_std_tuple<First, Last, true>
{
typedef std::tuple<> type;
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
static type
call(First const&, Last const&)
@ -35,35 +35,18 @@ namespace boost { namespace fusion { namespace detail
}
};
template <int ...> struct indexed_tuple { };
template <int, typename = indexed_tuple<>>
struct make_indexed_tuple;
template <int Head, int ...Tail>
struct make_indexed_tuple<Head, indexed_tuple<Tail...>>
{
typedef typename
boost::mpl::eval_if_c<
(Head == 0),
boost::mpl::identity<indexed_tuple<Tail...>>,
make_indexed_tuple<Head - 1, indexed_tuple<Head - 1, Tail...>>
>::type
type;
};
template <typename T, typename Rest>
struct push_front_std_tuple;
template <typename T, typename ...Rest>
struct push_front_std_tuple<T, std::tuple<Rest...>>
struct push_front_std_tuple<T, std::tuple<Rest...> >
{
typedef std::tuple<T, Rest...> type;
template <int ...I>
template <std::size_t ...I>
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
static type
indexed_call(T const& first, std::tuple<Rest...> const& rest, indexed_tuple<I...>)
indexed_call(T const& first, std::tuple<Rest...> const& rest, index_sequence<I...>)
{
return type(first, std::get<I>(rest)...);
}
@ -72,7 +55,7 @@ namespace boost { namespace fusion { namespace detail
static type
call(T const& first, std::tuple<Rest...> const& rest)
{
typedef typename make_indexed_tuple<sizeof...(Rest)>::type gen;
typedef typename make_index_sequence<sizeof...(Rest)>::type gen;
return indexed_call(first, rest, gen());
}
};

View File

@ -0,0 +1,59 @@
/*=============================================================================
Copyright (c) 2015 Agustin K-ballo Berge
Copyright (c) 2015 Kohei Takahashi
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 BOOST_FUSION_SUPPORT_DETAIL_INDEX_SEQUENCE_06232015_1038
#define BOOST_FUSION_SUPPORT_DETAIL_INDEX_SEQUENCE_06232015_1038
#include <boost/fusion/support/config.hpp>
#include <cstddef>
namespace boost { namespace fusion { namespace detail
{
template <std::size_t ...Ints>
struct index_sequence
{
typedef std::size_t value_type;
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
static std::size_t size() BOOST_NOEXCEPT
{ return sizeof...(Ints); }
// non standard extension
typedef index_sequence type;
};
template <typename Left, typename Right>
struct _make_index_sequence_join;
template <std::size_t... Left, std::size_t... Right>
struct _make_index_sequence_join<
index_sequence<Left...>, index_sequence<Right...>
> : index_sequence<Left..., (sizeof...(Left) + Right)...>
{};
template <std::size_t N>
struct make_index_sequence
: _make_index_sequence_join<
typename make_index_sequence<N / 2>::type
, typename make_index_sequence<N - N / 2>::type
>
{};
template <>
struct make_index_sequence<1>
: index_sequence<0>
{};
template <>
struct make_index_sequence<0>
: index_sequence<>
{};
}}}
#endif

View File

@ -188,6 +188,7 @@ project
[ compile support/pair_set.cpp : : : : ]
[ compile support/pair_vector.cpp : : : : ]
[ compile support/pair_nest.cpp : : : : ]
[ compile support/index_sequence.cpp : : : : ]
# [ compile-fail xxx.cpp : : : : ]

View File

@ -0,0 +1,32 @@
/*=============================================================================
Copyright (c) 2015 Kohei Takahashi
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)
==============================================================================*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/fusion/support/detail/index_sequence.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_same.hpp>
using namespace boost::fusion;
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<0>::type, detail::index_sequence<> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<1>::type, detail::index_sequence<0> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<2>::type, detail::index_sequence<0, 1> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<3>::type, detail::index_sequence<0, 1, 2> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<4>::type, detail::index_sequence<0, 1, 2, 3> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<5>::type, detail::index_sequence<0, 1, 2, 3, 4> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<6>::type, detail::index_sequence<0, 1, 2, 3, 4, 5> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<7>::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<8>::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6, 7> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<15>::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<16>::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15> >));
BOOST_MPL_ASSERT((boost::is_same<detail::make_index_sequence<17>::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16> >));
#endif