Skip to content

Commit 98ad674

Browse files
committed
P3978R3 constant_wrapper should unwrap on call and subscript
1 parent 6913287 commit 98ad674

2 files changed

Lines changed: 64 additions & 11 deletions

File tree

source/meta.tex

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -797,16 +797,6 @@
797797
friend constexpr auto operator->*(L, R) noexcept -> constant_wrapper<L::value->*(R::value)>
798798
{ return {}; }
799799

800-
// call and index
801-
template<@\exposconcept{constexpr-param}@ T, @\exposconcept{constexpr-param}@... Args>
802-
constexpr auto operator()(this T, Args...) noexcept
803-
requires requires { constant_wrapper<T::value(Args::value...)>(); }
804-
{ return constant_wrapper<T::value(Args::value...)>{}; }
805-
template<@\exposconcept{constexpr-param}@ T, @\exposconcept{constexpr-param}@... Args>
806-
constexpr auto operator[](this T, Args...) noexcept
807-
-> constant_wrapper<(T::value[Args::value...])>
808-
{ return {}; }
809-
810800
// pseudo-mutators
811801
template<@\exposconcept{constexpr-param}@ T>
812802
constexpr auto operator++(this T) noexcept
@@ -864,6 +854,11 @@
864854
-> constant_wrapper<X = R::value> { return {}; }
865855

866856
constexpr operator decltype(auto)() const noexcept { return value; }
857+
858+
template<class... Args>
859+
static constexpr decltype(auto) operator()(Args&&... args) noexcept(@\seebelow@);
860+
template<class... Args>
861+
static constexpr decltype(auto) operator[](Args&&... args) noexcept(@\seebelow@);
867862
};
868863
}
869864
\end{codeblock}
@@ -926,6 +921,64 @@
926921
Initialize elements of \exposid{data} with corresponding elements of \tcode{arr}.
927922
\end{itemdescr}
928923

924+
\indexlibrarymember{operator()}{constant_wrapper}%
925+
\begin{itemdecl}
926+
template<class... Args>
927+
static constexpr decltype(auto) operator()(Args&&... args) noexcept(@\seebelow@);
928+
\end{itemdecl}
929+
930+
\begin{itemdescr}
931+
\pnum
932+
Let \tcode{\placeholder{call-expr}} be
933+
\tcode{constant_wrapper<\placeholder{INVOKE}(value,
934+
remove_cvref_t<Args>::value...)>\{\}} if all types in
935+
\tcode{remove_cvref_t<Args>...} satisfy \exposconcept{constexpr-param} and
936+
\tcode{constant_wrapper<\placeholder{INVOKE}(val\-ue,
937+
remove_cvref_t<Args>::value...)>} is a valid type, otherwise let
938+
\tcode{\placeholder{call-expr}} be \tcode{\placeholder{INVOKE}(value,
939+
std::forward<Args>(args)...)}.
940+
941+
\pnum
942+
\constraints
943+
\tcode{\placeholder{call-expr}} is a valid expression.
944+
945+
\pnum
946+
\effects
947+
Equivalent to: \tcode{return \placeholder{call-expr};}
948+
949+
\pnum
950+
\remarks
951+
The exception specification is equivalent to \tcode{noexcept(\placeholder{call-expr})}.
952+
\end{itemdescr}
953+
954+
\indexlibrarymember{operator[]}{constant_wrapper}%
955+
\begin{itemdecl}
956+
template<class... Args>
957+
static constexpr decltype(auto) operator[](Args&&... args) noexcept(@\seebelow@);
958+
\end{itemdecl}
959+
960+
\begin{itemdescr}
961+
\pnum
962+
Let \tcode{\placeholder{subscr-expr}} be
963+
\tcode{constant_wrapper<value[remove_cvref_t<Args>::value...]>\{\}} if all
964+
types in \tcode{remove_cvref_t<Args>...} satisfy \exposconcept{constexpr-param}
965+
and \tcode{constant_wrapper<value[remove_cv\-ref_t<Args>::value...]>} is a valid
966+
type, otherwise let \tcode{\placeholder{subscr-expr}} be
967+
\tcode{value[std::forward<Args\brk{}>(args)...]}.
968+
969+
\pnum
970+
\constraints
971+
\tcode{\placeholder{subscr-expr}} is a valid expression.
972+
973+
\pnum
974+
\effects
975+
Equivalent to: \tcode{return \placeholder{subscr-expr};}
976+
977+
\pnum
978+
\remarks
979+
The exception specification is equivalent to \tcode{noexcept(\placeholder{subscr-expr})}.
980+
\end{itemdescr}
981+
929982
\rSec2[meta.unary]{Unary type traits}
930983

931984
\rSec3[meta.unary.general]{General}

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@
620620
#define @\defnlibxname{cpp_lib_complex_udls}@ 201309L // also in \libheader{complex}
621621
#define @\defnlibxname{cpp_lib_concepts}@ 202207L
622622
// freestanding, also in \libheader{concepts}, \libheader{compare}
623-
#define @\defnlibxname{cpp_lib_constant_wrapper}@ 202506L // freestanding, also in \libheader{type_traits}
623+
#define @\defnlibxname{cpp_lib_constant_wrapper}@ 202603L // freestanding, also in \libheader{utility}
624624
#define @\defnlibxname{cpp_lib_constexpr_algorithms}@ 202306L // also in \libheader{algorithm}, \libheader{utility}
625625
#define @\defnlibxname{cpp_lib_constexpr_atomic}@ 202411L // also in \libheader{atomic}
626626
#define @\defnlibxname{cpp_lib_constexpr_bitset}@ 202207L // also in \libheader{bitset}

0 commit comments

Comments
 (0)