std::reference_wrapper的實(shí)例是一個對象蜘渣,但是會隱式的轉(zhuǎn)換為T&,因此std::reference_wrapper可以作為將把被其包裹類型為參數(shù)的函數(shù)的實(shí)參肺然∧韪祝【太拗口了,上原文:Instances of std::reference_wrapper are objects (they can be copied or stored in containers) but they are implicitly convertible to T&, so that they can be used as arguments with the functions that take the underlying type by reference.】际起。如下面的代碼中拾碌,函數(shù)func的參數(shù)類型為int,而傳遞給func的參數(shù)確是std::reference_wrapper<int>類型的對象街望。這個特性是保證reference_wrapper對象可以作為函數(shù)實(shí)參的關(guān)鍵校翔。
void func(int param){
std::cout << param << std::endl;
}
int a = 3;
std::reference_wrapper<int> ra = a;
func(ra);