You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.0KB

  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #ifndef RANGES_V3_RANGE_DANGLING_HPP
  14. #define RANGES_V3_RANGE_DANGLING_HPP
  15. #include <utility>
  16. #include <concepts/concepts.hpp>
  17. #include <range/v3/range_fwd.hpp>
  18. #include <range/v3/range/concepts.hpp>
  19. #include <range/v3/utility/static_const.hpp>
  20. namespace ranges
  21. {
  22. /// \ingroup group-range
  23. /// A placeholder for an iterator or a sentinel into a range that may
  24. /// no longer be valid.
  25. struct dangling
  26. {
  27. dangling() = default;
  28. /// Implicit converting constructor; ignores argument
  29. template<typename T>
  30. constexpr CPP_ctor(dangling)(T &&)( //
  31. requires not_same_as_<T, dangling>)
  32. {}
  33. };
  34. /// \cond
  35. namespace detail
  36. {
  37. CPP_template(class R, class U)( //
  38. requires range<R>) //
  39. using maybe_dangling_ = if_then_t<forwarding_range_<R>, U, dangling>;
  40. }
  41. /// \endcond
  42. template<typename Rng>
  43. using safe_iterator_t = detail::maybe_dangling_<Rng, iterator_t<Rng>>;
  44. /// \cond
  45. struct _sanitize_fn
  46. {
  47. template<typename T>
  48. constexpr T && operator()(T && t) const noexcept
  49. {
  50. return static_cast<T &&>(t);
  51. }
  52. };
  53. using sanitize_fn RANGES_DEPRECATED(
  54. "The sanitize function is unneeded and deprecated.") = _sanitize_fn;
  55. namespace
  56. {
  57. RANGES_DEPRECATED("The sanitize function is unneeded and deprecated.")
  58. constexpr auto & sanitize = static_const<_sanitize_fn>::value;
  59. } // namespace
  60. /// \endcond
  61. namespace cpp20
  62. {
  63. using ranges::dangling;
  64. using ranges::safe_iterator_t;
  65. } // namespace cpp20
  66. } // namespace ranges
  67. #endif