Subject: Re: [boost] [Gauge for interest] Surrogate template
From: Alan sinde (alantsd_at_[hidden])
Date: 2011-02-28 09:49:42
>> On 27/02/11 18:50, Alan sinde wrote:
>> Typically, this is achieve through surrogate::operator T&().
> This typically has a lot of really unwanted quirky side effect :/
True. Implicit conversion can be quirky. Mainly due to type safety is compromised.
But it is mostly limited to implicit conversion to pointer and built-in types.
Where in pointer case, user can erroneously delete or modify via returned pointers without any compilation errors and warnings.
This is why std::string never provide operator char const*().
However, that doesn't defeat the role of implicit conversion in this case.
In boost::surrogate<T>, its implicit interface require the wrapped objects to be derivative of T.
This implies, wrapped type and T cannot be pointer or built-in type.
Since surrogate::operator T&() returns reference to object,
it is hard for user to apply operator delete on it.
Also, it is sensible for user to write to the returned reference in this case.
After all, isn't conversion to wrapped object the whole point in wrapper pattern?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk