cpp_future.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <cstddef> // size_t
  3. #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
  4. #include <nlohmann/detail/boolean_operators.hpp>
  5. namespace nlohmann
  6. {
  7. namespace detail
  8. {
  9. // alias templates to reduce boilerplate
  10. template<bool B, typename T = void>
  11. using enable_if_t = typename std::enable_if<B, T>::type;
  12. template<typename T>
  13. using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
  14. // implementation of C++14 index_sequence and affiliates
  15. // source: https://stackoverflow.com/a/32223343
  16. template<std::size_t... Ints>
  17. struct index_sequence
  18. {
  19. using type = index_sequence;
  20. using value_type = std::size_t;
  21. static constexpr std::size_t size() noexcept
  22. {
  23. return sizeof...(Ints);
  24. }
  25. };
  26. template<class Sequence1, class Sequence2>
  27. struct merge_and_renumber;
  28. template<std::size_t... I1, std::size_t... I2>
  29. struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
  30. : index_sequence < I1..., (sizeof...(I1) + I2)... > {};
  31. template<std::size_t N>
  32. struct make_index_sequence
  33. : merge_and_renumber < typename make_index_sequence < N / 2 >::type,
  34. typename make_index_sequence < N - N / 2 >::type > {};
  35. template<> struct make_index_sequence<0> : index_sequence<> {};
  36. template<> struct make_index_sequence<1> : index_sequence<0> {};
  37. template<typename... Ts>
  38. using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
  39. // dispatch utility (taken from ranges-v3)
  40. template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
  41. template<> struct priority_tag<0> {};
  42. // taken from ranges-v3
  43. template<typename T>
  44. struct static_const
  45. {
  46. static constexpr T value{};
  47. };
  48. template<typename T>
  49. constexpr T static_const<T>::value;
  50. } // namespace detail
  51. } // namespace nlohmann