projected.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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___ITERATOR_PROJECTED_H
  10. #define _LIBCPP___ITERATOR_PROJECTED_H
  11. #include <__config>
  12. #include <__iterator/concepts.h>
  13. #include <__iterator/incrementable_traits.h> // iter_difference_t
  14. #include <__type_traits/remove_cvref.h>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. #if _LIBCPP_STD_VER >= 20
  20. template <class _It, class _Proj>
  21. struct __projected_impl {
  22. struct __type {
  23. using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
  24. indirect_result_t<_Proj&, _It> operator*() const; // not defined
  25. };
  26. };
  27. template <weakly_incrementable _It, class _Proj>
  28. struct __projected_impl<_It, _Proj> {
  29. struct __type {
  30. using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
  31. using difference_type = iter_difference_t<_It>;
  32. indirect_result_t<_Proj&, _It> operator*() const; // not defined
  33. };
  34. };
  35. // Note that we implement std::projected in a way that satisfies P2538R1 even in standard
  36. // modes before C++26 to avoid breaking the ABI between standard modes (even though ABI
  37. // breaks with std::projected are expected to have essentially no impact).
  38. template <indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
  39. using projected = typename __projected_impl<_It, _Proj>::__type;
  40. #endif // _LIBCPP_STD_VER >= 20
  41. _LIBCPP_END_NAMESPACE_STD
  42. #endif // _LIBCPP___ITERATOR_PROJECTED_H