Skip to content

Commit e0e8457

Browse files
jensmaurertkoeppe
authored andcommitted
P2231R1 Missing constexpr in std::optional and std::variant
1 parent 4cdaadb commit e0e8457

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

source/support.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@
655655
// \libheader{unordered_map}, \libheader{unordered_set}, \libheader{vector}
656656
#define @\defnlibxname{cpp_lib_not_fn}@ 201603L // also in \libheader{functional}
657657
#define @\defnlibxname{cpp_lib_null_iterators}@ 201304L // also in \libheader{iterator}
658-
#define @\defnlibxname{cpp_lib_optional}@ 201606L // also in \libheader{optional}
658+
#define @\defnlibxname{cpp_lib_optional}@ 202106L // also in \libheader{optional}
659659
#define @\defnlibxname{cpp_lib_out_ptr}@ 202106L // also in \libheader{memory}
660660
#define @\defnlibxname{cpp_lib_parallel_algorithm}@ 201603L // also in \libheader{algorithm}, \libheader{numeric}
661661
#define @\defnlibxname{cpp_lib_polymorphic_allocator}@ 201902L // also in \libheader{memory_resource}
@@ -701,7 +701,7 @@
701701
#define @\defnlibxname{cpp_lib_uncaught_exceptions}@ 201411L // also in \libheader{exception}
702702
#define @\defnlibxname{cpp_lib_unordered_map_try_emplace}@ 201411L // also in \libheader{unordered_map}
703703
#define @\defnlibxname{cpp_lib_unwrap_ref}@ 201811L // also in \libheader{type_traits}
704-
#define @\defnlibxname{cpp_lib_variant}@ 202102L // also in \libheader{variant}
704+
#define @\defnlibxname{cpp_lib_variant}@ 202106L // also in \libheader{variant}
705705
#define @\defnlibxname{cpp_lib_void_t}@ 201411L // also in \libheader{type_traits}
706706
\end{codeblock}
707707

source/utilities.tex

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,7 +2442,7 @@
24422442

24432443
// \ref{optional.specalg}, specialized algorithms
24442444
template<class T>
2445-
void swap(optional<T>&, optional<T>&) noexcept(@\seebelow@);
2445+
constexpr void swap(optional<T>&, optional<T>&) noexcept(@\seebelow@);
24462446

24472447
template<class T>
24482448
constexpr optional<@\seebelow@> make_optional(T&&);
@@ -2482,25 +2482,25 @@
24822482
template<class U = T>
24832483
constexpr explicit(@\seebelow@) optional(U&&);
24842484
template<class U>
2485-
explicit(@\seebelow@) optional(const optional<U>&);
2485+
constexpr explicit(@\seebelow@) optional(const optional<U>&);
24862486
template<class U>
2487-
explicit(@\seebelow@) optional(optional<U>&&);
2487+
constexpr explicit(@\seebelow@) optional(optional<U>&&);
24882488

24892489
// \ref{optional.dtor}, destructor
2490-
~optional();
2490+
constexpr ~optional();
24912491

24922492
// \ref{optional.assign}, assignment
2493-
optional& operator=(nullopt_t) noexcept;
2493+
constexpr optional& operator=(nullopt_t) noexcept;
24942494
constexpr optional& operator=(const optional&);
24952495
constexpr optional& operator=(optional&&) noexcept(@\seebelow@);
2496-
template<class U = T> optional& operator=(U&&);
2497-
template<class U> optional& operator=(const optional<U>&);
2498-
template<class U> optional& operator=(optional<U>&&);
2499-
template<class... Args> T& emplace(Args&&...);
2500-
template<class U, class... Args> T& emplace(initializer_list<U>, Args&&...);
2496+
template<class U = T> constexpr optional& operator=(U&&);
2497+
template<class U> constexpr optional& operator=(const optional<U>&);
2498+
template<class U> constexpr optional& operator=(optional<U>&&);
2499+
template<class... Args> constexpr T& emplace(Args&&...);
2500+
template<class U, class... Args> constexpr T& emplace(initializer_list<U>, Args&&...);
25012501

25022502
// \ref{optional.swap}, swap
2503-
void swap(optional&) noexcept(@\seebelow@);
2503+
constexpr void swap(optional&) noexcept(@\seebelow@);
25042504

25052505
// \ref{optional.observe}, observers
25062506
constexpr const T* operator->() const;
@@ -2519,7 +2519,7 @@
25192519
template<class U> constexpr T value_or(U&&) &&;
25202520

25212521
// \ref{optional.mod}, modifiers
2522-
void reset() noexcept;
2522+
constexpr void reset() noexcept;
25232523

25242524
private:
25252525
T *val; // \expos
@@ -2719,7 +2719,7 @@
27192719

27202720
\indexlibraryctor{optional}%
27212721
\begin{itemdecl}
2722-
template<class U> explicit(@\seebelow@) optional(const optional<U>& rhs);
2722+
template<class U> constexpr explicit(@\seebelow@) optional(const optional<U>& rhs);
27232723
\end{itemdecl}
27242724

