static_assert.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  2. // vim:tabstop=4:shiftwidth=4:expandtab:
  3. /*
  4. * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net>
  5. *
  6. * This software is provided 'as-is', without any express or implied
  7. * warranty. In no event will the authors be held liable for any
  8. * damages arising from the use of this software.
  9. *
  10. * Permission is granted to anyone to use this software for any purpose,
  11. * including commercial applications, and to alter it and redistribute
  12. * it freely, subject to the following restrictions:
  13. *
  14. * 1. The origin of this software must not be misrepresented; you must
  15. * not claim that you wrote the original software. If you use this
  16. * software in a product, an acknowledgement in the product
  17. * documentation would be appreciated but is not required.
  18. * 2. Altered source versions must be plainly marked as such, and must
  19. * not be misrepresented as being the original software.
  20. * 3. This notice may not be removed or altered from any source
  21. * distribution.
  22. *
  23. * This file is part of Stones of Nvwa:
  24. * http://sourceforge.net/projects/nvwa
  25. *
  26. */
  27. /*!
  28. * \file static_assert.h
  29. * \ingroup QxMemLeak
  30. *
  31. * Template class to check validity duing compile time (adapted from Loki).
  32. *
  33. * \version 1.2, 2005/11/22
  34. * \author Wu Yongwei
  35. *
  36. */
  37. #ifndef QT_NO_DEBUG
  38. #ifndef _QX_MODE_RELEASE
  39. #if _QX_USE_MEM_LEAK_DETECTION
  40. #ifndef STATIC_ASSERT
  41. namespace qx {
  42. namespace memory {
  43. template <bool> struct __nvwa_compile_time_error;
  44. template <> struct __nvwa_compile_time_error<true> {};
  45. } // namespace memory
  46. } // namespace qx
  47. #define STATIC_ASSERT(_Expr, _Msg) \
  48. { \
  49. __nvwa_compile_time_error<((_Expr) != 0)> ERROR_##_Msg; \
  50. (void)ERROR_##_Msg; \
  51. }
  52. #endif // STATIC_ASSERT
  53. #endif // _QX_USE_MEM_LEAK_DETECTION
  54. #endif // _QX_MODE_RELEASE
  55. #endif // QT_NO_DEBUG