When is the use of std::ref necessary?
One of the example where std::ref is necessary: void update(int &data) //expects a reference to int { data = 15; } int main() { int data = 10; // This doesn’t compile as the data value is copied when its reference is expected. //std::thread t1(update, data); std::thread t1(update, std::ref(data)); // works t1.join(); return 0; } … Read more