concepts.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___MEMORY_CONCEPTS_H
  10. #define _LIBCPP___MEMORY_CONCEPTS_H
  11. #include <__concepts/same_as.h>
  12. #include <__config>
  13. #include <__iterator/concepts.h>
  14. #include <__iterator/iterator_traits.h>
  15. #include <__iterator/readable_traits.h>
  16. #include <__ranges/access.h>
  17. #include <__ranges/concepts.h>
  18. #include <__type_traits/is_reference.h>
  19. #include <__type_traits/remove_cvref.h>
  20. #include <__type_traits/remove_reference.h> // TODO(modules): This should not be required
  21. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  22. # pragma GCC system_header
  23. #endif
  24. _LIBCPP_BEGIN_NAMESPACE_STD
  25. #if _LIBCPP_STD_VER >= 20
  26. namespace ranges {
  27. // [special.mem.concepts]
  28. // This concept ensures that uninitialized algorithms can construct an object
  29. // at the address pointed-to by the iterator, which requires an lvalue.
  30. template <class _Ip>
  31. concept __nothrow_input_iterator =
  32. input_iterator<_Ip> && is_lvalue_reference_v<iter_reference_t<_Ip>> &&
  33. same_as<remove_cvref_t<iter_reference_t<_Ip>>, iter_value_t<_Ip>>;
  34. template <class _Sp, class _Ip>
  35. concept __nothrow_sentinel_for = sentinel_for<_Sp, _Ip>;
  36. template <class _Rp>
  37. concept __nothrow_input_range =
  38. range<_Rp> && __nothrow_input_iterator<iterator_t<_Rp>> && __nothrow_sentinel_for<sentinel_t<_Rp>, iterator_t<_Rp>>;
  39. template <class _Ip>
  40. concept __nothrow_forward_iterator =
  41. __nothrow_input_iterator<_Ip> && forward_iterator<_Ip> && __nothrow_sentinel_for<_Ip, _Ip>;
  42. template <class _Rp>
  43. concept __nothrow_forward_range = __nothrow_input_range<_Rp> && __nothrow_forward_iterator<iterator_t<_Rp>>;
  44. } // namespace ranges
  45. #endif // _LIBCPP_STD_VER >= 20
  46. _LIBCPP_END_NAMESPACE_STD
  47. #endif // _LIBCPP___MEMORY_CONCEPTS_H