Namespaces
Variants

std::meta::add_pointer

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
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 T is a reference type, then R is a pointer to the referred type.
  • Otherwise, if T names an object type, a function type that is not cv- or ref-qualified, or a (possibly cv-qualified) void type, then R is T*.
  • Otherwise (if T is a cv- or ref-qualified function type), R equals to T.

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

#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

checks if reflected type is a pointer type
(function) [edit]
removes a pointer from reflected type
(function) [edit]
adds a pointer to the given type
(class template) [edit]