iterator_traits.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // __ _____ _____ _____
  2. // __| | __| | | | JSON for Modern C++
  3. // | | |__ | | | | | | version 3.11.3
  4. // |_____|_____|_____|_|___| https://github.com/nlohmann/json
  5. //
  6. // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
  7. // SPDX-License-Identifier: MIT
  8. #pragma once
  9. #include <iterator> // random_access_iterator_tag
  10. #include <nlohmann/detail/abi_macros.hpp>
  11. #include <nlohmann/detail/meta/void_t.hpp>
  12. #include <nlohmann/detail/meta/cpp_future.hpp>
  13. NLOHMANN_JSON_NAMESPACE_BEGIN
  14. namespace detail
  15. {
  16. template<typename It, typename = void>
  17. struct iterator_types {};
  18. template<typename It>
  19. struct iterator_types <
  20. It,
  21. void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
  22. typename It::reference, typename It::iterator_category >>
  23. {
  24. using difference_type = typename It::difference_type;
  25. using value_type = typename It::value_type;
  26. using pointer = typename It::pointer;
  27. using reference = typename It::reference;
  28. using iterator_category = typename It::iterator_category;
  29. };
  30. // This is required as some compilers implement std::iterator_traits in a way that
  31. // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341.
  32. template<typename T, typename = void>
  33. struct iterator_traits
  34. {
  35. };
  36. template<typename T>
  37. struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
  38. : iterator_types<T>
  39. {
  40. };
  41. template<typename T>
  42. struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
  43. {
  44. using iterator_category = std::random_access_iterator_tag;
  45. using value_type = T;
  46. using difference_type = ptrdiff_t;
  47. using pointer = T*;
  48. using reference = T&;
  49. };
  50. } // namespace detail
  51. NLOHMANN_JSON_NAMESPACE_END