Boost logo

Boost :

Subject: Re: [boost] std::map::find() wrapper
From: Marsh Ray (marsh_at_[hidden])
Date: 2011-05-05 10:48:20

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.

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

- Marsh

Boost list run by bdawes at, gregod at, cpdaniel at, john at