traits.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <type_traits>
  5. #include <iterator/forwards.h>
  6. #include <iterator/detail/macro.h>
  7. // Section: Non-Dependant Typedef Helpers
  8. namespace iterator::detail {
  9. template <typename Iter>
  10. using category_t = typename std::iterator_traits<Iter>::iterator_category;
  11. template <typename C> using iter = decltype(std::begin(std::declval<C>()));
  12. }
  13. namespace iterator::detail {
  14. // Type Helper for identifying container-like objects
  15. template <typename C, typename = void> struct is_container : std::false_type {};
  16. template <typename C>
  17. struct is_container<C, std::void_t<iter<C>>> : std::true_type {};
  18. template <typename It, typename = void>
  19. struct sentinel_type {
  20. using type = void;
  21. };
  22. template <typename It>
  23. struct sentinel_type<It, std::void_t<typename It::sentinel_type>> {
  24. using type = typename It::sentinel_type;
  25. };
  26. }
  27. namespace iterator::detail {
  28. template <typename C> constexpr bool is_container_v = is_container<C>{};
  29. template <typename Iter>
  30. constexpr bool is_rvalue_iterator_v = !std::is_reference_v<DEREF_TYPE(Iter)>;
  31. template <typename It>
  32. constexpr bool has_sentinel_type_v = !std::is_void_v<typename sentinel_type<It>::type>;
  33. template <typename It, typename S>
  34. constexpr bool is_sentinel_v = std::is_same_v<typename sentinel_type<It>::type, S>;
  35. }
  36. #include <iterator/detail/undef.h>