Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2006-07-25 09:40:44

Anthony Williams wrote:
> Martin Wille <mw8329_at_[hidden]> writes:
>>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 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.
> How about the attached?
> The use of an inline function avoids the ODR violation, and the use of the
> detail::none_helper type with private constructors as the parameter ensures
> that noone can actually call the function, since they cannot construct a
> none_helper to pass. Likewise, they cannot define another function for use as
> none_t, since that function cannot construct the return value.
Now we're talking ;)

What I like about your solution is that it doesn't declare any type of
(const) variable at all so it won't have any problems with precompiled
headers in any compiler AFAICT.

In fact, with this solution there is no need to separate none_t from
none (need that arose only from the fact that 'none' caused problems in
precompiled headers in borland -at least- but none_t had to be defined

Just a comment... <iostream> doesn't need to be included.

Fernando Cacciola

Boost list run by bdawes at, gregod at, cpdaniel at, john at