- utility[meta header]
- std[meta namespace]
- constant_wrapper[meta class]
- function template[meta id-type]
- cpp26[meta cpp]
template <class... Args>
static constexpr decltype(auto) operator()(Args&&... args) noexcept(/*see below*/);constant_wrapperが保持する値を、関数として呼び出す。
call-exprを以下のように定めたとき、call-exprを返す:
- すべての
remove_cvref_t<Args>...がconstexpr-paramのモデルであり、かつconstant_wrapper<INVOKE(value, remove_cvref_t<Args>::value...)>が妥当な型である場合は、constant_wrapper<INVOKE(value, remove_cvref_t<Args>::value...)>{} - そうでない場合は、
INVOKE(value, std::forward<Args>(args)...)
- 静的メンバ関数である。
- 引数がすべて
constant_wrapperであり、その結果をふたたびconstant_wrapperで包める場合は、結果を包んで「型の世界」にとどめる。そうでない場合は、保持する値をアンラップして呼び出した結果をそのまま返す。 - 例外指定は
noexcept(call-expr)と等価である。
#include <utility>
constexpr int triple(int x) { return x * 3; }
int main()
{
// cw<triple>を呼び出すと、保持する関数を呼び出す
// 引数もconstant_wrapperなら、結果をconstant_wrapperで包む
auto r = std::cw<triple>(std::cw<7>);
static_assert(r == 21);
}
- C++26
- Clang: 23 [mark verified]
- GCC: 16.1 [mark verified]
- Visual C++: 2026 Update 2 [mark noimpl]