Skip to content

Commit 29499c6

Browse files
committed
P2231R1 Missing constexpr in std::optional and std::variant
1 parent fb3bea8 commit 29499c6

File tree

2 files changed

+45
-41
lines changed

2 files changed

+45
-41
lines changed

source/support.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@
651651
// \libheader{unordered_map}, \libheader{unordered_set}, \libheader{vector}
652652
#define @\defnlibxname{cpp_lib_not_fn}@ 201603L // also in \libheader{functional}
653653
#define @\defnlibxname{cpp_lib_null_iterators}@ 201304L // also in \libheader{iterator}
654-
#define @\defnlibxname{cpp_lib_optional}@ 201606L // also in \libheader{optional}
654+
#define @\defnlibxname{cpp_lib_optional}@ 202106L // also in \libheader{optional}
655655
#define @\defnlibxname{cpp_lib_parallel_algorithm}@ 201603L // also in \libheader{algorithm}, \libheader{numeric}
656656
#define @\defnlibxname{cpp_lib_polymorphic_allocator}@ 201902L // also in \libheader{memory_resource}
657657
#define @\defnlibxname{cpp_lib_quoted_string_io}@ 201304L // also in \libheader{iomanip}
@@ -694,7 +694,7 @@
694694
#define @\defnlibxname{cpp_lib_uncaught_exceptions}@ 201411L // also in \libheader{exception}
695695
#define @\defnlibxname{cpp_lib_unordered_map_try_emplace}@ 201411L // also in \libheader{unordered_map}
696696
#define @\defnlibxname{cpp_lib_unwrap_ref}@ 201811L // also in \libheader{type_traits}
697-
#define @\defnlibxname{cpp_lib_variant}@ 202102L // also in \libheader{variant}
697+
#define @\defnlibxname{cpp_lib_variant}@ 202106L // also in \libheader{variant}
698698
#define @\defnlibxname{cpp_lib_void_t}@ 201411L // also in \libheader{type_traits}
699699
\end{codeblock}
700700

source/utilities.tex

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@
24412441

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

24462446
template<class T>
24472447
constexpr optional<@\seebelow@> make_optional(T&&);
@@ -2481,25 +2481,25 @@
24812481
template<class U = T>
24822482
constexpr explicit(@\seebelow@) optional(U&&);
24832483
template<class U>
2484-
explicit(@\seebelow@) optional(const optional<U>&);
2484+
constexpr explicit(@\seebelow@) optional(const optional<U>&);
24852485
template<class U>
2486-
explicit(@\seebelow@) optional(optional<U>&&);
2486+
constexpr explicit(@\seebelow@) optional(optional<U>&&);
24872487

24882488
// \ref{optional.dtor}, destructor
2489-
~optional();
2489+
constexpr ~optional();
24902490

24912491
// \ref{optional.assign}, assignment
2492-
optional& operator=(nullopt_t) noexcept;
2492+
constexpr optional& operator=(nullopt_t) noexcept;
24932493
constexpr optional& operator=(const optional&);
24942494
constexpr optional& operator=(optional&&) noexcept(@\seebelow@);
2495-
template<class U = T> optional& operator=(U&&);
2496-
template<class U> optional& operator=(const optional<U>&);
2497-
template<class U> optional& operator=(optional<U>&&);
2498-
template<class... Args> T& emplace(Args&&...);
2499-
template<class U, class... Args> T& emplace(initializer_list<U>, Args&&...);
2495+
template<class U = T> constexpr optional& operator=(U&&);
2496+
template<class U> constexpr optional& operator=(const optional<U>&);
2497+
template<class U> constexpr optional& operator=(optional<U>&&);
2498+
template<class... Args> constexpr T& emplace(Args&&...);
2499+
template<class U, class... Args> constexpr T& emplace(initializer_list<U>, Args&&...);
25002500

25012501
// \ref{optional.swap}, swap
2502-
void swap(optional&) noexcept(@\seebelow@);
2502+
constexpr void swap(optional&) noexcept(@\seebelow@);
25032503

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

25202520
// \ref{optional.mod}, modifiers
2521-
void reset() noexcept;
2521+
constexpr void reset() noexcept;
25222522

25232523
private:
25242524
T *val; // \expos
@@ -2718,7 +2718,7 @@
27182718

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

27242724
\begin{itemdescr}
@@ -2760,7 +2760,7 @@
27602760

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

27662766
\begin{itemdescr}
@@ -2805,7 +2805,7 @@
28052805

28062806
\indexlibrarydtor{optional}%
28072807
\begin{itemdecl}
2808-
~optional();
2808+
constexpr ~optional();
28092809
\end{itemdecl}
28102810

28112811
\begin{itemdescr}
@@ -2825,7 +2825,7 @@
28252825

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

28312831
\begin{itemdescr}
@@ -2946,7 +2946,7 @@
29462946

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

29522952
\begin{itemdescr}
@@ -2976,7 +2976,7 @@
29762976

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

29822982
\begin{itemdescr}
@@ -3039,7 +3039,7 @@
30393039

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

