Namespaces
Variants
Views
Actions

Talk:cpp/utility/functional/ref

From cppreference.com

[edit] Example

The current example is not easy to understand from my point of view.

I would prefer the simpler above one inspired from wikipedia C++11 Wrapper_reference. The above example is also available on coliru.stacked-crooked.com. Oli (talk) 09:14, 21 July 2014 (PDT)

void increment( int &count )
{
  ++count;
}

template< class F, class A >
void intermediate( F func, A arg )
{
  func(arg);
}

int main()
{
  int i = 0;

  intermediate( increment, i );
  std::cout << "Without std::ref => i="<< i << '\n';

  intermediate( increment, std::ref(i) );
  std::cout << "Using   std::ref => i="<< i << '\n';
}
I could go either way. Or maybe this would be better with something even simpler? --Nate (talk) 15:28, 21 July 2014 (PDT)