@@ -10,9 +10,8 @@ template <class T>
1010class optional <T&> {
1111 public:
1212 using value_type = T;
13- using iterator =
14- std::contiguous_iterator<T,
15- optional>; // see [optionalref.iterators]
13+ using iterator = std::contiguous_iterator<T,
14+ optional>; // see [optionalref.iterators]
1615 public:
1716 // \ref{optionalref.ctor}, constructors
1817
@@ -21,13 +20,11 @@ class optional<T&> {
2120 constexpr optional (const optional& rhs) noexcept = default;
2221
2322 template <class Arg >
24- requires (std::is_constructible_v<T&, Arg> &&
25- !std::reference_constructs_from_temporary_v<T&, Arg>)
23+ requires (std::is_constructible_v<T&, Arg> && !std::reference_constructs_from_temporary_v<T&, Arg>)
2624 constexpr explicit optional (in_place_t , Arg&& arg);
2725
2826 template <class U >
29- requires (std::is_constructible_v<T&, U> &&
30- !(std::is_same_v<std::remove_cvref_t <U>, in_place_t >) &&
27+ requires (std::is_constructible_v<T&, U> && !(std::is_same_v<std::remove_cvref_t <U>, in_place_t >) &&
3128 !(std::is_same_v<std::remove_cvref_t <U>, optional>) &&
3229 !std::reference_constructs_from_temporary_v<T&, U>)
3330 constexpr explicit (!std::is_convertible_v<U, T&>)
@@ -36,8 +33,7 @@ class optional<T&> {
3633 }
3734
3835 template <class U >
39- requires (std::is_constructible_v<T&, U> &&
40- !(std::is_same_v<std::remove_cvref_t <U>, in_place_t >) &&
36+ requires (std::is_constructible_v<T&, U> && !(std::is_same_v<std::remove_cvref_t <U>, in_place_t >) &&
4137 !(std::is_same_v<std::remove_cvref_t <U>, optional>) &&
4238 std::reference_constructs_from_temporary_v<T&, U>)
4339 constexpr optional (U&& u) = delete;
@@ -47,66 +43,47 @@ class optional<T&> {
4743 // allows correct constraints by propagating the value category from the
4844 // optional to the value within the rhs.
4945 template <class U >
50- requires (std::is_constructible_v<T&, U&> &&
51- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
52- !std::is_same_v<T&, U> &&
53- !std::reference_constructs_from_temporary_v<T&, U&>)
54- constexpr explicit (!std::is_convertible_v<U&, T&>) optional(
55- optional<U>& rhs) noexcept (std::is_nothrow_constructible_v<T&, U&>);
46+ requires (std::is_constructible_v<T&, U&> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
47+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, U&>)
48+ constexpr explicit (!std::is_convertible_v<U&, T&>)
49+ optional(optional<U>& rhs) noexcept (std::is_nothrow_constructible_v<T&, U&>);
5650
5751 template <class U >
58- requires (std::is_constructible_v<T&, const U&> &&
59- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
60- !std::is_same_v<T&, U> &&
61- !std::reference_constructs_from_temporary_v<T&, const U&>)
52+ requires (std::is_constructible_v<T&, const U&> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
53+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, const U&>)
6254 constexpr explicit (!std::is_convertible_v<const U&, T&>)
63- optional(const optional<U>& rhs) noexcept (
64- std::is_nothrow_constructible_v<T&, const U&>);
55+ optional(const optional<U>& rhs) noexcept (std::is_nothrow_constructible_v<T&, const U&>);
6556
6657 template <class U >
67- requires (std::is_constructible_v<T&, U> &&
68- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
69- !std::is_same_v<T&, U> &&
70- !std::reference_constructs_from_temporary_v<T&, U>)
58+ requires (std::is_constructible_v<T&, U> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
59+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, U>)
7160 constexpr explicit (!std::is_convertible_v<U, T&>)
72- optional(optional<U>&& rhs) noexcept (
73- noexcept (std::is_nothrow_constructible_v<T&, U>));
61+ optional(optional<U>&& rhs) noexcept (noexcept (std::is_nothrow_constructible_v<T&, U>));
7462
7563 template <class U >
76- requires (std::is_constructible_v<T&, const U> &&
77- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
78- !std::is_same_v<T&, U> &&
79- !std::reference_constructs_from_temporary_v<T&, const U>)
64+ requires (std::is_constructible_v<T&, const U> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
65+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, const U>)
8066 constexpr explicit (!std::is_convertible_v<const U, T&>)
81- optional(const optional<U>&& rhs) noexcept (
82- noexcept (std::is_nothrow_constructible_v<T&, const U>));
67+ optional(const optional<U>&& rhs) noexcept (noexcept (std::is_nothrow_constructible_v<T&, const U>));
8368
8469 template <class U >
85- requires (std::is_constructible_v<T&, U&> &&
86- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
87- !std::is_same_v<T&, U> &&
88- std::reference_constructs_from_temporary_v<T&, U&>)
70+ requires (std::is_constructible_v<T&, U&> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
71+ !std::is_same_v<T&, U> && std::reference_constructs_from_temporary_v<T&, U&>)
8972 constexpr optional (optional<U>& rhs) = delete;
9073
9174 template <class U >
92- requires (std::is_constructible_v<T&, const U&> &&
93- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
94- !std::is_same_v<T&, U> &&
95- std::reference_constructs_from_temporary_v<T&, const U&>)
75+ requires (std::is_constructible_v<T&, const U&> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
76+ !std::is_same_v<T&, U> && std::reference_constructs_from_temporary_v<T&, const U&>)
9677 constexpr optional (const optional<U>& rhs) = delete;
9778
9879 template <class U >
99- requires (std::is_constructible_v<T&, U> &&
100- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
101- !std::is_same_v<T&, U> &&
102- std::reference_constructs_from_temporary_v<T&, U>)
80+ requires (std::is_constructible_v<T&, U> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
81+ !std::is_same_v<T&, U> && std::reference_constructs_from_temporary_v<T&, U>)
10382 constexpr optional (optional<U>&& rhs) = delete;
10483
10584 template <class U >
106- requires (std::is_constructible_v<T&, const U> &&
107- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
108- !std::is_same_v<T&, U> &&
109- std::reference_constructs_from_temporary_v<T&, const U>)
85+ requires (std::is_constructible_v<T&, const U> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
86+ !std::is_same_v<T&, U> && std::reference_constructs_from_temporary_v<T&, const U>)
11087 constexpr optional (const optional<U>&& rhs) = delete;
11188
11289 // \ref{optionalref.dtor}, destructor
@@ -118,10 +95,8 @@ class optional<T&> {
11895 constexpr optional& operator =(const optional& rhs) noexcept = default ;
11996
12097 template <class U >
121- requires (std::is_constructible_v<T&, U> &&
122- !std::reference_constructs_from_temporary_v<T&, U>)
123- constexpr T&
124- emplace (U&& u) noexcept (std::is_nothrow_constructible_v<T&, U>);
98+ requires (std::is_constructible_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, U>)
99+ constexpr T& emplace (U&& u) noexcept (std::is_nothrow_constructible_v<T&, U>);
125100
126101 // \ref{optionalref.swap}, swap
127102 constexpr void swap (optional& rhs) noexcept ;
@@ -167,8 +142,7 @@ class optional<T&> {
167142// \rSec3[optionalref.ctor]{Constructors}
168143template <class T >
169144template <class Arg >
170- requires (std::is_constructible_v<T&, Arg> &&
171- !std::reference_constructs_from_temporary_v<T&, Arg>)
145+ requires (std::is_constructible_v<T&, Arg> && !std::reference_constructs_from_temporary_v<T&, Arg>)
172146constexpr optional<T&>::optional(in_place_t , Arg&& arg) {
173147 convert_ref_init_val (std::forward<Arg>(arg));
174148}
@@ -187,49 +161,38 @@ constexpr optional<T&>::optional(in_place_t, Arg&& arg) {
187161
188162template <class T >
189163template <class U >
190- requires (std::is_constructible_v<T&, U&> &&
191- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
192- !std::is_same_v<T&, U> &&
193- !std::reference_constructs_from_temporary_v<T&, U&>)
194- constexpr optional<T&>::optional(optional<U>& rhs) noexcept (
195- std::is_nothrow_constructible_v<T&, U&>) {
164+ requires (std::is_constructible_v<T&, U&> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
165+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, U&>)
166+ constexpr optional<T&>::optional(optional<U>& rhs) noexcept (std::is_nothrow_constructible_v<T&, U&>) {
196167 if (rhs.has_value ()) {
197168 convert_ref_init_val (*rhs);
198169 }
199170}
200171
201172template <class T >
202173template <class U >
203- requires (std::is_constructible_v<T&, const U&> &&
204- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
205- !std::is_same_v<T&, U> &&
206- !std::reference_constructs_from_temporary_v<T&, const U&>)
207- constexpr optional<T&>::optional(const optional<U>& rhs) noexcept (
208- std::is_nothrow_constructible_v<T&, const U&>) {
174+ requires (std::is_constructible_v<T&, const U&> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
175+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, const U&>)
176+ constexpr optional<T&>::optional(const optional<U>& rhs) noexcept (std::is_nothrow_constructible_v<T&, const U&>) {
209177 if (rhs.has_value ()) {
210178 convert_ref_init_val (*rhs);
211179 }
212180}
213181
214182template <class T >
215183template <class U >
216- requires (std::is_constructible_v<T&, U> &&
217- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
218- !std::is_same_v<T&, U> &&
219- !std::reference_constructs_from_temporary_v<T&, U>)
220- constexpr optional<T&>::optional(optional<U>&& rhs) noexcept (
221- noexcept (std::is_nothrow_constructible_v<T&, U>)) {
184+ requires (std::is_constructible_v<T&, U> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
185+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, U>)
186+ constexpr optional<T&>::optional(optional<U>&& rhs) noexcept (noexcept (std::is_nothrow_constructible_v<T&, U>)) {
222187 if (rhs.has_value ()) {
223188 convert_ref_init_val (*std::move (rhs));
224189 }
225190}
226191
227192template <class T >
228193template <class U >
229- requires (std::is_constructible_v<T&, const U> &&
230- !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
231- !std::is_same_v<T&, U> &&
232- !std::reference_constructs_from_temporary_v<T&, const U>)
194+ requires (std::is_constructible_v<T&, const U> && !std::is_same_v<std::remove_cv_t <T>, optional<U>> &&
195+ !std::is_same_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, const U>)
233196constexpr optional<T&>::optional(const optional<U>&& rhs) noexcept (
234197 noexcept (std::is_nothrow_constructible_v<T&, const U>)) {
235198 if (rhs.has_value ()) {
@@ -246,10 +209,8 @@ constexpr optional<T&>& optional<T&>::operator=(nullopt_t) noexcept {
246209
247210template <class T >
248211template <class U >
249- requires (std::is_constructible_v<T&, U> &&
250- !std::reference_constructs_from_temporary_v<T&, U>)
251- constexpr T&
252- optional<T&>::emplace(U&& u) noexcept (std::is_nothrow_constructible_v<T&, U>) {
212+ requires (std::is_constructible_v<T&, U> && !std::reference_constructs_from_temporary_v<T&, U>)
213+ constexpr T& optional<T&>::emplace(U&& u) noexcept (std::is_nothrow_constructible_v<T&, U>) {
253214 convert_ref_init_val (std::forward<U>(u));
254215 return *value_;
255216}
@@ -301,12 +262,9 @@ constexpr T& optional<T&>::value() const {
301262template <class T >
302263template <class U >
303264constexpr std::remove_cv_t <T> optional<T&>::value_or(U&& u) const {
304- static_assert (std::is_constructible_v<std::remove_cv_t <T>, T&>,
305- " T must be constructible from a T&" );
306- static_assert (std::is_convertible_v<U, std::remove_cv_t <T>>,
307- " Must be able to convert u to T" );
308- return has_value () ? *value_
309- : static_cast <std::remove_cv_t <T>>(std::forward<U>(u));
265+ static_assert (std::is_constructible_v<std::remove_cv_t <T>, T&>, " T must be constructible from a T&" );
266+ static_assert (std::is_convertible_v<U, std::remove_cv_t <T>>, " Must be able to convert u to T" );
267+ return has_value () ? *value_ : static_cast <std::remove_cv_t <T>>(std::forward<U>(u));
310268}
311269
312270// \rSec3[optionalref.monadic]{Monadic operations}
@@ -324,15 +282,11 @@ constexpr auto optional<T&>::and_then(F&& f) const {
324282
325283template <class T >
326284template <class F >
327- constexpr optional<std::invoke_result_t <F, T&>>
328- optional<T&>::transform(F&& f) const {
285+ constexpr optional<std::invoke_result_t <F, T&>> optional<T&>::transform(F&& f) const {
329286 using U = std::invoke_result_t <F, T&>;
330- static_assert (!std::is_same_v<std::remove_cvref_t <U>, in_place_t >,
331- " Result must not be in_place_t" );
332- static_assert (!std::is_same_v<std::remove_cvref_t <U>, nullopt_t >,
333- " Result must not be nullopt_t" );
334- static_assert ((std::is_object_v<U> && !std::is_array_v<U>) ||
335- std::is_lvalue_reference_v<U>,
287+ static_assert (!std::is_same_v<std::remove_cvref_t <U>, in_place_t >, " Result must not be in_place_t" );
288+ static_assert (!std::is_same_v<std::remove_cvref_t <U>, nullopt_t >, " Result must not be nullopt_t" );
289+ static_assert ((std::is_object_v<U> && !std::is_array_v<U>) || std::is_lvalue_reference_v<U>,
336290 " Result must be an non-array object or an lvalue reference" );
337291 if (has_value ()) {
338292 return optional<U>{std::invoke (std::forward<F>(f), *value_)};
@@ -345,8 +299,7 @@ template <class T>
345299template <class F >
346300constexpr optional<T&> optional<T&>::or_else(F&& f) const {
347301 using U = std::invoke_result_t <F>;
348- static_assert (std::is_same_v<std::remove_cvref_t <U>, optional>,
349- " Result must be an optional" );
302+ static_assert (std::is_same_v<std::remove_cvref_t <U>, optional>, " Result must be an optional" );
350303 if (has_value ()) {
351304 return *value_;
352305 } else {
@@ -364,15 +317,11 @@ constexpr void optional<T&>::reset() noexcept {
364317namespace std {
365318template <typename T>
366319 requires requires (T a) {
367- {
368- std::hash<remove_const_t <T>>{}(a)
369- } -> std::convertible_to<std::size_t >;
320+ { std::hash<remove_const_t <T>>{}(a) } -> std::convertible_to<std::size_t >;
370321 }
371322struct hash <beman::optional::optional<T>> {
372- static_assert (!is_reference_v<T>,
373- " hash is not enabled for reference types" );
374- size_t operator ()(const beman::optional::optional<T>& o) const
375- noexcept (noexcept (hash<remove_const_t <T>>{}(*o))) {
323+ static_assert (!is_reference_v<T>, " hash is not enabled for reference types" );
324+ size_t operator ()(const beman::optional::optional<T>& o) const noexcept (noexcept (hash<remove_const_t <T>>{}(*o))) {
376325 if (o) {
377326 return std::hash<std::remove_const_t <T>>{}(*o);
378327 } else {
0 commit comments