|
Boost : |
From: Michael Marcin (mmarcin_at_[hidden])
Date: 2007-07-31 17:25:59
Michael Marcin wrote:
> Chris Fairles wrote:
>> This was a proposed library implementation of nullptr for c++0x from
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1601.pdf
>>
>> const // this is a const object...
>> class {
>> public:
>> template<class T> // convertible to any type
>> operator T*() const // of null non-member
>> { return 0; } // pointer...
>> template<class C, class T> // or any type of null
>> operator T C::*() const // member pointer...
>> { return 0; }
>> private:
>> void operator&() const; // whose address can't be taken
>> } nullptr = {}; // and whose name is nullptr
>>
>> Very similar to your impl although I think the static_cast in yours is
>> redundant. The standard says, 0, being an integral constant expression
>> that evaluates to zero, is a null pointer constant which is implicitly
>> convertible to a pointer type (4.10)
>>
>
> Cute. It might be nice to have this as a Boost utility library.
>
Interestingly that implementation fails for my test case because:
[temp.arg.type] 14.3.1 Template type arguments
2 A local type, a type with no linkage, an unnamed type or a type
compounded from any of these types shall
not be used as a template-argument for a template type-parameter.
So it must be named to be useful as an argument to say std::fill.
- Michael Marcin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk