|
Boost : |
From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-06-08 08:59:51
Just give it a better name, like null_pointer :)
On Fri, 8 Jun 2001, Chris Little wrote:
> Doug,
>
> Unfortunately adding nil will prevent anyone who is building Macintosh
> software from using Boost.
>
> On a Mac, nil is a preprocessor macro included in the system headers as a
> legacy of the days when the OS had a Pascal interface.
>
> Chris
>
> > -----Original Message-----
> > From: Douglas Gregor [mailto:gregod_at_[hidden]]
> > Sent: Thursday, June 07, 2001 9:06 PM
> > To: boost_at_[hidden]
> > Subject: [boost] boost::nil
> >
> >
> > Hello all,
> > The function library currently under review contains a
> > type 'nil_t' with an
> > instance 'nil'. It is a replacement for "0" or "NULL" in any
> > code. The
> > implementation is trivial, but it should probably be placed
> > in its own header
> > because it's usefulness extends beyond 'function'. The code is just:
> >
> > namespace boost {
> > struct nil_t
> > {
> > template<typename T> operator T*() const { return 0; }
> > template<typename T, typename U> operator T U::*() const
> > { return 0; }
> > };
> >
> > template<typename T>
> > inline bool operator==(const T* p, const nil_t&) { return !p; }
> >
> > template<typename T>
> > inline bool operator==(const nil_t&, const T* p) { return !p; }
> >
> > template<typename T>
> > inline bool operator!=(const T* p, const nil_t&) { return p; }
> >
> > template<typename T>
> > inline bool operator!=(const nil_t&, const T* p) { return p; }
> >
> > namespace {
> > nil_t nil;
> > }
> > }
> >
> > Advantages of 'nil' over NULL:
> > - NULL is not necessarily portable. Some C++ compilers
> > pick up bad
> > definitions of NULL from the system C libraries, making it useless.
> > - The type of NULL is unspecified, so it is impossible
> > to overload a
> > function based on it.
> >
> > Advantages of 'nil' over 0:
> > - 0 is an integer. It converts to pointer types but
> > doesn't convey much
> > information to the user.
> > - the type of 0 is "const int". Overloading a function
> > to take a null value
> > based on const int also allows any integer value to be passed
> > in, and the
> > error cannot be detected at compile-time.
> >
> > Doug
>
----------------------------------------------------------------------
Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
Ph.D. Candidate, IU B'ton email: jsiek_at_[hidden]
Summer Manager, AT&T Research phone: (973) 360-8185
----------------------------------------------------------------------
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk