xref: /freebsd-src/contrib/llvm-project/libcxx/include/__iterator/projected.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1fe6060f1SDimitry Andric // -*- C++ -*-
2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
3fe6060f1SDimitry Andric //
4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7fe6060f1SDimitry Andric //
8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
9bdd1243dSDimitry Andric 
10fe6060f1SDimitry Andric #ifndef _LIBCPP___ITERATOR_PROJECTED_H
11fe6060f1SDimitry Andric #define _LIBCPP___ITERATOR_PROJECTED_H
12fe6060f1SDimitry Andric 
13fe6060f1SDimitry Andric #include <__config>
14fe6060f1SDimitry Andric #include <__iterator/concepts.h>
15*5f757f3fSDimitry Andric #include <__iterator/incrementable_traits.h> // iter_difference_t
16bdd1243dSDimitry Andric #include <__type_traits/remove_cvref.h>
17fe6060f1SDimitry Andric 
18fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19fe6060f1SDimitry Andric #  pragma GCC system_header
20fe6060f1SDimitry Andric #endif
21fe6060f1SDimitry Andric 
22fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
23fe6060f1SDimitry Andric 
2406c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
25fe6060f1SDimitry Andric 
26*5f757f3fSDimitry Andric template <class _It, class _Proj>
27*5f757f3fSDimitry Andric struct __projected_impl {
28*5f757f3fSDimitry Andric   struct __type {
29fe6060f1SDimitry Andric     using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
30fe6060f1SDimitry Andric     indirect_result_t<_Proj&, _It> operator*() const; // not defined
31fe6060f1SDimitry Andric   };
32*5f757f3fSDimitry Andric };
33fe6060f1SDimitry Andric 
34fe6060f1SDimitry Andric template <weakly_incrementable _It, class _Proj>
35*5f757f3fSDimitry Andric struct __projected_impl<_It, _Proj> {
36*5f757f3fSDimitry Andric   struct __type {
37*5f757f3fSDimitry Andric     using value_type      = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
38fe6060f1SDimitry Andric     using difference_type = iter_difference_t<_It>;
39*5f757f3fSDimitry Andric     indirect_result_t<_Proj&, _It> operator*() const; // not defined
40fe6060f1SDimitry Andric   };
41*5f757f3fSDimitry Andric };
42*5f757f3fSDimitry Andric 
43*5f757f3fSDimitry Andric // Note that we implement std::projected in a way that satisfies P2538R1 even in standard
44*5f757f3fSDimitry Andric // modes before C++26 to avoid breaking the ABI between standard modes (even though ABI
45*5f757f3fSDimitry Andric // breaks with std::projected are expected to have essentially no impact).
46*5f757f3fSDimitry Andric template <indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
47*5f757f3fSDimitry Andric using projected = typename __projected_impl<_It, _Proj>::__type;
48fe6060f1SDimitry Andric 
4906c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20
50fe6060f1SDimitry Andric 
51fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
52fe6060f1SDimitry Andric 
53fe6060f1SDimitry Andric #endif // _LIBCPP___ITERATOR_PROJECTED_H
54