Skip to content

Commit daee5de

Browse files
committed
Rebase on current draft
1 parent 5637421 commit daee5de

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

include/beman/optional26/optional.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ class optional {
362362
constexpr T& value() &;
363363
constexpr const T& value() const&;
364364
constexpr T&& value() &&;
365-
template <class U>
365+
template <class U = std::remove_cv_t<T>>
366366
constexpr T value_or(U&& u) const&;
367-
template <class U>
367+
template <class U = std::remove_cv_t<T>>
368368
constexpr T value_or(U&& u) &&;
369369

370370
// \ref{optional.monadic}, monadic operations

papers/P2988/base-optional.tex

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
constexpr void swap(optional<T>&, optional<T>&) noexcept(@\seebelow@);
8787

8888
template<class T>
89-
constexpr optional<@\seebelow@> make_optional(T&&);
89+
constexpr optional<decay_t<T>> make_optional(T&&);
9090
template<class T, class... Args>
9191
constexpr optional<T> make_optional(Args&&... args);
9292
template<class T, class U, class... Args>
@@ -122,7 +122,7 @@
122122
constexpr explicit optional(in_place_t, Args&&...);
123123
template<class U, class... Args>
124124
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
125-
template<class U = T>
125+
template<class U = remove_cv_t<T>>
126126
constexpr explicit(@\seebelow@) optional(U&&);
127127
template<class U>
128128
constexpr explicit(@\seebelow@) optional(const optional<U>&);
@@ -136,7 +136,7 @@
136136
constexpr optional& operator=(nullopt_t) noexcept;
137137
constexpr optional& operator=(const optional&);
138138
constexpr optional& operator=(optional&&) noexcept(@\seebelow@);
139-
template<class U = T> constexpr optional& operator=(U&&);
139+
template<class U = remove_cv_t<T>> constexpr optional& operator=(U&&);
140140
template<class U> constexpr optional& operator=(const optional<U>&);
141141
template<class U> constexpr optional& operator=(optional<U>&&);
142142
template<class... Args> constexpr T& emplace(Args&&...);
@@ -164,8 +164,8 @@
164164
constexpr T& value() &; // freestanding-deleted
165165
constexpr T&& value() &&; // freestanding-deleted
166166
constexpr const T&& value() const &&; // freestanding-deleted
167-
template<class U> constexpr T value_or(U&&) const &;
168-
template<class U> constexpr T value_or(U&&) &&;
167+
template<class U = remove_cv_t<T>> constexpr T value_or(U&&) const &;
168+
template<class U = remove_cv_t<T>> constexpr T value_or(U&&) &&;
169169

170170
// \ref{optional.monadic}, monadic operations
171171
template<class F> constexpr auto and_then(F&& f) &;
@@ -183,7 +183,7 @@
183183
constexpr void reset() noexcept;
184184

185185
private:
186-
T *val; // \expos
186+
T* val; // \expos
187187
};
188188

189189
template<class T>
@@ -195,8 +195,7 @@
195195
Any instance of \tcode{optional<T>} at any given time either contains a value or does not contain a value.
196196
When an instance of \tcode{optional<T>} \defnx{contains a value}{contains a value!\idxcode{optional}},
197197
it means that an object of type \tcode{T}, referred to as the optional object's \defnx{contained value}{contained value!\idxcode{optional}},
198-
is allocated within the storage of the optional object.
199-
Implementations are not permitted to use additional storage, such as dynamic memory, to allocate its contained value.
198+
is nested within\iref{intro.object} the optional object.
200199
When an object of type \tcode{optional<T>} is contextually converted to \tcode{bool},
201200
the conversion returns \tcode{true} if the object contains a value;
202201
otherwise the conversion returns \tcode{false}.
@@ -357,7 +356,7 @@
357356

358357
\indexlibraryctor{optional}%
359358
\begin{itemdecl}
360-
template<class U = T> constexpr explicit(@\seebelow@) optional(U&& v);
359+
template<class U = remove_cv_t<T>> constexpr explicit(@\seebelow@) optional(U&& v);
361360
\end{itemdecl}
362361

363362
\begin{itemdescr}
@@ -609,16 +608,18 @@
609608

610609
\indexlibrarymember{operator=}{optional}%
611610
\begin{itemdecl}
612-
template<class U = T> constexpr optional<T>& operator=(U&& v);
611+
template<class U = remove_cv_t<T>> constexpr optional& operator=(U&& v);
613612
\end{itemdecl}
614613

