Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

cref Function

 

Constructs a const reference_wrapper from an argument.

template<class Ty>
    reference_wrapper<const Ty> cref(const Ty& arg);
template<class Ty>
    reference_wrapper<const Ty> cref(const reference_wrapper<Ty>& arg);

Ty

The type of the argument to wrap.

arg

The argument to wrap.

The first function returns reference_wrapper<const Ty>(arg.get()). You use it to wrap a const reference. The second function returns reference_wrapper<const Ty>(arg). You use it to rewrap a wrapped reference as a const reference.

Example

 

// std_tr1__functional__cref.cpp 
// compile with: /EHsc 
#include <functional> 
#include <iostream> 

int neg(int val) 
    { 
    return (-val); 
    } 

int main() 
    { 
    int i = 1; 

    std::cout << "i = " << i << std::endl; 
    std::cout << "cref(i) = " << std::cref(i) << std::endl; 
    std::cout << "cref(neg)(i) = " 
        << std::cref(&neg)(i) << std::endl; 

    return (0); 
    } 

i = 1
cref(i) = 1
cref(neg)(i) = -1

Requirements

Header: <functional>

Namespace: std

Show:
© 2017 Microsoft