countof.h 512 B

12345678910111213141516171819
  1. /*
  2. * Copyright 2010-2011 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef __BX_COUNTOF_H__
  6. #define __BX_COUNTOF_H__
  7. #include "bx.h"
  8. namespace bx
  9. {
  10. // http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
  11. template<typename T, size_t N> char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N];
  12. #define countof(x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(x) )
  13. } // namespace bx
  14. #endif // __BX_COUNTOF_H__