1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: util_StaticAssert.h 4 5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 16675 $ 14 *---------------------------------------------------------------------------*/ 15 16 17 #ifndef NN_UTIL_UTIL_STATICASSERT_H_ 18 #define NN_UTIL_UTIL_STATICASSERT_H_ 19 20 21 #ifdef __cplusplus 22 23 namespace nn { namespace util { 24 25 template <bool> struct STATIC_ASSERTION_FAILURE; 26 27 template <> struct STATIC_ASSERTION_FAILURE<true> {}; 28 29 namespace detail { 30 template<int x> struct static_assert_test {}; 31 } 32 33 }} 34 35 #define NN_UTIL_STATICASSERT_H_STRING_JOIN_(X, Y) NN_UTIL_STATICASSERT_H_STRING_JOIN1_(X, Y) 36 #define NN_UTIL_STATICASSERT_H_STRING_JOIN1_(X, Y) X##Y 37 38 /*! 39 @def NN_STATIC_ASSERT 40 41 @brief 引数に指定した式が成立するかどうかをコンパイル時に評価します。 42 43 評価が false だった場合には、コンパイルを停止します。 44 */ 45 #define NN_STATIC_ASSERT(B) typedef ::nn::util::detail::static_assert_test<sizeof(::nn::util::STATIC_ASSERTION_FAILURE<(B) != 0>)> NN_UTIL_STATICASSERT_H_STRING_JOIN_(nn_util_static_assert_typedef_, __LINE__) 46 47 /*! 48 @def NN_STATIC_ASSERT_IS_POD 49 50 @brief 引数に指定した型が POD かどうかをコンパイル時に評価します。 51 52 POD でなかったには、コンパイルを停止します。 53 */ 54 #define NN_STATIC_ASSERT_IS_POD(T) typedef union { T NN_UTIL_STATICASSERT_H_STRING_JOIN_(nn_util_static_assert_is_pod_menber_, __LINE__); } NN_UTIL_STATICASSERT_H_STRING_JOIN_(nn_util_static_assert_is_pod_, __LINE__) 55 56 #else // __cplusplus 57 58 // #define NN_STATIC_ASSERT(expr) char NN_UTIL_STATICASSERT_H_STRING_JOIN_(nn_util_static_assert_dummy_, __LINE__)[(expr) ? 1 : -1] 59 #define NN_STATIC_ASSERT(expr) void NN_UTIL_STATICASSERT_H_STRING_JOIN_##__FILE__##__LINE__(int arg[(expr) ? 1 : -1]) 60 #define NN_STATIC_ASSERT_IS_POD(T) typedef void NN_UTIL_STATICASSERT_H_STRING_JOIN_(nn_util_static_assert_dummy_, __LINE__) 61 62 #endif 63 64 #define NN_COMPILER_ASSERT(x) NN_STATIC_ASSERT(x) 65 66 #endif /* NN_UTIL_STATICASSERT_H_ */ 67