Demonstrating the Problem
C++98 argument deduction rules don't always let you pass references to functions and algorithms, even when the arguments used are references. This problem is quite common in algorithms that forward their arguments to other callable entities or when constructors forward their arguments to base class constructors. The following code listing demonstrates this problem:

You'd expect that after calling g(), the value of n would change to 1. However, func() actually gets a copy of n, not a reference to n. Changing the signature of g() to:

template<class F, class T> void g(F f, T& t)

causes other problems (for instance, when calling g() with rvalue arguments) so this option is ruled out.

This phenomenon is known as the argument forwarding problem. It can lead to bugs that are very hard to detect, especially when working with high-level libraries of algorithms.

Containers manifest a similar problem. Containers of references can be useful in simulating heterogeneous containersa topic that I've discussed here more than once. However, it's impossible to create such containers in C++98. What may look like a container of references is actually an ordinary container of value objects. This happens because the references are implicitly replaced with value copies of the original argument:

While this behavior is desirable in many cases, there are times when you really need to store references in containers. Changing the template argument to int& certainly won't help because the generation of the vector <int&> specialization produces illegal code constructs such as int& & and int&*:

vector<int&> vi; //compilation error

Enter reference_wrapperstd::tr1::reference_wrapper<T> is a CopyConstructible and Assignable wrapper around a reference to an object of type T. It provides a conversion operator to T&, thereby enabling a function template to work on references unmodified. reference_wrapper can be used in places where argument deduction would not deduce a reference. For example, you can rewrite the previous vector example like this: