utility.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // detail/utility.hpp
  3. // ~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_DETAIL_UTILITY_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include <utility>
  17. namespace asio {
  18. namespace detail {
  19. #if defined(ASIO_HAS_STD_INDEX_SEQUENCE)
  20. using std::index_sequence;
  21. using std::index_sequence_for;
  22. using std::make_index_sequence;
  23. #else // defined(ASIO_HAS_STD_INDEX_SEQUENCE)
  24. template <std::size_t...>
  25. struct index_sequence
  26. {
  27. };
  28. template <typename T, typename U>
  29. struct join_index_sequences;
  30. template <std::size_t... I, std::size_t... J>
  31. struct join_index_sequences<index_sequence<I...>, index_sequence<J...>>
  32. {
  33. using type = index_sequence<I..., J...>;
  34. };
  35. template <std::size_t First, std::size_t Last>
  36. struct index_pack :
  37. join_index_sequences<
  38. typename index_pack<First, First + (Last - First + 1) / 2 - 1>::type,
  39. typename index_pack<First + (Last - First + 1) / 2, Last>::type
  40. >
  41. {
  42. };
  43. template <std::size_t N>
  44. struct index_pack<N, N>
  45. {
  46. using type = index_sequence<N>;
  47. };
  48. template <std::size_t Begin, std::size_t End>
  49. struct index_range : index_pack<Begin, End - 1>
  50. {
  51. };
  52. template <std::size_t N>
  53. struct index_range<N, N>
  54. {
  55. using type = index_sequence<>;
  56. };
  57. template <typename... T>
  58. using index_sequence_for = typename index_range<0, sizeof...(T)>::type;
  59. template <std::size_t N>
  60. using make_index_sequence = typename index_range<0, N>::type;
  61. #endif // defined(ASIO_HAS_STD_INDEX_SEQUENCE)
  62. } // namespace detail
  63. } // namespace asio
  64. #endif // ASIO_DETAIL_UTILITY_HPP