30453045
\begin{itemdescr}
@@ -3103,7 +3103,7 @@
31033103

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

31093109
\begin{itemdescr}
@@ -3134,7 +3134,7 @@
31343134

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

31403140
\begin{itemdescr}
@@ -3167,7 +3167,7 @@
31673167

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

31733173
\begin{itemdescr}
@@ -3388,7 +3388,7 @@
33883388

33893389
\indexlibrarymember{reset}{optional}%
33903390
\begin{itemdecl}
3391-
void reset() noexcept;
3391+
constexpr void reset() noexcept;
33923392
\end{itemdecl}
33933393

33943394
\begin{itemdescr}
@@ -3847,7 +3847,8 @@
38473847

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

38533854
\begin{itemdescr}
@@ -4023,7 +4024,7 @@
40234024

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

40284029
// \ref{variant.bad.access}, class \tcode{bad_variant_access}
40294030
class bad_variant_access;
@@ -4070,24 +4071,25 @@
40704071
constexpr variant& operator=(const variant&);
40714072
constexpr variant& operator=(variant&&) noexcept(@\seebelow@);
40724073

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

40754076
// \ref{variant.mod}, modifiers
40764077
template<class T, class... Args>
4077-
T& emplace(Args&&...);
4078+
constexpr T& emplace(Args&&...);
40784079
template<class T, class U, class... Args>
4079-
T& emplace(initializer_list<U>, Args&&...);
4080+
constexpr T& emplace(initializer_list<U>, Args&&...);
40804081
template<size_t I, class... Args>
4081-
variant_alternative_t<I, variant<Types...>>& emplace(Args&&...);
4082+
constexpr variant_alternative_t<I, variant<Types...>>& emplace(Args&&...);
40824083
template<size_t I, class U, class... Args>
4083-
variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U>, Args&&...);
4084+
constexpr variant_alternative_t<I, variant<Types...>>&
4085+
emplace(initializer_list<U>, Args&&...);
40844086

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

40894091
// \ref{variant.swap}, swap
4090-
void swap(variant&) noexcept(@\seebelow@);
4092+
constexpr void swap(variant&) noexcept(@\seebelow@);
40914093
};
40924094
}
40934095
\end{codeblock}
@@ -4413,7 +4415,7 @@
44134415

44144416
\indexlibrarydtor{variant}%
44154417
\begin{itemdecl}
4416-
~variant();
4418+
constexpr ~variant();
44174419
\end{itemdecl}
44184420

44194421
\begin{itemdescr}
@@ -4532,7 +4534,7 @@
45324534

45334535
\indexlibrarymember{operator=}{variant}%
45344536
\begin{itemdecl}
4535-
template<class T> variant& operator=(T&& t) noexcept(@\seebelow@);
4537+
template<class T> constexpr variant& operator=(T&& t) noexcept(@\seebelow@);
45364538
\end{itemdecl}
45374539

45384540
\begin{itemdescr}
@@ -4614,7 +4616,7 @@
46144616

46154617
\indexlibrarymember{emplace}{variant}%
46164618
\begin{itemdecl}
4617-
template<class T, class... Args> T& emplace(Args&&... args);
4619+
template<class T, class... Args> constexpr T& emplace(Args&&... args);
46184620
\end{itemdecl}
46194621

46204622
\begin{itemdescr}
@@ -4634,7 +4636,8 @@
46344636

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

46404643
\begin{itemdescr}
@@ -4655,7 +4658,7 @@
46554658
\indexlibrarymember{emplace}{variant}%
46564659
\begin{itemdecl}
46574660
template<size_t I, class... Args>
4658-
variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
4661+
constexpr variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
46594662
\end{itemdecl}
46604663

46614664
\begin{itemdescr} % NOCHECK: order
@@ -4696,7 +4699,8 @@
46964699
\indexlibrarymember{emplace}{variant}%
46974700
\begin{itemdecl}
46984701
template<size_t I, class U, class... Args>
4699-
variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U> il, Args&&... args);
4702+
constexpr variant_alternative_t<I, variant<Types...>>&
4703+
emplace(initializer_list<U> il, Args&&... args);
47004704
\end{itemdecl}
47014705

47024706
\begin{itemdescr} % NOCHECK: order
@@ -4777,7 +4781,7 @@
47774781

47784782
\indexlibrarymember{swap}{variant}%
47794783
\begin{itemdecl}
4780-
void swap(variant& rhs) noexcept(@\seebelow@);
4784+
constexpr void swap(variant& rhs) noexcept(@\seebelow@);
47814785
\end{itemdecl}
47824786

47834787
\begin{itemdescr}
@@ -5249,7 +5253,7 @@
52495253
\indexlibrarymember{swap}{variant}%
52505254
\begin{itemdecl}
52515255
template<class... Types>
5252-
void swap(variant<Types...>& v, variant<Types...>& w) noexcept(@\seebelow@);
5256+
constexpr void swap(variant<Types...>& v, variant<Types...>& w) noexcept(@\seebelow@);
52535257
\end{itemdecl}
52545258

52555259
\begin{itemdescr}

0 commit comments

Comments
 (0)