master
 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 __primary_template _LIBCPP_NODEBUG     = __type;
30    using __projected_iterator _LIBCPP_NODEBUG   = _It;
31    using __projected_projection _LIBCPP_NODEBUG = _Proj;
32
33    using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
34    indirect_result_t<_Proj&, _It> operator*() const; // not defined
35  };
36};
37
38template <weakly_incrementable _It, class _Proj>
39struct __projected_impl<_It, _Proj> {
40  struct __type {
41    using __primary_template _LIBCPP_NODEBUG     = __type;
42    using __projected_iterator _LIBCPP_NODEBUG   = _It;
43    using __projected_projection _LIBCPP_NODEBUG = _Proj;
44
45    using value_type      = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
46    using difference_type = iter_difference_t<_It>;
47    indirect_result_t<_Proj&, _It> operator*() const; // not defined
48  };
49};
50
51// Note that we implement std::projected in a way that satisfies P2538R1 even in standard
52// modes before C++26 to avoid breaking the ABI between standard modes (even though ABI
53// breaks with std::projected are expected to have essentially no impact).
54template <indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
55using projected = typename __projected_impl<_It, _Proj>::__type;
56
57#endif // _LIBCPP_STD_VER >= 20
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP___ITERATOR_PROJECTED_H