From 2b14951660fda17bc2b98fe2e78a90adda31bc97 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 22 Jun 2015 21:58:54 +0900 Subject: [PATCH] Split c++14 like index_sequence into support/detail. --- .../std_tuple/detail/build_std_tuple.hpp | 35 +++-------- .../fusion/support/detail/index_sequence.hpp | 59 +++++++++++++++++++ test/Jamfile | 1 + test/support/index_sequence.cpp | 32 ++++++++++ 4 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 include/boost/fusion/support/detail/index_sequence.hpp create mode 100644 test/support/index_sequence.cpp diff --git a/include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp b/include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp index 41e0d434..b60dc76f 100644 --- a/include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp +++ b/include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp @@ -7,26 +7,26 @@ #if !defined(BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100) #define BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100 -#include -#include #include +#include #include #include #include #include #include +#include namespace boost { namespace fusion { namespace detail { - template ::value - > + template ::value> struct build_std_tuple; template struct build_std_tuple { 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 struct indexed_tuple { }; - - template > - struct make_indexed_tuple; - - template - struct make_indexed_tuple> - { - typedef typename - boost::mpl::eval_if_c< - (Head == 0), - boost::mpl::identity>, - make_indexed_tuple> - >::type - type; - }; - template struct push_front_std_tuple; template - struct push_front_std_tuple> + struct push_front_std_tuple > { typedef std::tuple type; - template + template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED static type - indexed_call(T const& first, std::tuple const& rest, indexed_tuple) + indexed_call(T const& first, std::tuple const& rest, index_sequence) { return type(first, std::get(rest)...); } @@ -72,7 +55,7 @@ namespace boost { namespace fusion { namespace detail static type call(T const& first, std::tuple const& rest) { - typedef typename make_indexed_tuple::type gen; + typedef typename make_index_sequence::type gen; return indexed_call(first, rest, gen()); } }; diff --git a/include/boost/fusion/support/detail/index_sequence.hpp b/include/boost/fusion/support/detail/index_sequence.hpp new file mode 100644 index 00000000..1b596e72 --- /dev/null +++ b/include/boost/fusion/support/detail/index_sequence.hpp @@ -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 +#include + +namespace boost { namespace fusion { namespace detail +{ + template + 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 + struct _make_index_sequence_join; + + template + struct _make_index_sequence_join< + index_sequence, index_sequence + > : index_sequence + {}; + + template + struct make_index_sequence + : _make_index_sequence_join< + typename make_index_sequence::type + , typename make_index_sequence::type + > + {}; + + template <> + struct make_index_sequence<1> + : index_sequence<0> + {}; + + template <> + struct make_index_sequence<0> + : index_sequence<> + {}; +}}} + +#endif + diff --git a/test/Jamfile b/test/Jamfile index a21303eb..87b4bf51 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 : : : : ] diff --git a/test/support/index_sequence.cpp b/test/support/index_sequence.cpp new file mode 100644 index 00000000..f155a8c7 --- /dev/null +++ b/test/support/index_sequence.cpp @@ -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 + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + +#include +#include +#include + +using namespace boost::fusion; + +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0, 1> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0, 1, 2> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0, 1, 2, 3> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0, 1, 2, 3, 4> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0, 1, 2, 3, 4, 5> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6> >)); +BOOST_MPL_ASSERT((boost::is_same::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6, 7> >)); + +BOOST_MPL_ASSERT((boost::is_same::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::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::type, detail::index_sequence<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16> >)); + +#endif +