cref Function
Constructs a const reference_wrapper from an argument.
Syntax
template<class Ty>
reference_wrapper<const Ty> cref(const Ty& arg);
template<class Ty>
reference_wrapper<const Ty> cref(const reference_wrapper<Ty>& arg);
Parameters
Ty
The type of the argument to wrap.arg
The argument to wrap.
Remarks
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