summaryrefslogtreecommitdiff
path: root/src/array_fun.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-03-25 14:22:43 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-03-25 14:22:43 +0000
commit886f8ee58e1630f8abb1a1e57c6fbd5e9349d7e2 (patch)
treedfc53a1c108440440755a403c2d678c7f4d2b2ae /src/array_fun.h
parentf15d22b6195aeeef6a16bf2c5b5501d55b285349 (diff)
2010-03-25 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed arrayLength. Defined A2_ARRAY_LEN as macro to calculate size of array at compile time. * src/array_fun.h * test/BitfieldManTest.cc * test/BtPortMessageTest.cc * test/DHTRoutingTableDeserializerTest.cc * test/DHTRoutingTableSerializerTest.cc * test/DownloadHelperTest.cc * test/LongestSequencePieceSelectorTest.cc * test/MultiDiskAdaptorTest.cc * test/OptionParserTest.cc * test/PriorityPieceSelectorTest.cc * test/array_funTest.cc
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>