class template
<type_traits>

std::add_lvalue_reference

template <class T> struct add_lvalue_reference;
Add lvalue reference
Obtains the lvalue reference type that refers to T.

The transformed type is aliased as member type add_lvalue_reference::type as follows:

  • If T is an object or function type, this is T&.
  • If T is an rvalue reference type, this is the lvalue reference that refers to the same type (e.g., for int&& this is int&).
  • Otherwise (i.e., T is void or already an lvalue reference), it is T unchanged.

Notice that this class merely obtains a type using another type as model, but it does not transform values or objects between those types.

Template parameters

T
A type.

Member types

member typedefinition
typeIf T is an object or function type: T&
If T is the rvalue reference type U&&: U&
Otherwise: T

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// add_lvalue_reference
#include <iostream>
#include <type_traits>

int main() {
  typedef std::add_lvalue_reference<int>::type A;    // int&
  typedef std::add_lvalue_reference<int&>::type B;   // int&
  typedef std::add_lvalue_reference<int&&>::type C;  // int&
  typedef std::add_lvalue_reference<int*>::type D;   // int*&

  std::cout << std::boolalpha;
  std::cout << "typedefs of int&:" << std::endl;
  std::cout << "A: " << std::is_same<int&,A>::value << std::endl;
  std::cout << "B: " << std::is_same<int&,B>::value << std::endl;
  std::cout << "C: " << std::is_same<int&,C>::value << std::endl;
  std::cout << "D: " << std::is_same<int&,D>::value << std::endl;

  return 0;
}


Output:
typedefs of int&:
A: true
B: true
C: true
D: false

See also

<type_traits>