Add template based elems implementation

This commit is contained in:
Danny Robson 2011-06-21 20:16:39 +10:00
parent 8801023626
commit f924c990df
2 changed files with 6 additions and 2 deletions

View File

@ -1,12 +1,12 @@
#include "../float.hpp"
#include "../debug.hpp"
#include "../types.hpp"
#include <limits>
using namespace std;
#define elems(x) (sizeof(x) / sizeof(0[x]))
void
test_double (void) {

View File

@ -92,5 +92,9 @@ sign_cast (const typename sign_types<T>::with_sign v)
}
/// Returns the number of elements of a statically allocated array
template <typename T, size_t N>
size_t elems(T (&)[N])
{ return N; }
#endif // __TYPES_HPP