Boost logo

Boost :

From: Christophe (christophe.avoinne_at_[hidden])
Date: 2002-06-04 03:35:18


Just a precision, I also use a similar method for a null pointer but with some
differences :

    extern class null_type
      {

        null_type (null_type const &);
        void operator &();

      public:
        null_type ()
          { }

        template< typename data_type > operator data_type *() const
          { return (data_type *)0; }

      } const null;

1) First I declare 'null' as being external, since it doesn't make a sense to
have a static copy of 'null' in each c++ files using 'null'. It is possible to
use extern because no method really use 'this' and public methods are always
inline functions (that is, 'this' is never referred at the end.)

2) Second I declare constructor and address operator '&' as private to be sure
none will try to use them. Maybe I should also declare the assign operator '='
as private ? is the fact that 'null' is defined as being 'const' enough to
prevent from using such operator ?

3) By the way, I always use gcc, so my code could not work for other
compilator... using with MSVC 6, it looks as if it reads this class well, but
when I desesperately try to use 'null' like in : pointer = null; well it fails
to use the templated conversation operator of 'null_type'.

Regards.

----- Original Message -----
From: Michal 'Sektor' Malecki <michalmal_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, June 04, 2002 8:51 AM
Subject: [boost] Propositions

> c) null
> In C++ you should not use NULL, because it's missing. However C++ would need
> some "universal null pointer" value. There is a very simple definition,
thanks to which
> you have a "null" called symbol, you can assign it into ANY pointer value (if
in some
> cases it would be impossible, you can use null.cast<TYPE>()), you can compare
> some pointer with it, you can pass this symbol as a function argument, if
overloaded
> for a pointer and an integer, the pointer version is choosen. You can also
provide another
> "null pointer value" implementation for some type (default is so-called NULL)
by
> overdefining the empty_pointer_value::cast<Type>().


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