Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2000-08-01 08:33:44


> Someone asked about usage at namespace scope in a header - this can
produce
> conflicts and this is covered in the docs along with a recomendation to
> insert the preconditions into their own namespace so that the scope of the
> declarations are unique to that header.

Only the 'enum' method produces conflicts. The 'typedef' method does not
[7.1.3/2]:
  typedef int Bob;
  typedef int Bob; // no error

> Finally with regard to template instantiation - regardless of whether an
> enum or typedef based approach is used, the declarations should be
> instantiated at the same time as the template regardless of whether they
> are used - both typedefs and enum's are descibed as declarations in the
> standard (not definitions), and it's only definitions which are
> instantiated on demand, all declarations should be instantiated with the
> template (anyhow that's my reading of it). However since Beman has
> encountered problems with unused declarations not being instantiated, I've
> put both versions in the header; the default is to use an enum, but
> defining BOOST_USE_TYPEDEF_PRECONDITION will switch over to the typedef
> version - it's there in case a particular compiler has a problem with the
> enum version.

enum's are actually definitions (as well as declarations) -- see
[3.1/2]-[3.1/3]. Based on [14.7.1/1], I think it would be valid for a
compiler to only declare the enumeration *names* on implicit instantiation,
and not evaluate their initializer values (thus by-passing the test) unless
those names were explicitly used elsewhere. This would be similar to nested
class definitions, where the name is declared on implicit instantiation of
the enclosing class, but the definition is not evaluated until the nested
class is referenced in a context that requires a complete type.

typedef's are declarations (and not definitions), and therefore *should*
work on conforming compilers (too bad we don't have one of those! :).

Hey -- maybe the "best" of both worlds:
  enum { enum__LINE__ = sizeof(...FAILURE<(cond)>) }; typedef
...test<(enum__LINE__)> typedef__LINE__

Make the typedef depend on the enum! Then, if a compiler chokes on the enum
*or* the typedef, it will fail.

OTOH, we would still have to keep the "make up your own file namespace when
using at namespace scope" thing (which I'm not really fond of).

        -Steve


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