#include<iostream>
#include<utility>
#include<tuple>
#include<functional>
using namespace std;
int main()
{
int i = 0;
auto p = make_pair(ref(i), ref(i++));
p.first++;
p.second++;
cout << "i = " << i << endl;
}
For example if I use ref()
like this, the compiler will say
use of deleted function 'void std::ref(const _Tp&&) [with _Tp = int]'
however if my code is following
#include<iostream>
#include<utility>
#include<tuple>
#include<functional>
using namespace std;
int main()
{
int i = 0;
auto p = make_pair(ref(i), ref(++i));
p.first++;
p.second++;
cout << "i = " << i << endl;
}
I will successfully get the output i = 3
, so I can't understand why I get so different answers.