std::meta::is_constructor, std::meta::is_default_constructor, std::meta::is_copy_constructor, std::meta::is_move_constructor
Defined in header <meta> | ||
|---|---|---|
consteval bool is_constructor( std::meta::info r ); | (1) | (since C++26) |
consteval bool is_default_constructor( std::meta::info r ); | (2) | (since C++26) |
consteval bool is_copy_constructor( std::meta::info r ); | (3) | (since C++26) |
consteval bool is_move_constructor( std::meta::info r ); | (4) | (since C++26) |
Returns true if r represents:
1) constructor,
3) copy constructor,
4) move constructor.
Otherwise returns false.
Parameters
| r | - | a reflection value |
Return value
true if r represents a specified constructor, otherwise false
Example
#include <iostream>
#include <memory>
#include <meta>
template <typename C>
requires(std::meta::is_class_type(^^C))
constexpr void print_constructors()
{
constexpr static auto class_name =
std::define_static_string(std::meta::display_string_of(^^C));
std::cout << "class " << class_name << '\n';
constexpr auto ctx = std::meta::access_context::unchecked();
constexpr static auto members =
std::define_static_array(std::meta::members_of(^^C, ctx));
template for (constexpr auto member : members)
{
if constexpr (std::meta::is_constructor(member))
{
std::cout << " " << std::meta::display_string_of(member) << " is ";
if constexpr (std::meta::is_default_constructor(member))
std::cout << "default ";
else if constexpr (std::meta::is_copy_constructor(member))
std::cout << "copy ";
else if constexpr (std::meta::is_move_constructor(member))
std::cout << "move ";
std::cout << "constructor\n";
}
}
}
struct C
{
C();
C(const C&);
C(C&&);
C(int);
};
int main()
{
print_constructors<C>();
print_constructors<std::weak_ptr<int>>();
}
Possible output:
class C C::C() is default constructor C::C(const C&) is copy constructor C::C(C&&) is move constructor C::C(int) is constructor class std::weak_ptr<int> constexpr std::weak_ptr<_Tp>::weak_ptr() [with _Tp = int] is default constructor std::weak_ptr<_Tp>::weak_ptr(const std::weak_ptr<_Tp>&) [with _Tp = int] is copy constructor std::weak_ptr<_Tp>::weak_ptr(std::weak_ptr<_Tp>&&) [with _Tp = int] is move constructor
See also
|
(C++26) | checks if reflection represents a function (function) |
|
(C++26) | checks if reflected type is a function type (function) |
|
(C++26) | checks if reflection represents a special member function (function) |
|
(C++26)(C++26)(C++26)(C++26) | checks if the reflected type can be invoked (as if by std::invoke) with the given argument types (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/is_constructor