1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: util_Crc.cpp 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: 29096 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_UTIL_UTIL_MISC_H_ 17 #define NN_UTIL_UTIL_MISC_H_ 18 19 #include <nn/dbg.h> 20 21 #ifdef __cplusplus 22 23 namespace nn { namespace util { 24 25 // int array[10]; 26 // GetArraySize(array) -> 10 27 template <typename T, size_t Num> GetArraySize(T (& a)[Num])28 size_t GetArraySize(T (&a)[Num]) 29 { 30 NN_UNUSED_VAR(a); 31 return Num; 32 } 33 34 template <size_t V> 35 struct SizeTValue 36 { 37 enum { value = V }; 38 }; 39 40 // int array[10]; 41 // GetArraySizeT(array).value -> 10 42 template <typename T, size_t Num> GetArraySizeT(T (& a)[Num])43 const SizeTValue<Num>& GetArraySizeT(T (&a)[Num]) 44 { 45 NN_UNUSED_VAR(a); 46 return *reinterpret_cast<SizeTValue<Num>*>(1); 47 } 48 49 // int array[10]; 50 // sizeof(*NumOfElementsT(array)) -> 10 51 template <typename T, size_t Num> 52 char (*NumOfElementsT(T (&a)[Num]))[Num]; 53 }} 54 55 #endif // __cplusplus 56 57 58 #endif // ifndef NN_UTIL_UTIL_MISC_H_ 59