summaryrefslogtreecommitdiff
path: root/ucoo/common.hh
diff options
context:
space:
mode:
authorNicolas Schodet2015-04-20 10:34:06 +0200
committerNicolas Schodet2019-10-07 00:44:50 +0200
commitdef502b1c9dba8d5e883e4a22c31a495b631e8a4 (patch)
tree0430a8432c4f4c3272b44e54b643a6b58f9bf2c3 /ucoo/common.hh
parent7a91c75e1cccf6b32b950100c3eb1a90402443d3 (diff)
Use C++11 feature to implement lengthof
Also disable warning about auto_ptr until it is changed.
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