/*---------------------------------------------------------------------------* Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #ifndef NN_UTIL_UTIL_STATICASSERT_H_ #define NN_UTIL_UTIL_STATICASSERT_H_ #ifdef __cplusplus namespace nn { template struct STATIC_ASSERTION_FAILURE; template <> struct STATIC_ASSERTION_FAILURE {}; namespace detail { template struct static_assert_test {}; } } #define NN_ASSERT_H_STRING_JOIN_(X, Y) NN_ASSERT_H_STRING_JOIN1_(X, Y) #define NN_ASSERT_H_STRING_JOIN1_(X, Y) X##Y /*! @def NN_STATIC_ASSERT @brief Evaluates whether the expression specified by argument is true at compile time. Compilation stops if it evaluates as false. */ #define NN_STATIC_ASSERT(exp) \ typedef ::nn::detail::static_assert_test< \ sizeof(::nn::STATIC_ASSERTION_FAILURE<(exp) != 0>) \ > NN_ASSERT_H_STRING_JOIN_(nn_static_assert_typedef_, __LINE__) /*! @def NN_STATIC_ASSERT_IS_POD @brief Evaluates whether the type specified by the argument is POD at compile time. Compilation stops if it is not POD. */ #define NN_STATIC_ASSERT_IS_POD(T) \ typedef union \ { \ T NN_ASSERT_H_STRING_JOIN_(nn_static_assert_is_pod_menber_, __LINE__); \ } \ NN_ASSERT_H_STRING_JOIN_(nn_static_assert_is_pod_, __LINE__) #else // __cplusplus #define NN_STATIC_ASSERT(expr) void NN_ASSERT_H_STRING_JOIN_##__FILE__##__LINE__(int arg[(expr) ? 1 : -1]) #define NN_STATIC_ASSERT_IS_POD(T) ((void)0) #endif #endif /* NN_UTIL_STATICASSERT_H_ */