Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-01-07 16:33:28


>From: "David B. Held" <dheld_at_[hidden]>

> "Terje Slettebø" <tslettebo_at_[hidden]> wrote in message
> news:023f01c2b65a$1758e990$cb6c6f50_at_pc...
> > [...]
> > Thus, it prefers static const, if it's possible to initialise it
in-class,
> > on the given compiler, as allowed in the standard. However,
> > "C++ Templates: The Complete Guide" says about the difference
> > between the two (p. 304):
> > [...]
>
> I agree that Vandevoorde & Josuttis give a pretty compelling
> argument in favor of enum. I think it should be considered a
> best practice for Boost code, and BOOST_STATIC_CONSTANT
> should be deprecated, unless there is a reason that enum is
> inferior on some platforms.

Unfortunately, there is, but maybe not enough to offset the advantage of
enum (also what Daniel mentioned). Borland C++ Builder 6.0 doesn't handle
enum very well (this is also mentioned in the Boost integral constants
guideline). It occurs especially in more complex metaprogramming
expressions. Even if you use the other guidelines (fully qualify names,
etc.), it may still fail. I tested modifying Loki's Conversion template to
use enum rather than static const int (in the Borland port). The original
works, but the enum-version gave a cryptic compiler error. Simpler things,
like altering Length in the same way, worked fine.

In this respect it's kind of the opposite of MSVC 6, which doesn't handle
static const int (with in-class initialisation), at all.

Of course, it would be possible to change BOOST_STATIC_CONST to have the
opposite guideline as today - prefer enum unless the compile doesn't handle
it.

Regards,

Terje


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