summaryrefslogtreecommitdiff
path: root/ucoo/common.hh
diff options
context:
space:
mode:
Diffstat (limited to 'ucoo/common.hh')
-rw-r--r--ucoo/common.hh11
1 files changed, 8 insertions, 3 deletions
diff --git a/ucoo/common.hh b/ucoo/common.hh
index 282041f..505cf60 100644
--- a/ucoo/common.hh
+++ b/ucoo/common.hh
@@ -83,9 +83,14 @@ assert_perror (bool condition)
halt_perror ();
}
-} // namespace ucoo
+/// Get array length at compile time.
+template<class T, int N>
+constexpr int
+lengthof (T (&)[N])
+{
+ return N;
+}
-/// Get array length at compile time, must be a macro until c++11.
-#define lengthof(array) (sizeof (array) / sizeof((array)[0]))
+} // namespace ucoo
#endif // ucoo_common_h