27252725
\begin{itemdescr}
@@ -2761,7 +2761,7 @@
27612761

27622762
\indexlibraryctor{optional}%
27632763
\begin{itemdecl}
2764-
template<class U> explicit(@\seebelow@) optional(optional<U>&& rhs);
2764+
template<class U> constexpr explicit(@\seebelow@) optional(optional<U>&& rhs);
27652765
\end{itemdecl}
27662766

27672767
\begin{itemdescr}
@@ -2806,7 +2806,7 @@
28062806

28072807
\indexlibrarydtor{optional}%
28082808
\begin{itemdecl}
2809-
~optional();
2809+
constexpr ~optional();
28102810
\end{itemdecl}
28112811

28122812
\begin{itemdescr}
@@ -2826,7 +2826,7 @@
28262826

28272827
\indexlibrarymember{operator=}{optional}%
28282828
\begin{itemdecl}
2829-
optional<T>& operator=(nullopt_t) noexcept;
2829+
constexpr optional<T>& operator=(nullopt_t) noexcept;
28302830
\end{itemdecl}
28312831

28322832
\begin{itemdescr}
@@ -2947,7 +2947,7 @@
29472947

29482948
\indexlibrarymember{operator=}{optional}%
29492949
\begin{itemdecl}
2950-
template<class U = T> optional<T>& operator=(U&& v);
2950+
template<class U = T> constexpr optional<T>& operator=(U&& v);
29512951
\end{itemdecl}
29522952

29532953
\begin{itemdescr}
@@ -2977,7 +2977,7 @@
29772977

29782978
\indexlibrarymember{operator=}{optional}%
29792979
\begin{itemdecl}
2980-
template<class U> optional<T>& operator=(const optional<U>& rhs);
2980+
template<class U> constexpr optional<T>& operator=(const optional<U>& rhs);
29812981
\end{itemdecl}
29822982

29832983
\begin{itemdescr}
@@ -3040,7 +3040,7 @@
30403040

30413041
\indexlibrarymember{operator=}{optional}%
30423042
\begin{itemdecl}
3043-
template<class U> optional<T>& operator=(optional<U>&& rhs);
3043+
template<class U> constexpr optional<T>& operator=(optional<U>&& rhs);
30443044
\end{itemdecl}
30453045

30463046
\begin{itemdescr}
@@ -3104,7 +3104,7 @@
31043104

31053105
\indexlibrarymember{emplace}{optional}%
31063106
\begin{itemdecl}
3107-
template<class... Args> T& emplace(Args&&... args);
3107+
template<class... Args> constexpr T& emplace(Args&&... args);
31083108
\end{itemdecl}
31093109

31103110
\begin{itemdescr}
@@ -3135,7 +3135,7 @@
31353135

31363136
\indexlibrarymember{emplace}{optional}%
31373137
\begin{itemdecl}
3138-
template<class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
3138+
template<class U, class... Args> constexpr T& emplace(initializer_list<U> il, Args&&... args);
31393139
\end{itemdecl}
31403140

31413141
\begin{itemdescr}
@@ -3168,7 +3168,7 @@
31683168

31693169
\indexlibrarymember{swap}{optional}%
31703170
\begin{itemdecl}
3171-
void swap(optional& rhs) noexcept(@\seebelow@);
3171+
constexpr void swap(optional& rhs) noexcept(@\seebelow@);
31723172
\end{itemdecl}
31733173

31743174
\begin{itemdescr}
@@ -3389,7 +3389,7 @@
33893389

33903390
\indexlibrarymember{reset}{optional}%
33913391
\begin{itemdecl}
3392-
void reset() noexcept;
3392+
constexpr void reset() noexcept;
33933393
\end{itemdecl}
33943394

33953395
\begin{itemdescr}
@@ -3848,7 +3848,8 @@
38483848

38493849
\indexlibrarymember{swap}{optional}%
38503850
\begin{itemdecl}
3851-
template<class T> void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));
3851+
template<class T>
3852+
constexpr void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));
38523853
\end{itemdecl}
38533854

38543855
\begin{itemdescr}
@@ -4024,7 +4025,7 @@
40244025

40254026
// \ref{variant.specalg}, specialized algorithms
40264027
template<class... Types>
4027-
void swap(variant<Types...>&, variant<Types...>&) noexcept(@\seebelow@);
4028+
constexpr void swap(variant<Types...>&, variant<Types...>&) noexcept(@\seebelow@);
40284029

40294030
// \ref{variant.bad.access}, class \tcode{bad_variant_access}
40304031
class bad_variant_access;
@@ -4065,30 +4066,31 @@
40654066
constexpr explicit variant(in_place_index_t<I>, initializer_list<U>, Args&&...);
40664067

40674068
// \ref{variant.dtor}, destructor
4068-
~variant();
4069+
constepxr ~variant();
40694070

