is_reference Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at is_reference Class.

Tests if type is a reference.

template <class Ty>  
struct is_reference;  

Parameters

Ty
The type to query.

An instance of the type predicate holds true if the type Ty is a reference to an object or to a function, otherwise it holds false.

// std__type_traits__is_reference.cpp   
// compile with: /EHsc   
#include <type_traits>   
#include <iostream>   
  
struct trivial   
    {   
    int val;   
    };   
  
int main()   
    {   
    std::cout << "is_reference<trivial> == " << std::boolalpha   
        << std::is_reference<trivial>::value << std::endl;   
    std::cout << "is_reference<trivial&> == " << std::boolalpha   
        << std::is_reference<trivial&>::value << std::endl;   
    std::cout << "is_reference<int()> == " << std::boolalpha   
        << std::is_reference<int()>::value << std::endl;   
    std::cout << "is_reference<int(&)()> == " << std::boolalpha   
        << std::is_reference<int(&)()>::value << std::endl;   
  
    return (0);   
    }  
  

is_reference<trivial> == false  
is_reference<trivial&> == true  
is_reference<int()> == false  
is_reference<int(&)()> == true  

Header: <type_traits>

Namespace: std

<type_traits>
is_pointer Class

Show: