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