summaryrefslogtreecommitdiff
path: root/src/array_fun.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/array_fun.h')
-rw-r--r--src/array_fun.h20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/array_fun.h b/src/array_fun.h
index 7b047a19..87d14430 100644
--- a/src/array_fun.h
+++ b/src/array_fun.h
@@ -41,21 +41,15 @@
namespace aria2 {
// calculate length of array
-
-template<typename T, size_t N>
-char (&char_array_ref(T (&)[N]))[N];
-
template<typename T, size_t N>
-size_t arrayLength(T (&a)[N])
-{
- return sizeof(char_array_ref(a));
-}
+char (&char_array_ref_fun(T (&)[N]))[N];
+// For 0 length array
template<typename T>
-size_t arrayLength(T (&a)[0u])
-{
- return 0;
-}
+char (&char_array_ref_fun(T (&)[0u]))[0u];
+
+// To calculate size of array at compile time, we use macro here.
+#define A2_ARRAY_LEN(X) sizeof(char_array_ref_fun(X))
template<typename T, size_t N>
T* vbegin(T (&a)[N])
@@ -66,7 +60,7 @@ T* vbegin(T (&a)[N])
template<typename T, size_t N>
T* vend(T (&a)[N])
{
- return a+arrayLength(a);
+ return a+N;
}
template<typename T>