Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-08-07 10:20:37

Sascha Krissler <boost-dev_at_[hidden]> writes:

> Another solution would be to make a detail::generic_optional with all
> the operator foo and let optional inherit from it.
> That would be infinitesimal backward-incompatible ;)

I would use a simple metafunction to transform a type T into a type
with a null value:

  template <class T>
  struct nullable
       typedef boost::optional<T> type;

  template <class T>
  struct nullable<T*>
       typedef T* type;

  // other specializations for types with built-in NULL values

This way you're really not incurring any overhead for types that are
already nullable. Use free functions to smooth out any messy
interface differences due to the optional<T> wrapper on some types.


Dave Abrahams
Boost Consulting

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