40704071
// \ref{variant.assign}, assignment
40714072
constexpr variant& operator=(const variant&);
40724073
constexpr variant& operator=(variant&&) noexcept(@\seebelow@);
40734074

4074-
template<class T> variant& operator=(T&&) noexcept(@\seebelow@);
4075+
template<class T> constexpr variant& operator=(T&&) noexcept(@\seebelow@);
40754076

40764077
// \ref{variant.mod}, modifiers
40774078
template<class T, class... Args>
4078-
T& emplace(Args&&...);
4079+
constexpr T& emplace(Args&&...);
40794080
template<class T, class U, class... Args>
4080-
T& emplace(initializer_list<U>, Args&&...);
4081+
constexpr T& emplace(initializer_list<U>, Args&&...);
40814082
template<size_t I, class... Args>
4082-
variant_alternative_t<I, variant<Types...>>& emplace(Args&&...);
4083+
constexpr variant_alternative_t<I, variant<Types...>>& emplace(Args&&...);
40834084
template<size_t I, class U, class... Args>
4084-
variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U>, Args&&...);
4085+
constexpr variant_alternative_t<I, variant<Types...>>&
4086+
emplace(initializer_list<U>, Args&&...);
40854087

40864088
// \ref{variant.status}, value status
40874089
constexpr bool valueless_by_exception() const noexcept;
40884090
constexpr size_t index() const noexcept;
40894091

40904092
// \ref{variant.swap}, swap
4091-
void swap(variant&) noexcept(@\seebelow@);
4093+
constexpr void swap(variant&) noexcept(@\seebelow@);
40924094
};
40934095
}
40944096
\end{codeblock}
@@ -4414,7 +4416,7 @@
44144416

44154417
\indexlibrarydtor{variant}%
44164418
\begin{itemdecl}
4417-
~variant();
4419+
constexpr ~variant();
44184420
\end{itemdecl}
44194421

44204422
\begin{itemdescr}
@@ -4533,7 +4535,7 @@
45334535

45344536
\indexlibrarymember{operator=}{variant}%
45354537
\begin{itemdecl}
4536-
template<class T> variant& operator=(T&& t) noexcept(@\seebelow@);
4538+
template<class T> constexpr variant& operator=(T&& t) noexcept(@\seebelow@);
45374539
\end{itemdecl}
45384540

45394541
\begin{itemdescr}
@@ -4615,7 +4617,7 @@
46154617

46164618
\indexlibrarymember{emplace}{variant}%
46174619
\begin{itemdecl}
4618-
template<class T, class... Args> T& emplace(Args&&... args);
4620+
template<class T, class... Args> constexpr T& emplace(Args&&... args);
46194621
\end{itemdecl}
46204622

46214623
\begin{itemdescr}
@@ -4635,7 +4637,8 @@
46354637

46364638
\indexlibrarymember{emplace}{variant}%
46374639
\begin{itemdecl}
4638-
template<class T, class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
4640+
template<class T, class U, class... Args>
4641+
constexpr T& emplace(initializer_list<U> il, Args&&... args);
46394642
\end{itemdecl}
46404643

46414644
\begin{itemdescr}
@@ -4656,7 +4659,7 @@
46564659
\indexlibrarymember{emplace}{variant}%
46574660
\begin{itemdecl}
46584661
template<size_t I, class... Args>
4659-
variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
4662+
constexpr variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
46604663
\end{itemdecl}
46614664

46624665
\begin{itemdescr} % NOCHECK: order
@@ -4697,7 +4700,8 @@
46974700
\indexlibrarymember{emplace}{variant}%
46984701
\begin{itemdecl}
46994702
template<size_t I, class U, class... Args>
4700-
variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U> il, Args&&... args);
4703+
constexpr variant_alternative_t<I, variant<Types...>>&
4704+
emplace(initializer_list<U> il, Args&&... args);
47014705
\end{itemdecl}
47024706

47034707
\begin{itemdescr} % NOCHECK: order
@@ -4778,7 +4782,7 @@
47784782

47794783
\indexlibrarymember{swap}{variant}%
47804784
\begin{itemdecl}
4781-
void swap(variant& rhs) noexcept(@\seebelow@);
4785+
constexpr void swap(variant& rhs) noexcept(@\seebelow@);
47824786
\end{itemdecl}
47834787

47844788
\begin{itemdescr}
@@ -5250,7 +5254,7 @@
52505254
\indexlibrarymember{swap}{variant}%
52515255
\begin{itemdecl}
52525256
template<class... Types>
5253-
void swap(variant<Types...>& v, variant<Types...>& w) noexcept(@\seebelow@);
5257+
constexpr void swap(variant<Types...>& v, variant<Types...>& w) noexcept(@\seebelow@);
52545258
\end{itemdecl}
52555259

52565260
\begin{itemdescr}

0 commit comments

Comments
 (0)