|
Boost : |
Subject: Re: [boost] std::map::find() wrapper
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2011-05-05 10:53:21
Den 05-05-2011 16:48, Marsh Ray skrev:
> On 05/05/2011 05:52 AM, Thorsten Ottosen wrote:
>>
>> T* has the distict advantage that it is optimally efficient, even though
>> that optional<T&> might slightly be more type-safe.
>
> sizeof(T*) is guaranteed to be nonzero, and in practice is 4 or 8 bytes,
> whereas references are allowed to have no size at all.
Can you mention just one ABI where references are merely pointers?
> References have a very restricted set of allowed behaviors. Pointers are
> first-class values in their own right and this makes it impossible (in
> the general case) for a compiler to know if an object is being aliased
> by other pointers. You make the optimizer's job much, much harder by
> taking the address of something.
> It depends on a lot of factors of course, but there are cases where
> references are faster than pointers, so T* is not necessarily "optimally
> efficient".
perhaps, but in this case the reference /is/ a dereferenced pointer from
within a map.
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk