Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 1999-08-19 11:56:13


Email seemed somewhat boring, until Csaba Szepesvari wrote:
>
>class foo {
>
>public:
> template <bool initialise = false>
> foo( value_type& value ) { if (initialise) Initialise(value); }
>
> template <bool initialise = false>
> foo() { if (initialise) Initialise(default_value); }
>};

A general problem with any conditional initialization scheme is that it
will always approach the level of encomberance as just initializing the
variable by hand. For instance, say you want the default (0)
initialization, with the above syntax, you'd write:

foo<true> f;

Compare that to a equivalent declaration given a different way of
handling the default:

foo2 f2(0); // or foo2 f2 = 0;

Of course, the latter would refer to a class definition like this:

class foo2
{
        foo() {}
        foo2(value_type v) : _v(v) {} // Or whatever the initialization is.
        ...
};

In general, if initialization is desired, it's easier to just go ahead
and initialize it than to tell the class that it should initialize itself.
One difference between the foo and foo2 approach is that foo2 doesn't
have the concept of a default initialization value, which I think is
a plus for foo2, since who can say what the default initialization value
is? Personally, I think it should be all bits set to 1 (just to be
obnoxious and moreso to accentuate the point).


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