615614
\begin{itemdescr}
616615
\pnum
617616
\constraints
618-
\tcode{is_same_v<remove_cvref_t<U>, optional>} is \tcode{false},
619-
\tcode{conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>} is \tcode{false},
620-
\tcode{is_constructible_v<T, U>} is \tcode{true}, and
621-
\tcode{is_assignable_v<T\&, U>} is \tcode{true}.
617+
\begin{itemize}
618+
\item \tcode{is_same_v<remove_cvref_t<U>, optional>} is \tcode{false},
619+
\item \tcode{conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>} is \tcode{false},
620+
\item \tcode{is_constructible_v<T, U>} is \tcode{true}, and
621+
\item \tcode{is_assignable_v<T\&, U>} is \tcode{true}.
622+
\end{itemize}
622623

623624
\pnum
624625
\effects
@@ -1044,7 +1045,7 @@
10441045

10451046
\indexlibrarymember{value_or}{optional}%
10461047
\begin{itemdecl}
1047-
template<class U> constexpr T value_or(U&& v) const &;
1048+
template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) const &;
10481049
\end{itemdecl}
10491050

10501051
\begin{itemdescr}
@@ -1062,7 +1063,7 @@
10621063

10631064
\indexlibrarymember{value_or}{optional}%
10641065
\begin{itemdecl}
1065-
template<class U> constexpr T value_or(U&& v) &&;
1066+
template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) &&;
10661067
\end{itemdecl}
10671068

10681069
\begin{itemdescr}
@@ -1510,6 +1511,7 @@
15101511
\begin{itemdescr}
15111512
\pnum
15121513
\constraints
1514+
\tcode{U} is not a specialization of \tcode{optional}.
15131515
The expression \tcode{*x == v} is well-formed and
15141516
its result is convertible to \tcode{bool}.
15151517
\begin{note}
@@ -1529,6 +1531,7 @@
15291531
\begin{itemdescr}
15301532
\pnum
15311533
\constraints
1534+
\tcode{T} is not a specialization of \tcode{optional}.
15321535
The expression \tcode{v == *x} is well-formed and
15331536
its result is convertible to \tcode{bool}.
15341537

@@ -1545,6 +1548,7 @@
15451548
\begin{itemdescr}
15461549
\pnum
15471550
\constraints
1551+
\tcode{U} is not a specialization of \tcode{optional}.
15481552
The expression \tcode{*x != v} is well-formed and
15491553
its result is convertible to \tcode{bool}.
15501554

@@ -1561,6 +1565,7 @@
15611565
\begin{itemdescr}
15621566
\pnum
15631567
\constraints
1568+
\tcode{T} is not a specialization of \tcode{optional}.
15641569
The expression \tcode{v != *x} is well-formed and
15651570
its result is convertible to \tcode{bool}.
15661571

@@ -1577,6 +1582,7 @@
15771582
\begin{itemdescr}
15781583
\pnum
15791584
\constraints
1585+
\tcode{U} is not a specialization of \tcode{optional}.
15801586
The expression \tcode{*x < v} is well-formed and
15811587
its result is convertible to \tcode{bool}.
15821588

@@ -1593,6 +1599,7 @@
15931599
\begin{itemdescr}
15941600
\pnum
15951601
\constraints
1602+
\tcode{T} is not a specialization of \tcode{optional}.
15961603
The expression \tcode{v < *x} is well-formed and
15971604
its result is convertible to \tcode{bool}.
15981605

@@ -1609,6 +1616,7 @@
16091616
\begin{itemdescr}
16101617
\pnum
16111618
\constraints
1619+
\tcode{U} is not a specialization of \tcode{optional}.
16121620
The expression \tcode{*x > v} is well-formed and
16131621
its result is convertible to \tcode{bool}.
16141622

@@ -1625,6 +1633,7 @@
16251633
\begin{itemdescr}
16261634
\pnum
16271635
\constraints
1636+
\tcode{T} is not a specialization of \tcode{optional}.
16281637
The expression \tcode{v > *x} is well-formed and
16291638
its result is convertible to \tcode{bool}.
16301639

@@ -1641,6 +1650,7 @@
16411650
\begin{itemdescr}
16421651
\pnum
16431652
\constraints
1653+
\tcode{U} is not a specialization of \tcode{optional}.
16441654
The expression \tcode{*x <= v} is well-formed and
16451655
its result is convertible to \tcode{bool}.
16461656

@@ -1657,6 +1667,7 @@
16571667
\begin{itemdescr}
16581668
\pnum
16591669
\constraints
1670+
\tcode{T} is not a specialization of \tcode{optional}.
16601671
The expression \tcode{v <= *x} is well-formed and
16611672
its result is convertible to \tcode{bool}.
16621673

@@ -1673,6 +1684,7 @@
16731684
\begin{itemdescr}
16741685
\pnum
16751686
\constraints
1687+
\tcode{U} is not a specialization of \tcode{optional}.
16761688
The expression \tcode{*x >= v} is well-formed and
16771689
its result is convertible to \tcode{bool}.
16781690

