Boost logo

Boost :

From: Raffaele Romito (berserker_r_at_[hidden])
Date: 2006-02-24 04:31:39


What about a null_helper class?
This is my approach:

namespace boost {
static class null_helper
{
public:
   template <typename T>
   inline operator shared_ptr<T>() const { return shared_ptr<T>(); }

   template <typename T>
   inline operator T *() const { return 0; }
}null;
}

I find this very useful in samples like this:

class node
{
public:
   node(boost::shared_ptr<node> parent = boost::null, // instead of
boost::shared_ptr<node>()
           int *value = boost::null); //
no difference from ordinary pointers
};

Waiting for your feedback ;)

-------------

Raffaele Romito


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