Boost logo

Boost Users :

From: Bohdan (yg-boost-users_at_[hidden])
Date: 2002-09-25 17:52:37


"Mark Storer" <mstorer_at_[hidden]> wrote in message
news:E840F0B7E6189547BDB91DA8BF2228AB01625629_at_csmail.cardiff.com...
> Couldn't you do something along the lines of:
>
> template < typename PointerT, typeName RefereceT = &(*PointerT) >

Try to compile your code ...

> Only I think that's an address rather than a reference...
>
> How about:
>
> template < typename T >
> void f( T *ptr )
> {
> T &ref = *ptr;
> // ... do something with ref ...
> }

I didn't tell that PointerT is T*. You forgot about smart pointers and
iterators.

>
>
> And what do you have against "->"? I don't think a reference's "." is any
> faster than a pointer's "->", so that shouldn't be a concern... just
trying
> to save some knuckle grease?

I hope it was not offensive.

> I don't get it. (I'm getting a lot of
> practice with that phrase since I started digging into STL & Boost)

1) The problem is not related to raw pointers, but to smart ones.
2) I have nothing against "->".
3) ReferenceT is not always T&, it can also be some kind of proxy or simply
value type, or even void (for input iterator).
4) The original problem (for me) was in creating generic "dereference"
function:
<code>
template <typename PointerT >
ReferenceT dereference( PointerT ptr )
{
         return *ptr;
}
<\code>

Have you any ideas on how to distinguish ReferenceT in this case ?
---------------------------------------
Take a look at boost.devel for more details.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net