@@ -1689,6 +1701,7 @@
16891701
\begin{itemdescr}
16901702
\pnum
16911703
\constraints
1704+
\tcode{T} is not a specialization of \tcode{optional}.
16921705
The expression \tcode{v >= *x} is well-formed and
16931706
its result is convertible to \tcode{bool}.
16941707

papers/P2988/new-optional.tex

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
constexpr void swap(optional<T>&, optional<T>&) noexcept(@\seebelow@);
9393

9494
template<class T>
95-
constexpr optional<@\seebelow@> make_optional(T&&);
95+
constexpr optional<decay_t<T>> make_optional(T&&);
9696
template<class T, class... Args>
9797
constexpr optional<T> make_optional(Args&&... args);
9898
template<class T, class U, class... Args>
@@ -129,7 +129,7 @@
129129
constexpr explicit optional(in_place_t, Args&&...);
130130
template<class U, class... Args>
131131
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
132-
template<class U = T>
132+
template<class U = remove_cv_t<T>>
133133
constexpr explicit(@\seebelow@) optional(U&&);
134134
template<class U>
135135
constexpr explicit(@\seebelow@) optional(const optional<U>&);
@@ -151,7 +151,7 @@
151151
constexpr optional& operator=(nullopt_t) noexcept;
152152
constexpr optional& operator=(const optional&);
153153
constexpr optional& operator=(optional&&) noexcept(@\seebelow@);
154-
template<class U = T> constexpr optional& operator=(U&&);
154+
template<class U = remove_cv_t<T>> constexpr optional& operator=(U&&);
155155
template<class U> constexpr optional& operator=(const optional<U>&);
156156
\end{codeblock}
157157
\color{addclr}
@@ -186,8 +186,8 @@
186186
constexpr T& value() &; // freestanding-deleted
187187
constexpr T&& value() &&; // freestanding-deleted
188188
constexpr const T&& value() const &&; // freestanding-deleted
189-
template<class U> constexpr T value_or(U&&) const &;
190-
template<class U> constexpr T value_or(U&&) &&;
189+
template<class U = remove_cv_t<T>> constexpr T value_or(U&&) const &;
190+
template<class U = remove_cv_t<T>> constexpr T value_or(U&&) &&;
191191

192192
// \ref{optional.monadic}, monadic operations
193193
template<class F> constexpr auto and_then(F&& f) &;
@@ -205,7 +205,7 @@
205205
constexpr void reset() noexcept;
206206

207207
private:
208-
T *val; // \expos
208+
T* val; // \expos
209209
};
210210

211211
template<class T>
@@ -217,8 +217,7 @@
217217
Any instance of \tcode{optional<T>} at any given time either contains a value or does not contain a value.
218218
When an instance of \tcode{optional<T>} \defnx{contains a value}{contains a value!\idxcode{optional}},
219219
it means that an object of type \tcode{T}, referred to as the optional object's \defnx{contained value}{contained value!\idxcode{optional}},
220-
is allocated within the storage of the optional object.
221-
Implementations are not permitted to use additional storage, such as dynamic memory, to allocate its contained value.
220+
is nested within\iref{intro.object} the optional object.
222221
When an object of type \tcode{optional<T>} is contextually converted to \tcode{bool},
223222
the conversion returns \tcode{true} if the object contains a value;
224223
otherwise the conversion returns \tcode{false}.
@@ -389,7 +388,7 @@
389388

390389
\indexlibraryctor{optional}%
391390
\begin{itemdecl}
392-
template<class U = T> constexpr explicit(@\seebelow@) optional(U&& v);
391+
template<class U = remove_cv_t<T>> constexpr explicit(@\seebelow@) optional(U&& v);
393392
\end{itemdecl}
394393

395394
\begin{itemdescr}
@@ -661,16 +660,18 @@
661660

662661
\indexlibrarymember{operator=}{optional}%
663662
\begin{itemdecl}
664-
template<class U = T> constexpr optional<T>& operator=(U&& v);
663+
template<class U = remove_cv_t<T>> constexpr optional<T>& operator=(U&& v);
665664
\end{itemdecl}
666665

667666
\begin{itemdescr}
668667
\pnum
669668
\constraints
670-
\tcode{is_same_v<remove_cvref_t<U>, optional>} is \tcode{false},
671-
\tcode{conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>} is \tcode{false},
672-
\tcode{is_constructible_v<T, U>} is \tcode{true}, and
673-
\tcode{is_assignable_v<T\&, U>} is \tcode{true}.
669+
\begin{itemize}
670+
\item \tcode{is_same_v<remove_cvref_t<U>, optional>} is \tcode{false},
671+
\item \tcode{conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>>} is \tcode{false},
672+
\item \tcode{is_constructible_v<T, U>} is \tcode{true}, and
673+
\item \tcode{is_assignable_v<T\&, U>} is \tcode{true}.
674+
\end{itemize}
674675

675676
\pnum
676677
\effects

0 commit comments

Comments
 (0)