std::meta::add_pointer
From cppreference.com
| Defined in header <meta>
|
||
consteval std::meta::info add_pointer( std::meta::info r );
|
(since C++26) | |
Adds a pointer to a reflected type T, represented by r.
Let R be a type the reflection of which is returned.
- If
Tis a reference type, thenRis a pointer to the referred type. - Otherwise, if
Tnames an object type, a function type that is not cv- or ref-qualified, or a (possibly cv-qualified)voidtype, thenRisT*. - Otherwise (if
Tis a cv- or ref-qualified function type),Requals toT.
Equivalent to return std::meta::dealias(^^std::add_pointer_t<T>);.
Parameters
| r | - | a reflection value |
Return value
A reflection of the type R as described above.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Example
Run this code
#include <meta>
static_assert
(""
&& (add_pointer(^^int) == ^^int*)
&& (add_pointer(^^int&) == ^^int*)
&& (add_pointer(^^int&&) == ^^int*)
&& (add_pointer(^^int*) == ^^int**)
&& (add_pointer(^^int**) == ^^int***)
&& (add_pointer(^^void) == ^^void*)
&& (add_pointer(^^const int) == ^^const int*)
&& (add_pointer(^^const int*) == ^^const int**)
&& (add_pointer(^^int* volatile) == ^^int* volatile*)
&& (add_pointer(^^void(void)) == ^^void(*)(void))
&& (add_pointer(^^int[1]) == ^^int(*)[1])
&& (remove_pointer(add_pointer(^^int&)) == remove_reference(^^int&))
);
struct S
{
void f_ref() & {}
void f_const() const {}
};
template<typename Func, typename Class>
consteval void ptr_to_member_func_cvref_test(Func Class::*)
{
static_assert(add_pointer(^^Class) == ^^Class*);
static_assert(add_pointer(^^Func) == ^^Func);
}
int main()
{
ptr_to_member_func_cvref_test(&S::f_ref);
ptr_to_member_func_cvref_test(&S::f_const);
}
See also
(C++26) |
checks if reflected type is a pointer type (function) |
(C++26) |
removes a pointer from reflected type (function) |
(C++11) |
adds a pointer to the given type (class template) |