Boost logo

Boost :

From: Ross Smith (ross.s_at_[hidden])
Date: 2001-07-16 15:42:33


> 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

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