1 /*---------------------------------------------------------------------------* 2 3 Copyright (C) Nintendo. All rights reserved. 4 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 11 *---------------------------------------------------------------------------*/ 12 13 14 #ifndef NN_UTIL_UTIL_STATICASSERT_H_ 15 #define NN_UTIL_UTIL_STATICASSERT_H_ 16 17 18 #ifdef __cplusplus 19 20 namespace nn 21 { 22 template <bool> struct STATIC_ASSERTION_FAILURE; 23 template <> struct STATIC_ASSERTION_FAILURE<true> {}; 24 25 namespace detail 26 { 27 template<int x> struct static_assert_test {}; 28 } 29 } 30 31 #define NN_ASSERT_H_STRING_JOIN_(X, Y) NN_ASSERT_H_STRING_JOIN1_(X, Y) 32 #define NN_ASSERT_H_STRING_JOIN1_(X, Y) X##Y 33 34 /*! 35 @def NN_STATIC_ASSERT 36 37 @brief Evaluates whether the expression specified by argument is <tt>true</tt> at compile time. 38 39 Compilation stops if it evaluates as <tt>false</tt>. 40 */ 41 #define NN_STATIC_ASSERT(exp) \ 42 typedef ::nn::detail::static_assert_test< \ 43 sizeof(::nn::STATIC_ASSERTION_FAILURE<(exp) != 0>) \ 44 > NN_ASSERT_H_STRING_JOIN_(nn_static_assert_typedef_, __LINE__) 45 46 /*! 47 @def NN_STATIC_ASSERT_IS_POD 48 49 @brief Evaluates whether the type specified by the argument is <tt>POD</tt> at compile time. 50 51 Compilation stops if it is not <tt>POD</tt>. 52 */ 53 #define NN_STATIC_ASSERT_IS_POD(T) \ 54 typedef union \ 55 { \ 56 T NN_ASSERT_H_STRING_JOIN_(nn_static_assert_is_pod_menber_, __LINE__); \ 57 } \ 58 NN_ASSERT_H_STRING_JOIN_(nn_static_assert_is_pod_, __LINE__) 59 60 #else // __cplusplus 61 62 #define NN_STATIC_ASSERT(expr) void NN_ASSERT_H_STRING_JOIN_##__FILE__##__LINE__(int arg[(expr) ? 1 : -1]) 63 #define NN_STATIC_ASSERT_IS_POD(T) ((void)0) 64 65 #endif 66 67 #endif /* NN_UTIL_STATICASSERT_H_ */ 68