|
Boost : |
From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-04-13 05:46:30
Thorsten Ottosen wrote:
> "David Abrahams" <dave_at_[hidden]> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk