|
86 | 86 | constexpr void swap(optional<T>&, optional<T>&) noexcept(@\seebelow@); |
87 | 87 |
|
88 | 88 | template<class T> |
89 | | - constexpr optional<@\seebelow@> make_optional(T&&); |
| 89 | + constexpr optional<decay_t<T>> make_optional(T&&); |
90 | 90 | template<class T, class... Args> |
91 | 91 | constexpr optional<T> make_optional(Args&&... args); |
92 | 92 | template<class T, class U, class... Args> |
|
122 | 122 | constexpr explicit optional(in_place_t, Args&&...); |
123 | 123 | template<class U, class... Args> |
124 | 124 | constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...); |
125 | | - template<class U = T> |
| 125 | + template<class U = remove_cv_t<T>> |
126 | 126 | constexpr explicit(@\seebelow@) optional(U&&); |
127 | 127 | template<class U> |
128 | 128 | constexpr explicit(@\seebelow@) optional(const optional<U>&); |
|
136 | 136 | constexpr optional& operator=(nullopt_t) noexcept; |
137 | 137 | constexpr optional& operator=(const optional&); |
138 | 138 | 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&&); |
140 | 140 | template<class U> constexpr optional& operator=(const optional<U>&); |
141 | 141 | template<class U> constexpr optional& operator=(optional<U>&&); |
142 | 142 | template<class... Args> constexpr T& emplace(Args&&...); |
|
164 | 164 | constexpr T& value() &; // freestanding-deleted |
165 | 165 | constexpr T&& value() &&; // freestanding-deleted |
166 | 166 | 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&&) &&; |
169 | 169 |
|
170 | 170 | // \ref{optional.monadic}, monadic operations |
171 | 171 | template<class F> constexpr auto and_then(F&& f) &; |
|
183 | 183 | constexpr void reset() noexcept; |
184 | 184 |
|
185 | 185 | private: |
186 | | - T *val; // \expos |
| 186 | + T* val; // \expos |
187 | 187 | }; |
188 | 188 |
|
189 | 189 | template<class T> |
|
195 | 195 | Any instance of \tcode{optional<T>} at any given time either contains a value or does not contain a value. |
196 | 196 | When an instance of \tcode{optional<T>} \defnx{contains a value}{contains a value!\idxcode{optional}}, |
197 | 197 | 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. |
200 | 199 | When an object of type \tcode{optional<T>} is contextually converted to \tcode{bool}, |
201 | 200 | the conversion returns \tcode{true} if the object contains a value; |
202 | 201 | otherwise the conversion returns \tcode{false}. |
|
357 | 356 |
|
358 | 357 | \indexlibraryctor{optional}% |
359 | 358 | \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); |
361 | 360 | \end{itemdecl} |
362 | 361 |
|
363 | 362 | \begin{itemdescr} |
|
609 | 608 |
|
610 | 609 | \indexlibrarymember{operator=}{optional}% |
611 | 610 | \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); |
613 | 612 | \end{itemdecl} |
614 | 613 |
|
615 | 614 | \begin{itemdescr} |
616 | 615 | \pnum |
617 | 616 | \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} |
622 | 623 |
|
623 | 624 | \pnum |
624 | 625 | \effects |
|
1044 | 1045 |
|
1045 | 1046 | \indexlibrarymember{value_or}{optional}% |
1046 | 1047 | \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 &; |
1048 | 1049 | \end{itemdecl} |
1049 | 1050 |
|
1050 | 1051 | \begin{itemdescr} |
|
1062 | 1063 |
|
1063 | 1064 | \indexlibrarymember{value_or}{optional}% |
1064 | 1065 | \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) &&; |
1066 | 1067 | \end{itemdecl} |
1067 | 1068 |
|
1068 | 1069 | \begin{itemdescr} |
|
1510 | 1511 | \begin{itemdescr} |
1511 | 1512 | \pnum |
1512 | 1513 | \constraints |
| 1514 | +\tcode{U} is not a specialization of \tcode{optional}. |
1513 | 1515 | The expression \tcode{*x == v} is well-formed and |
1514 | 1516 | its result is convertible to \tcode{bool}. |
1515 | 1517 | \begin{note} |
|
1529 | 1531 | \begin{itemdescr} |
1530 | 1532 | \pnum |
1531 | 1533 | \constraints |
| 1534 | +\tcode{T} is not a specialization of \tcode{optional}. |
1532 | 1535 | The expression \tcode{v == *x} is well-formed and |
1533 | 1536 | its result is convertible to \tcode{bool}. |
1534 | 1537 |
|
|
1545 | 1548 | \begin{itemdescr} |
1546 | 1549 | \pnum |
1547 | 1550 | \constraints |
| 1551 | +\tcode{U} is not a specialization of \tcode{optional}. |
1548 | 1552 | The expression \tcode{*x != v} is well-formed and |
1549 | 1553 | its result is convertible to \tcode{bool}. |
1550 | 1554 |
|
|
1561 | 1565 | \begin{itemdescr} |
1562 | 1566 | \pnum |
1563 | 1567 | \constraints |
| 1568 | +\tcode{T} is not a specialization of \tcode{optional}. |
1564 | 1569 | The expression \tcode{v != *x} is well-formed and |
1565 | 1570 | its result is convertible to \tcode{bool}. |
1566 | 1571 |
|
|
1577 | 1582 | \begin{itemdescr} |
1578 | 1583 | \pnum |
1579 | 1584 | \constraints |
| 1585 | +\tcode{U} is not a specialization of \tcode{optional}. |
1580 | 1586 | The expression \tcode{*x < v} is well-formed and |
1581 | 1587 | its result is convertible to \tcode{bool}. |
1582 | 1588 |
|
|
1593 | 1599 | \begin{itemdescr} |
1594 | 1600 | \pnum |
1595 | 1601 | \constraints |
| 1602 | +\tcode{T} is not a specialization of \tcode{optional}. |
1596 | 1603 | The expression \tcode{v < *x} is well-formed and |
1597 | 1604 | its result is convertible to \tcode{bool}. |
1598 | 1605 |
|
|
1609 | 1616 | \begin{itemdescr} |
1610 | 1617 | \pnum |
1611 | 1618 | \constraints |
| 1619 | +\tcode{U} is not a specialization of \tcode{optional}. |
1612 | 1620 | The expression \tcode{*x > v} is well-formed and |
1613 | 1621 | its result is convertible to \tcode{bool}. |
1614 | 1622 |
|
|
1625 | 1633 | \begin{itemdescr} |
1626 | 1634 | \pnum |
1627 | 1635 | \constraints |
| 1636 | +\tcode{T} is not a specialization of \tcode{optional}. |
1628 | 1637 | The expression \tcode{v > *x} is well-formed and |
1629 | 1638 | its result is convertible to \tcode{bool}. |
1630 | 1639 |
|
|
1641 | 1650 | \begin{itemdescr} |
1642 | 1651 | \pnum |
1643 | 1652 | \constraints |
| 1653 | +\tcode{U} is not a specialization of \tcode{optional}. |
1644 | 1654 | The expression \tcode{*x <= v} is well-formed and |
1645 | 1655 | its result is convertible to \tcode{bool}. |
1646 | 1656 |
|
|
1657 | 1667 | \begin{itemdescr} |
1658 | 1668 | \pnum |
1659 | 1669 | \constraints |
| 1670 | +\tcode{T} is not a specialization of \tcode{optional}. |
1660 | 1671 | The expression \tcode{v <= *x} is well-formed and |
1661 | 1672 | its result is convertible to \tcode{bool}. |
1662 | 1673 |
|
|
1673 | 1684 | \begin{itemdescr} |
1674 | 1685 | \pnum |
1675 | 1686 | \constraints |
| 1687 | +\tcode{U} is not a specialization of \tcode{optional}. |
1676 | 1688 | The expression \tcode{*x >= v} is well-formed and |
1677 | 1689 | its result is convertible to \tcode{bool}. |
1678 | 1690 |
|
|
1689 | 1701 | \begin{itemdescr} |
1690 | 1702 | \pnum |
1691 | 1703 | \constraints |
| 1704 | +\tcode{T} is not a specialization of \tcode{optional}. |
1692 | 1705 | The expression \tcode{v >= *x} is well-formed and |
1693 | 1706 | its result is convertible to \tcode{bool}. |
1694 | 1707 |
|
|
0 commit comments