std::meta::add_lvalue_reference, std::meta::add_rvalue_reference
From cppreference.com
| Defined in header <meta>
|
||
consteval std::meta::info add_lvalue_reference( std::meta::info r );
|
(1) | (since C++26) |
consteval std::meta::info add_rvalue_reference( std::meta::info r );
|
(2) | (since C++26) |
Returns a reflection of an lvalue or rvalue reference type of the underlying type T represented by reflection r.
1) If
T is a function type that has no cv- or ref- qualifier or an object type, returns ^^T&. If T is an rvalue reference to some type U, then returns ^^U&. Otherwise, returns ^^T. Equivalent to
return std::meta::dealias(std::add_lvalue_reference_t<T>);.2) If
T is a function type that has no cv- or ref- qualifier or an object type, returns ^^T&&, otherwise returns ^^T. Equivalent to
return std::meta::dealias(std::add_rvalue_reference_t<T>);.Parameters
| r | - | a reflection value |
Return value
A reflection of the type represented by r with added lvalue or rvalue reference appropriately.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Notes
These type transformations honor reference collapsing rules:
add_lvalue_reference(^^T&)is^^T&,add_lvalue_reference(^^T&&)is^^T&,add_rvalue_reference(^^T&)is^^T&,add_rvalue_reference(^^T&&)is^^T&&.
The major difference to directly using ^^T& is that add_lvalue_reference(^^void) is ^^void, while ^^void& leads to a compilation error.
Example
Run this code
#include <meta>
static_assert
(""
&& std::meta::is_lvalue_reference_type(add_lvalue_reference(^^int))
&& std::meta::is_rvalue_reference_type(add_rvalue_reference(^^int))
&& !std::meta::is_lvalue_reference_type(add_rvalue_reference(^^void))
&& (add_lvalue_reference(^^int) == ^^int&)
&& (add_rvalue_reference(^^int) == ^^int&&)
&& (add_lvalue_reference(^^void) == ^^void)
);
int main() {}
See also
(C++26) |
checks if reflection represents either an lvalue reference or rvalue reference (function) |
(C++26) |
checks if reflection represents an lvalue reference (function) |
(C++26) |
checks if reflection represents an rvalue reference (function) |
| checks if the reflected entity is a ref qualified member function (function) | |
(C++26) |
removes a reference from reflected type (function) |
(C++26) |
combines meta::remove_cv and meta::remove_reference (function) |
(C++11)(C++11) |
adds an lvalue or rvalue reference to the given type (class template) |