bx.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef BX_H_HEADER_GUARD
  6. #define BX_H_HEADER_GUARD
  7. #include <stdint.h> // uint32_t
  8. #include <stdlib.h> // size_t
  9. #include "platform.h"
  10. #include "macros.h"
  11. namespace bx
  12. {
  13. // http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
  14. template<typename T, size_t N> char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N];
  15. #define BX_COUNTOF(_x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(_x) )
  16. // Template for avoiding MSVC: C4127: conditional expression is constant
  17. template<bool>
  18. inline bool isEnabled()
  19. {
  20. return true;
  21. }
  22. template<>
  23. inline bool isEnabled<false>()
  24. {
  25. return false;
  26. }
  27. #define BX_ENABLED(_x) bx::isEnabled<!!(_x)>()
  28. inline bool ignoreC4127(bool _x)
  29. {
  30. return _x;
  31. }
  32. #define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) )
  33. } // namespace bx
  34. // Annoying C++0x stuff..
  35. namespace std { namespace tr1 {}; using namespace tr1; }
  36. #endif // BX_H_HEADER_GUARD