Boost logo

Boost :

From: Martin Wille (mw8329_at_[hidden])
Date: 2006-07-25 02:57:54


Joe Gottman wrote:
> In order to avoid having an unnamed namespace inside a header file, none.hpp
> has been rewritten as
>
> namespace boost {
> none_t const none = ((none_t)0) ;
> } // namespace
>
> But if two source files contain none.hpp won't this violate the
> one-definition rule?

none would have internal linkage according to 7.1.5.1/2. So it wouldn't
violate the ODR. But a pointer to none from one translation unit would
differ from a pointer to none from a different TU.

> What's wrong with defining none_t and none as follows:
>
> namespace boost {
> enum none_t {none = 0};
> }
>
> This allows us to have a unique value boost::none of type boost::none_t that
> can be included in any number of source files without violating the ODR.

It would also avoid the pointer-to-none problem mentioned above, simply
because you can't create a pointer to an enumerator.

However, none_t instances of enumeration type would be implicitely
convertible to int, while the member pointer version of none_t isn't.

Regards,
m

Send instant messages to your online friends http://au.messenger.yahoo.com


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