Namespaces
Variants

std::meta::has_default_argument

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
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 F is a specialization of a templated function T, then returns true if there exists a declaration D of T that is reachable from a point in the evaluation context and D specifies a default argument for the parameter of T corresponding to P. Otherwise, returns false.
  • Otherwise, if there exists a declaration D of F that is reachable from a point in the evaluation context and D specifies a default argument for P, then returns true. Otherwise, returns false.

Parameters

r - a reflection value

Return value

true if r represents a function parameter that has a default argument; otherwise false.

Example

#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

obtains the parameters of the reflected function
(function) [edit]
obtains the variable of the reflected function parameter in the function definition
(function) [edit]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.