1 /*============================================================================= 2 Copyright (c) 2015 Agustin K-ballo Berge 3 Copyright (c) 2015 Kohei Takahashi 4 5 Distributed under the Boost Software License, Version 1.0. (See accompanying 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 ==============================================================================*/ 8 9 #ifndef BOOST_FUSION_SUPPORT_DETAIL_INDEX_SEQUENCE_06232015_1038 10 #define BOOST_FUSION_SUPPORT_DETAIL_INDEX_SEQUENCE_06232015_1038 11 12 #include <boost/fusion/support/config.hpp> 13 #include <cstddef> 14 15 // GCC5 has O(logN) implementation, see https://gcc.gnu.org/PR66059 . 16 #if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) \ 17 || (defined(BOOST_LIBSTDCXX_VERSION) \ 18 && BOOST_LIBSTDCXX_VERSION >= 500000 && __cplusplus >= 201402) 19 #include <utility> 20 #define BOOST_FUSION_STDLIB_HAS_INTEGER_SEQUENCE 21 #endif 22 23 namespace boost { namespace fusion { namespace detail 24 { 25 #ifdef BOOST_FUSION_STDLIB_HAS_INTEGER_SEQUENCE 26 // Use aliasing templates without checking availability, the compiler should work. 27 template <std::size_t ...Ints> 28 using index_sequence = std::index_sequence<Ints...>; 29 30 template <std::size_t N> 31 struct make_index_sequence 32 { 33 using type = std::make_index_sequence<N>; 34 }; 35 #else 36 template <std::size_t ...Ints> 37 struct index_sequence 38 { 39 typedef std::size_t value_type; 40 41 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 42 static std::size_t size() BOOST_NOEXCEPT 43 { return sizeof...(Ints); } 44 45 // non standard extension 46 typedef index_sequence type; 47 }; 48 49 template <typename Left, typename Right> 50 struct _make_index_sequence_join; 51 52 template <std::size_t... Left, std::size_t... Right> 53 struct _make_index_sequence_join< 54 index_sequence<Left...>, index_sequence<Right...> 55 > : index_sequence<Left..., (sizeof...(Left) + Right)...> 56 {}; 57 58 template <std::size_t N> 59 struct make_index_sequence 60 : _make_index_sequence_join< 61 typename make_index_sequence<N / 2>::type 62 , typename make_index_sequence<N - N / 2>::type 63 > 64 {}; 65 66 template <> 67 struct make_index_sequence<1> 68 : index_sequence<0> 69 {}; 70 71 template <> 72 struct make_index_sequence<0> 73 : index_sequence<> 74 {}; 75 #endif 76 }}} 77 78 #endif 79 80