Is this std::ref behaviour logical?

前端 未结 3 1230
独厮守ぢ
独厮守ぢ 2021-02-04 23:29

Consider this code:

#include 
#include 

int xx = 7;

template
void f1(T arg)
{
    arg += xx;
}

template

        
3条回答
  •  半阙折子戏
    2021-02-04 23:56

    reference_wrapper has operator = and a non explicit constructor, see documentation.

    So, even if it is surprising, it is the normal behaviour:

    f2 rebinds the local reference_wrapper to xx.

提交回复
热议问题