From f924c990df8512710eaddfc39512eaf9e3ca4799 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 21 Jun 2011 20:16:39 +1000 Subject: [PATCH] Add template based elems implementation --- test/float.cpp | 4 ++-- types.hpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/float.cpp b/test/float.cpp index 81b8c45d..0a94ab3c 100644 --- a/test/float.cpp +++ b/test/float.cpp @@ -1,12 +1,12 @@ #include "../float.hpp" #include "../debug.hpp" +#include "../types.hpp" + #include using namespace std; -#define elems(x) (sizeof(x) / sizeof(0[x])) - void test_double (void) { diff --git a/types.hpp b/types.hpp index afee0e5a..dbbd9922 100644 --- a/types.hpp +++ b/types.hpp @@ -92,5 +92,9 @@ sign_cast (const typename sign_types::with_sign v) } +/// Returns the number of elements of a statically allocated array +template +size_t elems(T (&)[N]) + { return N; } #endif // __TYPES_HPP