Namespaces
Variants

std:: remove_reference

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
Definiert im Header <type_traits>
template < class T >
struct remove_reference ;
(seit C++11)

Wenn der Typ T ein Referenztyp ist, stellt er die Member-Typdefinition type bereit, die den durch T referenzierten Typ darstellt. Andernfalls ist type gleich T .

Wenn das Programm Spezialisierungen für std::remove_reference hinzufügt, ist das Verhalten undefiniert.

Inhaltsverzeichnis

Mitgliedertypen

Name Definition
type der von T referenzierte Typ oder T falls es keine Referenz ist

Hilfstypen

template < class T >
using remove_reference_t = typename remove_reference < T > :: type ;
(seit C++14)

Mögliche Implementierung

template<class T> struct remove_reference { typedef T type; };
template<class T> struct remove_reference<T&> { typedef T type; };
template<class T> struct remove_reference<T&&> { typedef T type; };

Beispiel

#include <iostream>
#include <type_traits>
int main()
{
    std::cout << std::boolalpha;
    std::cout << "std::remove_reference<int>::type is int? "
              << std::is_same<int, std::remove_reference<int>::type>::value << '\n';
    std::cout << "std::remove_reference<int&>::type is int? "
              << std::is_same<int, std::remove_reference<int&>::type>::value << '\n';
    std::cout << "std::remove_reference<int&&>::type is int? "
              << std::is_same<int, std::remove_reference<int&&>::type>::value << '\n';
    std::cout << "std::remove_reference<const int&>::type is const int? "
              << std::is_same<const int,
                              std::remove_reference<const int&>::type>::value << '\n';
}

Ausgabe:

std::remove_reference<int>::type is int? true
std::remove_reference<int&>::type is int? true
std::remove_reference<int&&>::type is int? true
std::remove_reference<const int&>::type is const int? true

Siehe auch

prüft, ob ein Typ entweder ein lvalue reference oder rvalue reference ist
(class template)
fügt einen lvalue oder rvalue Referenztyp zum gegebenen Typ hinzu
(class template)
kombiniert std::remove_cv und std::remove_reference
(class template)