forked from rosebudai/OpenRCT2-Web
For reference see http://www.g-truc.net/post-0708.html and http://lxr.free-electrons.com/source/include/linux/kernel.h#L54 This will provide a type-safe mechanism for counting elements of array. If you try passing something which cannot be counted, compiler will frown at you right away.
21 lines
303 B
C++
21 lines
303 B
C++
#ifndef _UTIL_HPP_
|
|
#define _UTIL_HPP_
|
|
|
|
#include <cstdlib>
|
|
|
|
/**
|
|
* Common utility functions.
|
|
*/
|
|
namespace Util {
|
|
|
|
// Based on http://www.g-truc.net/post-0708.html
|
|
template <typename T, size_t N>
|
|
constexpr size_t CountOf(T const (&)[N]) noexcept
|
|
{
|
|
return N;
|
|
}
|
|
|
|
} // namespace Util
|
|
|
|
#endif // _UTIL_HPP_
|