
Thorsten Ottosen wrote:
"David Abrahams" <dave@boost-consulting.com> wrote in message
It works generically on lvalues and rvalues, so that if someone hands you a function object f, and some_algo is more efficient when it can modify its first argument in-place, you can do
some_algo( mutate_rvalue(f(),0), x );
yeah, definitely an improvement, although I wish there was some way of putting a static assertion in there. The new error message is a lot worse.
How about this: template<class T> struct cant_mutate_const_values { typedef int type; }; template<class T> struct cant_mutate_const_values<T const> { typedef typename cant_mutate_const_values::error type; }; template<class T> T& mutate_rvalue(T const& x) { return const_cast<T&>(x); } template<class T> T& mutate_rvalue(T& x, typename cant_mutate_const_values<T>::type = 0) { return x; } -- Daniel Wallin