다음을 통해 공유


cref 함수

인수에서 상수 reference_wrapper를 생성합니다.

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.

예제

 

// 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); 
    } 
 
  

요구 사항

헤더: <기능>

네임스페이스: std

참고 항목

참조

ref 함수

reference_wrapper 클래스