std::meta::has_default_argument
From cppreference.com
| Defined in header <meta>
|
||
consteval bool has_default_argument( std::meta::info r );
|
(since C++26) | |
Returns true if r represents a function parameter P that has a default argument D. Otherwise, returns false.
Formally, let P denote a function parameter, F denote a function, and D denote a default argument.
- If
Fis a specialization of a templated functionT, then returnstrueif there exists a declarationDofTthat is reachable from a point in the evaluation context andDspecifies a default argument for the parameter ofTcorresponding toP. Otherwise, returnsfalse. - Otherwise, if there exists a declaration
DofFthat is reachable from a point in the evaluation context andDspecifies a default argument forP, then returnstrue. Otherwise, returnsfalse.
Contents
Parameters
| r | - | a reflection value |
Return value
true if r represents a function parameter that has a default argument; otherwise false.
Example
Run this code
#include <meta>
void foo(int x, double y = 3.14);
constexpr auto rx{std::meta::parameters_of(^^foo)[0]}; // int x
constexpr auto ry{std::meta::parameters_of(^^foo)[1]}; // double y = 3.14
static_assert(std::meta::type_of(rx) == ^^int);
static_assert(has_default_argument(rx) == false);
static_assert(std::meta::type_of(ry) == ^^double);
static_assert(has_default_argument(ry) == true);
int main() {}
See also
(C++26) |
obtains the parameters of the reflected function (function) |
(C++26) |
obtains the variable of the reflected function parameter in the function definition (function) |