xmscore  1.0
carray.h File Reference

Utilities for c-style arrays. More...

Go to the source code of this file.

Macros

#define XM_COUNTOF(array)   (sizeof(::xms::caArraySizeHelper(array)))
 Returns the number of elements of a C/C++ array. More...
 

Functions

template<typename T , size_t N>
char(& xms::caArraySizeHelper (T(&array)[N]))[N]
 Helper to get the number of elements of a C/C++ array. More...
 

Detailed Description

Utilities for c-style arrays.

Definition in file carray.h.

Macro Definition Documentation

◆ XM_COUNTOF

#define XM_COUNTOF (   array)    (sizeof(::xms::caArraySizeHelper(array)))

Returns the number of elements of a C/C++ array.

It uses the XmArraySizeHelper template function.

Definition at line 15 of file carray.h.

Function Documentation

◆ caArraySizeHelper()

template<typename T , size_t N>
char(& xms::caArraySizeHelper ( T(&)  array[N]) )[N]

Helper to get the number of elements of a C/C++ array.

Parameters
arrayArray of data
Returns
array size

Found this here: http://blogs.msdn.com/the1/pages/210011.aspx. Note that "it doesn't work with types defined inside a function because _ArraySizeHelper expects a type that is accessible in the global scope." In the future could change to a C++11 version from http://www.g-truc.net/post-0708.html:

template <typename T, std::size_t N>
constexpr std::size_t caCountOf(T const (&)[N]) noexcept
{
return N;
}
#define XM_COUNTOF(array) (::xms::caCountOf(array)))