1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: util_StaticAssert.h 4 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 $Rev: 16675 $ 11 *--------------------------------------------------------------------------- 12 13 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 /* Please see man pages for details 39 40 41 42 43 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 /* Please see man pages for details 48 49 50 51 52 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