make_index_sequence.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright Barrett Adair 2016-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. */
  6. #ifndef BOOST_CLBL_TRTS_DETAIL_POLYFILLS_MAKE_INDEX_SEQUENCE_HPP
  7. #define BOOST_CLBL_TRTS_DETAIL_POLYFILLS_MAKE_INDEX_SEQUENCE_HPP
  8. #undef BOOST_CLBL_TRTS_IX_SEQ
  9. #define BOOST_CLBL_TRTS_IX_SEQ(...) \
  10. ::boost::callable_traits::detail::index_sequence<__VA_ARGS__>
  11. #undef BOOST_CLBL_TRTS_MAKE_IX_SEQ
  12. #define BOOST_CLBL_TRTS_MAKE_IX_SEQ(...) \
  13. ::boost::callable_traits::detail::make_index_sequence<__VA_ARGS__>
  14. namespace boost { namespace callable_traits { namespace detail {
  15. template<std::size_t...>
  16. struct index_sequence { using type = index_sequence; };
  17. template<typename, typename>
  18. struct concat;
  19. template<std::size_t... I1, std::size_t... I2>
  20. struct concat<index_sequence<I1...>, index_sequence<I2...>>
  21. : index_sequence<I1..., (sizeof...(I1)+I2)...> {};
  22. template<std::size_t N>
  23. struct make_index_sequence_t;
  24. template<std::size_t N>
  25. struct make_index_sequence_t : concat<
  26. typename make_index_sequence_t<N/2>::type,
  27. typename make_index_sequence_t<N - N/2>::type >::type {};
  28. template<>
  29. struct make_index_sequence_t<0> : index_sequence<> {};
  30. template<>
  31. struct make_index_sequence_t<1> : index_sequence<0> {};
  32. template<std::size_t... I>
  33. using make_index_sequence = typename make_index_sequence_t<I...>::type;
  34. }}} // namespace boost::callable_traits::detail
  35. #endif // #ifndef BOOST_CLBL_TRTS_DETAIL_POLYFILLS_MAKE_INDEX_SEQUENCE_HPP