index_sequence.hpp 2.3 KB

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