
31 Jul
2007
31 Jul
'07
4:38 p.m.
Hello, 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? Thanks, Michael Marcin