utility.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // detail/utility.hpp
  3. // ~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_UTILITY_HPP
  11. #define BOOST_ASIO_DETAIL_UTILITY_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <utility>
  17. namespace boost {
  18. namespace asio {
  19. namespace detail {
  20. #if defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE)
  21. using std::index_sequence;
  22. using std::index_sequence_for;
  23. using std::make_index_sequence;
  24. #else // defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE)
  25. template <std::size_t...>
  26. struct index_sequence
  27. {
  28. };
  29. template <typename T, typename U>
  30. struct join_index_sequences;
  31. template <std::size_t... I, std::size_t... J>
  32. struct join_index_sequences<index_sequence<I...>, index_sequence<J...>>
  33. {
  34. using type = index_sequence<I..., J...>;
  35. };
  36. template <std::size_t First, std::size_t Last>
  37. struct index_pack :
  38. join_index_sequences<
  39. typename index_pack<First, First + (Last - First + 1) / 2 - 1>::type,
  40. typename index_pack<First + (Last - First + 1) / 2, Last>::type
  41. >
  42. {
  43. };
  44. template <std::size_t N>
  45. struct index_pack<N, N>
  46. {
  47. using type = index_sequence<N>;
  48. };
  49. template <std::size_t Begin, std::size_t End>
  50. struct index_range : index_pack<Begin, End - 1>
  51. {
  52. };
  53. template <std::size_t N>
  54. struct index_range<N, N>
  55. {
  56. using type = index_sequence<>;
  57. };
  58. template <typename... T>
  59. using index_sequence_for = typename index_range<0, sizeof...(T)>::type;
  60. template <std::size_t N>
  61. using make_index_sequence = typename index_range<0, N>::type;
  62. #endif // defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE)
  63. } // namespace detail
  64. } // namespace asio
  65. } // namespace boost
  66. #endif // BOOST_ASIO_DETAIL_UTILITY_HPP