Frederick Gotham wrote:
It seems there's quite a few compilers out there that don't follow the C++
Standard when it comes to default-initialisation. Here's some quick test
code if anyone would like to try it out. So far, it seems to identify g++
and VC++ as K++ compilers.
BTW, I wrote these utils for K++ compilers :-). Of course, I got the
ideas all over the show... Array::zero is basically the one I use.
Unfortunately, I still have to handle mutliple subscript arrays.
namespace Array{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Returns the first item in an array - for use with algorithms.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
T* begin( T (&array)[N] )
{
return &array[0];
}
template <class T, std::size_t N>
const T* begin( const T (&array)[N] )
{
return &array[0];
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Returns the last item in an array - for use with algorithms.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
T* end( T (&array)[N] )
{
return (&array[0]+N);
}
template <class T, std::size_t N>
const T* end( const T (&array)[N] )
{
return (&array[0]+N);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Initialises an array over its entire range with <value>.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
void fill( T (&array)[N], const T& value )
{
std::fill( begin( array ), end( array ), value );
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Zero initialises an array over its entire range. Mostly applicable
to arrays of
// scalar types.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
void zero( T (&array)[N] )
{
std::fill( begin( array ), end( array ), T() );
}
}//namespace Array
Regards,
Werner