Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-10-09 04:50:10


"David B. Held" wrote:
>
> "Daniel Frey" <daniel.frey_at_[hidden]> wrote in message
> news:3DA3EE01.2F19EED0_at_aixigo.de...
> > > [...]
> > > operator const ptr< const T >&() const
> > > {
> > > [Bad ugly reinterpret_cast-version snipped]
> > > [Insert your favorite static_cast-version here :)]
> > > }
> > >
> > I'm interested to hear whether this solves the original problem. If it
> > doesn't, please let me know, as this would mean that my own
> > pointer-classes might have an unsolved problem, too. :)
>
> This doesn't really do much for me. shared_ptr<> already has
> implicit conversion to shared_ptr<T const>, and the static_cast<>
> version can't avoid the creation of temporaries, so you may as well
> pay for the copy. And you still have to explicitly declare ptr<T const>

Why do you think that it will create a temporary? Consider:

[Pseudo-code ahead...]

void f( const ptr< const T >& p ) {
   std::cout << &p << std::endl;
}

int main() {
   ptr< T > q;
   std::cout << &q << std::endl;
   f( q );
}

The above gives me two identical addresses for my ptr-class. Obviously
it won't if I declare f like this:

void f( ptr< const T >& p ) ...

but this is - of course - intentional. Or am I still missing something?

Regards, Daniel

--
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk