Boost logo

Boost :

From: Michael Marcin (mike_at_[hidden])
Date: 2007-07-31 12:38:29


I have something like:

class A;
boost::array<A*,10> the_array;

std::fill( the_array.begin(), the_array.end(), NULL );

Which wont compile (at least under Visual Studio 2005) without a cast
for NULL... I've had this problem before and decided to try to find an
easy cast free expressive solution for it.

After a few minutes I came up with:

namespace detail
     struct null_ptr_impl
         template< typename T >
         operator T* () const { return static_cast<T*>(0); }
} // end namespace detail
const detail::null_ptr_impl null_ptr;

std::fill( the_array.begin(), the_array.end(), null_ptr );

Does this exist somewhere already? Is it a good solution?


Michael Marcin

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