index_sequence.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright Oliver Kowalke 2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_CONTEXT_DETAIL_INDEX_SEQUENCE_H
  6. #define BOOST_CONTEXT_DETAIL_INDEX_SEQUENCE_H
  7. #include <cstddef>
  8. #include <boost/config.hpp>
  9. #include <boost/context/detail/config.hpp>
  10. #ifdef BOOST_HAS_ABI_HEADERS
  11. # include BOOST_ABI_PREFIX
  12. #endif
  13. namespace boost {
  14. namespace context {
  15. namespace detail {
  16. #if ! defined(BOOST_CONTEXT_NO_CXX14_INTEGER_SEQUENCE)
  17. template< std::size_t ... I >
  18. using index_sequence = std::index_sequence< I ... >;
  19. template< std::size_t I >
  20. using make_index_sequence = std::make_index_sequence< I >;
  21. template< typename ... T >
  22. using index_sequence_for = std::index_sequence_for< T ... >;
  23. #else
  24. //http://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence
  25. template< std::size_t ... I >
  26. struct index_sequence {
  27. using type = index_sequence;
  28. using value_type = std::size_t;
  29. static constexpr std::size_t size() {
  30. return sizeof ... (I);
  31. }
  32. };
  33. template< typename Seq1, typename Seq2 >
  34. struct concat_sequence;
  35. template< std::size_t ... I1, std::size_t ... I2 >
  36. struct concat_sequence< index_sequence< I1 ... >, index_sequence< I2 ... > > : public index_sequence< I1 ..., (sizeof ... (I1)+I2) ... > {
  37. };
  38. template< std::size_t I >
  39. struct make_index_sequence : public concat_sequence< typename make_index_sequence< I/2 >::type,
  40. typename make_index_sequence< I-I/2 >::type > {
  41. };
  42. template<>
  43. struct make_index_sequence< 0 > : public index_sequence<> {
  44. };
  45. template<>
  46. struct make_index_sequence< 1 > : public index_sequence< 0 > {
  47. };
  48. template< typename ... T >
  49. using index_sequence_for = make_index_sequence< sizeof ... (T) >;
  50. #endif
  51. }}}
  52. #ifdef BOOST_HAS_ABI_HEADERS
  53. #include BOOST_ABI_SUFFIX
  54. #endif
  55. #endif // BOOST_CONTEXT_DETAIL_INDEX_SEQUENCE_H