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