Horizon
Loading...
Searching...
No Matches
result_types.hpp
1// Range v3 library
2//
3// Copyright Eric Niebler 2013-present
4//
5// Use, modification and distribution is subject to the
6// Boost Software License, Version 1.0. (See accompanying
7// file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10// Project home: https://github.com/ericniebler/range-v3
11
12#ifndef RANGES_V3_ALGORITHM_RESULT_TYPES_HPP
13#define RANGES_V3_ALGORITHM_RESULT_TYPES_HPP
14
15#include <concepts/concepts.hpp>
16
18
19#include <range/v3/detail/prologue.hpp>
20
21namespace ranges
22{
24 namespace detail
25 {
26 // Extensions: the dangling story actually works, and result structs
27 // are conditionally equality_comparable
28#define RANGES_ALGO_RESULT_AUX_2(C, T1, M1, T2, M2) \
29 template(typename X, typename Y)( \
30 requires convertible_to<T1 const &, X> AND convertible_to<T2 const &, Y>) \
31 operator C<X, Y>() const & \
32 { \
33 return {M1, M2}; \
34 } \
35 template(typename X, typename Y)( \
36 requires convertible_to<T1, X> AND convertible_to<T2, Y>) \
37 operator C<X, Y>() && \
38 { \
39 return {static_cast<T1 &&>(M1), static_cast<T2 &&>(M2)}; \
40 } \
41 CPP_broken_friend_member \
42 friend constexpr auto operator==(C<T1, T2> const & x, C<T1, T2> const & y) \
43 -> CPP_broken_friend_ret(bool)( \
44 requires equality_comparable<T1> && equality_comparable<T2>) \
45 { \
46 return x.M1 == y.M1 && x.M2 == y.M2; \
47 } \
48 CPP_broken_friend_member \
49 friend constexpr auto operator!=(C<T1, T2> const & x, C<T1, T2> const & y) \
50 -> CPP_broken_friend_ret(bool)( \
51 requires equality_comparable<T1> && equality_comparable<T2>) \
52 { \
53 return !(x == y); \
54 } \
55
56
57#define RANGES_ALGO_RESULT_AUX_3(C, T1, M1, T2, M2, T3, M3) \
58 template(typename X, typename Y, typename Z)( \
59 requires convertible_to<T1 const &, X> AND convertible_to<T2 const &, Y> AND \
60 convertible_to<T3 const &, Z>) \
61 operator C<X, Y, Z>() const & \
62 { \
63 return {M1, M2, M3}; \
64 } \
65 template(typename X, typename Y, typename Z)( \
66 requires convertible_to<T1, X> AND convertible_to<T2, Y> AND \
67 convertible_to<T3, Z>) \
68 operator C<X, Y, Z>() && \
69 { \
70 return {static_cast<T1 &&>(M1), static_cast<T2 &&>(M2), static_cast<T3 &&>(M3)}; \
71 } \
72 CPP_broken_friend_member \
73 friend constexpr auto operator==(C<T1, T2, T3> const & x, C<T1, T2, T3> const & y) \
74 -> CPP_broken_friend_ret(bool)( \
75 requires equality_comparable<T1> && equality_comparable<T2> && \
76 equality_comparable<T3>) \
77 { \
78 return x.M1 == y.M1 && x.M2 == y.M2 && x.M3 == y.M3; \
79 } \
80 CPP_broken_friend_member \
81 friend constexpr auto operator!=(C<T1, T2, T3> const & x, C<T1, T2, T3> const & y) \
82 -> CPP_broken_friend_ret(bool)( \
83 requires equality_comparable<T1> && equality_comparable<T2> && \
84 equality_comparable<T3>) \
85 { \
86 return !(x == y); \
87 } \
88
89
90 template<typename I, typename O>
91 struct in_out_result
92 {
93 I in;
94 O out;
95
96 RANGES_ALGO_RESULT_AUX_2(in_out_result, I, in, O, out)
97 };
98
99 template<typename I1, typename O>
100 struct in1_out_result
101 {
102 I1 in1;
103 O out;
104
105 RANGES_ALGO_RESULT_AUX_2(in1_out_result, I1, in1, O, out)
106 };
107
108 template<typename I1, typename I2>
109 struct in1_in2_result
110 {
111 I1 in1;
112 I2 in2;
113
114 RANGES_ALGO_RESULT_AUX_2(in1_in2_result, I1, in1, I2, in2)
115 };
116
117 template<typename I, typename Fun>
118 struct in_fun_result
119 {
120 I in;
121 Fun fun;
122
123 RANGES_ALGO_RESULT_AUX_2(in_fun_result, I, in, Fun, fun)
124 };
125
126 template<typename O, typename Fun>
127 struct out_fun_result
128 {
129 O out;
130 Fun fun;
131
132 RANGES_ALGO_RESULT_AUX_2(out_fun_result, O, out, Fun, fun)
133 };
134
135 template<typename T, typename U>
136 struct min_max_result
137 {
138 T min;
139 U max;
140
141 RANGES_ALGO_RESULT_AUX_2(min_max_result, T, min, U, max)
142 };
143
144 template<typename I1, typename I2, typename O>
145 struct in1_in2_out_result
146 {
147 I1 in1;
148 I2 in2;
149 O out;
150
151 RANGES_ALGO_RESULT_AUX_3(in1_in2_out_result, I1, in1, I2, in2, O, out)
152 };
153
154 template<typename I, typename O1, typename O2>
155 struct in_out1_out2_result
156 {
157 I in;
158 O1 out1;
159 O2 out2;
160
161 RANGES_ALGO_RESULT_AUX_3(in_out1_out2_result, I, in, O1, out1, O2, out2)
162 };
163 } // namespace detail
165} // namespace ranges
166
167#include <range/v3/detail/epilogue.hpp>
168
169#endif
not_< empty< find< L, T > > > in
A Boolean integral constant wrapper around true if there is at least one occurrence of T in L.
Definition meta.hpp:3081