Boost logo

Boost :

From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2001-07-17 03:33:06


Can you explain to a naive C++ user if this is
a compiler implementation problem,

or the way the user writes the constructor,

or if it is fundamental to the language.

Paul

PS If the latter it would seem a showstopper for using C++! :-(

> -----Original Message-----
> From: ross_at_[hidden] [mailto:ross_at_[hidden]]On Behalf Of
> Ross Smith
> Sent: Monday, July 16, 2001 9:43 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Static data vs. inline functions
>
>
> > From: Michael Kenniston [mailto:Msk_at_[hidden]]
> >
> > There are (at least) two ways of handling this:
> >
> > 1 - const T mything( init_value );
> > // ...
> > T x = mything;
> >
> > 2 - inline T mything() { return mything( init_value ); }
> > // ...
> > T x = mything();
> >
> > If the constructor for T is simple enough, either of
> > the two methods should allow a good compiler to optimize
> > well by inlining the init_value, so efficiency does not
> > appear to be a major consideration here.
> >
> > The first method is certainly more conventional, provides
> > a cleaner, more concise syntax without the extraneous "()",
> > and so is probably a little easier to understand and to use.
> > It also clearly expresses the "const" nature of mything.
>
> The big disadvantage of the first way is that initialisation isn't
> guaranteed to happen soon enough if T has a nontrivial constructor. IMHO
> this is a showstopper, far more important than any aesthetic
> considerations.
>
> --
> Ross Smith <ross.s_at_[hidden]> The Internet Group, Auckland, New Zealand
> ========================================================================
> "Unix has always lurked provocatively in the background of the operating
> system wars, like the Russian Army." -- Neal Stephenson
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


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