diff --git a/ChangeLog b/ChangeLog index ab7d3e03..fbd68f1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2010-03-25 Tatsuhiro Tsujikawa + + Added vbegin() and vend() for fixed sized array. + * src/DownloadHandlerConstants.cc + * src/FeatureConfig.cc + * src/OptionHandlerFactory.cc + * src/ServerStat.cc + * src/TimeA2.cc + * src/XmlRpcMethod.cc + * src/array_fun.h + * src/download_helper.cc + * src/messageDigest.cc + * src/util.cc + * test/BittorrentHelperTest.cc + * test/DHTRoutingTableDeserializerTest.cc + * test/DHTRoutingTableSerializerTest.cc + * test/DefaultBtAnnounceTest.cc + * test/DefaultBtProgressInfoFileTest.cc + * test/DownloadContextTest.cc + * test/DownloadHelperTest.cc + * test/FeatureConfigTest.cc + * test/FeedbackURISelectorTest.cc + * test/HttpRequestTest.cc + * test/InOrderURISelectorTest.cc + * test/MSEHandshakeTest.cc + * test/MultiDiskAdaptorTest.cc + * test/MultiFileAllocationIteratorTest.cc + * test/PriorityPieceSelectorTest.cc + * test/RequestGroupManTest.cc + * test/UtilTest.cc + * test/XmlRpcMethodTest.cc + * test/a2algoTest.cc + * test/array_funTest.cc + 2010-03-24 Tatsuhiro Tsujikawa Simplified code using lastByteMask diff --git a/src/DownloadHandlerConstants.cc b/src/DownloadHandlerConstants.cc index deb4e0c2..3cd6ca6e 100644 --- a/src/DownloadHandlerConstants.cc +++ b/src/DownloadHandlerConstants.cc @@ -57,8 +57,7 @@ const std::vector& DownloadHandlerConstants::getMetalinkExtensions() { static const std::vector l - (&METALINK_EXTENSIONS[0], - &METALINK_EXTENSIONS[arrayLength(METALINK_EXTENSIONS)]); + (vbegin(METALINK_EXTENSIONS), vend(METALINK_EXTENSIONS)); return l; } @@ -66,24 +65,21 @@ const std::vector& DownloadHandlerConstants::getMetalinkContentTypes() { static const std::vector l - (&METALINK_CONTENT_TYPES[0], - &METALINK_CONTENT_TYPES[arrayLength(METALINK_CONTENT_TYPES)]); + (vbegin(METALINK_CONTENT_TYPES), vend(METALINK_CONTENT_TYPES)); return l; } const std::vector& DownloadHandlerConstants::getBtExtensions() { static const std::vector l - (&BT_EXTENSIONS[0], - &BT_EXTENSIONS[arrayLength(BT_EXTENSIONS)]); + (vbegin(BT_EXTENSIONS), vend(BT_EXTENSIONS)); return l; } const std::vector& DownloadHandlerConstants::getBtContentTypes() { static const std::vector l - (&BT_CONTENT_TYPES[0], - &BT_CONTENT_TYPES[arrayLength(BT_CONTENT_TYPES)]); + (vbegin(BT_CONTENT_TYPES), vend(BT_CONTENT_TYPES)); return l; } diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc index 66dfcf23..6f93449a 100644 --- a/src/FeatureConfig.cc +++ b/src/FeatureConfig.cc @@ -117,7 +117,7 @@ FeatureConfig::FeatureConfig() { FeatureMap::value_type(FEATURE_FIREFOX3_COOKIE, FIREFOX3_COOKIE_ENABLED), }; - _features.insert(&featureArray[0], &featureArray[arrayLength(featureArray)]); + _features.insert(vbegin(featureArray), vend(featureArray)); } SharedHandle FeatureConfig::getInstance() diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index a2d514ac..ee871898 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -210,7 +210,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() V_SELECT, #endif // !HAVE_EPOLL std::vector - (¶ms[0],¶ms[arrayLength(params)]))); + (vbegin(params), vend(params)))); op->addTag(TAG_ADVANCED); handlers.push_back(op); } @@ -286,8 +286,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() TEXT_LOG_LEVEL, V_DEBUG, std::vector - (¶ms[0], - ¶ms[arrayLength(params)]))); + (vbegin(params), vend(params)))); op->addTag(TAG_ADVANCED); handlers.push_back(op); } @@ -649,7 +648,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() TEXT_URI_SELECTOR, V_FEEDBACK, std::vector - (¶ms[0], ¶ms[arrayLength(params)]))); + (vbegin(params), vend(params)))); op->addTag(TAG_FTP); op->addTag(TAG_HTTP); handlers.push_back(op); @@ -1379,7 +1378,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() TEXT_METALINK_PREFERRED_PROTOCOL, V_NONE, std::vector - (¶ms[0], ¶ms[arrayLength(params)]))); + (vbegin(params), vend(params)))); op->addTag(TAG_METALINK); handlers.push_back(op); } diff --git a/src/ServerStat.cc b/src/ServerStat.cc index 034ff34a..b5c9a0a5 100644 --- a/src/ServerStat.cc +++ b/src/ServerStat.cc @@ -167,13 +167,11 @@ void ServerStat::setStatus(STATUS status) void ServerStat::setStatus(const std::string& status) { - size_t len = arrayLength(STATUS_STRING); - const std::string* p = std::find(&STATUS_STRING[0], - &STATUS_STRING[len], + const std::string* p = std::find(vbegin(STATUS_STRING), vend(STATUS_STRING), status); - if(p != &STATUS_STRING[len]) { + if(p != vend(STATUS_STRING)) { _status = static_cast(ServerStat::OK+ - std::distance(&STATUS_STRING[0], p)); + std::distance(vbegin(STATUS_STRING), p)); } } diff --git a/src/TimeA2.cc b/src/TimeA2.cc index 8ddd9416..405c3a41 100644 --- a/src/TimeA2.cc +++ b/src/TimeA2.cc @@ -212,7 +212,7 @@ Time Time::parseHTTPDate(const std::string& datetime) &parseRFC850Ext, }; for(Time (**funcsp)(const std::string&) = &funcs[0]; - funcsp != &funcs[arrayLength(funcs)]; ++funcsp) { + funcsp != vend(funcs); ++funcsp) { Time t = (*funcsp)(datetime); if(t.good()) { return t; diff --git a/src/XmlRpcMethod.cc b/src/XmlRpcMethod.cc index 35e89bd1..0a6e7f0c 100644 --- a/src/XmlRpcMethod.cc +++ b/src/XmlRpcMethod.cc @@ -147,8 +147,7 @@ const std::set& listChangeableOptions() PREF_MAX_DOWNLOAD_LIMIT, PREF_MAX_UPLOAD_LIMIT }; - static std::set options - (&OPTIONS[0], &OPTIONS[arrayLength(OPTIONS)]); + static std::set options(vbegin(OPTIONS), vend(OPTIONS)); return options; } @@ -173,8 +172,7 @@ const std::set& listChangeableGlobalOptions() PREF_MAX_OVERALL_DOWNLOAD_LIMIT, PREF_MAX_CONCURRENT_DOWNLOADS, }; - static std::set options - (&OPTIONS[0], &OPTIONS[arrayLength(OPTIONS)]); + static std::set options(vbegin(OPTIONS), vend(OPTIONS)); return options; } diff --git a/src/array_fun.h b/src/array_fun.h index d70ad367..7b047a19 100644 --- a/src/array_fun.h +++ b/src/array_fun.h @@ -57,6 +57,18 @@ size_t arrayLength(T (&a)[0u]) return 0; } +template +T* vbegin(T (&a)[N]) +{ + return a; +} + +template +T* vend(T (&a)[N]) +{ + return a+arrayLength(a); +} + template class array_ptr { private: diff --git a/src/download_helper.cc b/src/download_helper.cc index 43b1a86b..531b09e7 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -155,9 +155,7 @@ const std::set& listRequestOptions() PREF_REALTIME_CHUNK_CHECKSUM }; static std::set requestOptions - (&REQUEST_OPTIONS[0], - &REQUEST_OPTIONS[arrayLength(REQUEST_OPTIONS)]);; - + (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS)); return requestOptions; } diff --git a/src/messageDigest.cc b/src/messageDigest.cc index 0043c138..ce860f89 100644 --- a/src/messageDigest.cc +++ b/src/messageDigest.cc @@ -89,8 +89,7 @@ static const DigestAlgoMap& getDigestAlgos() ("sha256", DigestAlgoEntry(GCRY_MD_SHA256, STRENGTH_SHA_256)), #endif // HAVE_LIBGCRYPT }; - static const DigestAlgoMap algomap - (&digests[0], &digests[arrayLength(digests)]); + static const DigestAlgoMap algomap(vbegin(digests), vend(digests)); return algomap; } diff --git a/src/util.cc b/src/util.cc index fc90b7c8..abeb6b20 100644 --- a/src/util.cc +++ b/src/util.cc @@ -256,16 +256,14 @@ bool inRFC3986ReservedChars(const char c) ':' , '/' , '?' , '#' , '[' , ']' , '@', '!' , '$' , '&' , '\'' , '(' , ')', '*' , '+' , ',' , ';' , '=' }; - return std::find(&reserved[0], &reserved[arrayLength(reserved)], c) != - &reserved[arrayLength(reserved)]; + return std::find(vbegin(reserved), vend(reserved), c) != vend(reserved); } bool inRFC3986UnreservedChars(const char c) { static const char unreserved[] = { '-', '.', '_', '~' }; return isAlpha(c) || isDigit(c) || - std::find(&unreserved[0], &unreserved[arrayLength(unreserved)], c) != - &unreserved[arrayLength(unreserved)]; + std::find(vbegin(unreserved), vend(unreserved), c) != vend(unreserved); } bool inRFC2978MIMECharset(const char c) @@ -276,8 +274,7 @@ bool inRFC2978MIMECharset(const char c) '`', '{', '}', '~' }; return isAlpha(c) || isDigit(c) || - std::find(&chars[0], &chars[arrayLength(chars)], c) != - &chars[arrayLength(chars)]; + std::find(vbegin(chars), vend(chars), c) != vend(chars); } bool inRFC2616HttpToken(const char c) @@ -287,8 +284,7 @@ bool inRFC2616HttpToken(const char c) '^', '_', '`', '|', '~' }; return isAlpha(c) || isDigit(c) || - std::find(&chars[0], &chars[arrayLength(chars)], c) != - &chars[arrayLength(chars)]; + std::find(vbegin(chars), vend(chars), c) != vend(chars); } std::string percentEncode(const unsigned char* target, size_t len) { @@ -1245,10 +1241,8 @@ public: // We don't escape '/' because we use it as a path separator. static const char WIN_INVALID_PATH_CHARS[] = { '"', '*', ':', '<', '>', '?', '\\', '|' }; - if(std::find(&WIN_INVALID_PATH_CHARS[0], - &WIN_INVALID_PATH_CHARS[arrayLength(WIN_INVALID_PATH_CHARS)], - c) != - &WIN_INVALID_PATH_CHARS[arrayLength(WIN_INVALID_PATH_CHARS)]) { + if(std::find(vbegin(WIN_INVALID_PATH_CHARS), vend(WIN_INVALID_PATH_CHARS), + c) != vend(WIN_INVALID_PATH_CHARS)) { return _repChar; } #endif // __MINGW32__ diff --git a/test/BittorrentHelperTest.cc b/test/BittorrentHelperTest.cc index 087ee709..28ae4844 100644 --- a/test/BittorrentHelperTest.cc +++ b/test/BittorrentHelperTest.cc @@ -317,7 +317,7 @@ void BittorrentHelperTest::testComputeFastSet() std::vector fastSet; computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize); size_t ans[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 }; - std::vector ansSet(&ans[0], &ans[arrayLength(ans)]); + std::vector ansSet(vbegin(ans), vend(ans)); CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin())); } ipaddr = "10.0.0.1"; @@ -325,7 +325,7 @@ void BittorrentHelperTest::testComputeFastSet() std::vector fastSet; computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize); size_t ans[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 }; - std::vector ansSet(&ans[0], &ans[arrayLength(ans)]); + std::vector ansSet(vbegin(ans), vend(ans)); CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin())); } // See when pieces < fastSetSize @@ -334,7 +334,7 @@ void BittorrentHelperTest::testComputeFastSet() std::vector fastSet; computeFastSet(fastSet, ipaddr, numPieces, infoHash, fastSetSize); size_t ans[] = { 8, 6, 7, 5, 1, 4, 0, 2, 3 }; - std::vector ansSet(&ans[0], &ans[arrayLength(ans)]); + std::vector ansSet(vbegin(ans), vend(ans)); CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet.begin())); } } diff --git a/test/DHTRoutingTableDeserializerTest.cc b/test/DHTRoutingTableDeserializerTest.cc index a7f81f6c..211800c6 100644 --- a/test/DHTRoutingTableDeserializerTest.cc +++ b/test/DHTRoutingTableDeserializerTest.cc @@ -43,8 +43,7 @@ void DHTRoutingTableDeserializerTest::testDeserialize() nodesSrc[i]->setPort(6881+i); } nodesSrc[1]->setIPAddress("non-numerical-name"); - std::vector > nodes - (&nodesSrc[0], &nodesSrc[arrayLength(nodesSrc)]); + std::vector > nodes(vbegin(nodesSrc), vend(nodesSrc)); DHTRoutingTableSerializer s; s.setLocalNode(localNode); diff --git a/test/DHTRoutingTableSerializerTest.cc b/test/DHTRoutingTableSerializerTest.cc index 3c81e3df..4ca188a0 100644 --- a/test/DHTRoutingTableSerializerTest.cc +++ b/test/DHTRoutingTableSerializerTest.cc @@ -1,4 +1,11 @@ #include "DHTRoutingTableSerializer.h" + +#include +#include +#include + +#include + #include "Exception.h" #include "util.h" #include "DHTNode.h" @@ -6,10 +13,6 @@ #include "DHTConstants.h" #include "bittorrent_helper.h" #include "a2netcompat.h" -#include -#include -#include -#include namespace aria2 { @@ -40,8 +43,7 @@ void DHTRoutingTableSerializerTest::testSerialize() nodesSrc[i]->setPort(6881+i); } nodesSrc[1]->setIPAddress("non-numerical-name"); - std::vector > nodes - (&nodesSrc[0], &nodesSrc[arrayLength(nodesSrc)]); + std::vector > nodes(vbegin(nodesSrc), vend(nodesSrc)); DHTRoutingTableSerializer s; s.setLocalNode(localNode); diff --git a/test/DefaultBtAnnounceTest.cc b/test/DefaultBtAnnounceTest.cc index 344bbf9b..ff712ce7 100644 --- a/test/DefaultBtAnnounceTest.cc +++ b/test/DefaultBtAnnounceTest.cc @@ -58,7 +58,7 @@ public: _dctx.reset(new DownloadContext(pieceLength, totalLength)); BDE torrentAttrs = BDE::dict(); torrentAttrs[bittorrent::INFO_HASH] = - std::string(&infoHash[0], &infoHash[arrayLength(infoHash)]); + std::string(vbegin(infoHash), vend(infoHash)); _dctx->setAttribute(bittorrent::BITTORRENT, torrentAttrs); bittorrent::setStaticPeerId(peerId); @@ -282,7 +282,7 @@ void DefaultBtAnnounceTest::testURLOrderInStoppedEvent() "http://localhost2/announce" }; BDE announceList = BDE::list(); - announceList << createAnnounceTier(&urls[0], &urls[arrayLength(urls)]); + announceList << createAnnounceTier(vbegin(urls), vend(urls)); setAnnounceList(_dctx, announceList); DefaultBtAnnounce btAnnounce(_dctx, _option); @@ -312,7 +312,7 @@ void DefaultBtAnnounceTest::testURLOrderInCompletedEvent() "http://localhost2/announce" }; BDE announceList = BDE::list(); - announceList << createAnnounceTier(&urls[0], &urls[arrayLength(urls)]); + announceList << createAnnounceTier(vbegin(urls), vend(urls)); setAnnounceList(_dctx, announceList); DefaultBtAnnounce btAnnounce(_dctx, _option); diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc index 0c6d2106..dcf49f32 100644 --- a/test/DefaultBtProgressInfoFileTest.cc +++ b/test/DefaultBtProgressInfoFileTest.cc @@ -72,14 +72,13 @@ public: _dctx.reset(new DownloadContext()); BDE torrentAttrs = BDE::dict(); torrentAttrs[bittorrent::INFO_HASH] = - std::string(&infoHash[0], &infoHash[arrayLength(infoHash)]); + std::string(vbegin(infoHash), vend(infoHash)); _dctx->setAttribute(bittorrent::BITTORRENT, torrentAttrs); _dctx->setDir(_option->get(PREF_DIR)); const SharedHandle fileEntries[] = { SharedHandle(new FileEntry("/path/to/file",totalLength,0)) }; - _dctx->setFileEntries(&fileEntries[0], - &fileEntries[arrayLength(fileEntries)]); + _dctx->setFileEntries(vbegin(fileEntries), vend(fileEntries)); _dctx->setPieceLength(pieceLength); _peerStorage.reset(new MockPeerStorage()); _btRuntime.reset(new BtRuntime()); diff --git a/test/DownloadContextTest.cc b/test/DownloadContextTest.cc index a68c0f7e..ba9a3502 100644 --- a/test/DownloadContextTest.cc +++ b/test/DownloadContextTest.cc @@ -39,8 +39,7 @@ void DownloadContextTest::testFindFileEntryByOffset() SharedHandle(new FileEntry("file5",3000,3000)), SharedHandle(new FileEntry("file6",0,6000)) }; - ctx.setFileEntries(&fileEntries[0], - &fileEntries[arrayLength(fileEntries)]); + ctx.setFileEntries(vbegin(fileEntries), vend(fileEntries)); CPPUNIT_ASSERT_EQUAL(std::string("file1"), ctx.findFileEntryByOffset(0)->getPath()); diff --git a/test/DownloadHelperTest.cc b/test/DownloadHelperTest.cc index 17fde9b7..1384c0fd 100644 --- a/test/DownloadHelperTest.cc +++ b/test/DownloadHelperTest.cc @@ -69,7 +69,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri() "http://bravo/file", "http://charlie/file" }; - std::vector uris(&array[0], &array[arrayLength(array)]); + std::vector uris(vbegin(array), vend(array)); _option->put(PREF_SPLIT, "3"); _option->put(PREF_DIR, "/tmp"); _option->put(PREF_OUT, "file.out"); @@ -157,7 +157,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_parameterized() "http://{alpha, bravo}/file", "http://charlie/file" }; - std::vector uris(&array[0], &array[arrayLength(array)]); + std::vector uris(vbegin(array), vend(array)); _option->put(PREF_SPLIT, "3"); _option->put(PREF_DIR, "/tmp"); _option->put(PREF_OUT, "file.out"); @@ -193,7 +193,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent() "http://bravo/file", "http://charlie/file" }; - std::vector uris(&array[0], &array[arrayLength(array)]); + std::vector uris(vbegin(array), vend(array)); _option->put(PREF_SPLIT, "3"); _option->put(PREF_DIR, "/tmp"); _option->put(PREF_OUT, "file.out"); @@ -241,7 +241,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink() "http://charlie/file", "test.xml" }; - std::vector uris(&array[0], &array[arrayLength(array)]); + std::vector uris(vbegin(array), vend(array)); _option->put(PREF_SPLIT, "3"); _option->put(PREF_METALINK_SERVERS, "2"); _option->put(PREF_DIR, "/tmp"); @@ -329,7 +329,7 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent() "http://charlie/file" }; - std::vector auxURIs(&array[0], &array[arrayLength(array)]); + std::vector auxURIs(vbegin(array), vend(array)); _option->put(PREF_SPLIT, "5"); _option->put(PREF_TORRENT_FILE, "test.torrent"); _option->put(PREF_DIR, "/tmp"); diff --git a/test/FeatureConfigTest.cc b/test/FeatureConfigTest.cc index 32debd2e..1a58152c 100644 --- a/test/FeatureConfigTest.cc +++ b/test/FeatureConfigTest.cc @@ -89,7 +89,7 @@ void FeatureConfigTest::testFeatureSummary() { std::string featuresString; const std::string delim(", "); - std::for_each(&features[0], &features[arrayLength(features)], + std::for_each(vbegin(features), vend(features), StringAppend(featuresString, delim)); // USE util::trimSelf(featureString); featuresString = util::trim(featuresString, delim); diff --git a/test/FeedbackURISelectorTest.cc b/test/FeedbackURISelectorTest.cc index b2e9c224..2785b398 100644 --- a/test/FeedbackURISelectorTest.cc +++ b/test/FeedbackURISelectorTest.cc @@ -34,7 +34,7 @@ public: "http://bravo/file" }; std::vector uris; - uris.assign(&urisSrc[0], &urisSrc[arrayLength(urisSrc)]); + uris.assign(vbegin(urisSrc), vend(urisSrc)); _fileEntry.setUris(uris); diff --git a/test/HttpRequestTest.cc b/test/HttpRequestTest.cc index 8160637d..5ef923f0 100644 --- a/test/HttpRequestTest.cc +++ b/test/HttpRequestTest.cc @@ -690,8 +690,7 @@ void HttpRequestTest::testAddAcceptType() httpRequest.disableContentEncoding(); httpRequest.setRequest(request); httpRequest.setAuthConfigFactory(_authConfigFactory, _option.get()); - httpRequest.addAcceptType(&acceptTypes[0], - &acceptTypes[arrayLength(acceptTypes)]); + httpRequest.addAcceptType(vbegin(acceptTypes), vend(acceptTypes)); std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" diff --git a/test/InOrderURISelectorTest.cc b/test/InOrderURISelectorTest.cc index e9b499ad..cd6d6300 100644 --- a/test/InOrderURISelectorTest.cc +++ b/test/InOrderURISelectorTest.cc @@ -28,7 +28,7 @@ public: "http://bravo/file" }; std::vector uris; - uris.assign(&urisSrc[0], &urisSrc[arrayLength(urisSrc)]); + uris.assign(vbegin(urisSrc), vend(urisSrc)); _fileEntry.setUris(uris); diff --git a/test/MSEHandshakeTest.cc b/test/MSEHandshakeTest.cc index 4304006f..3ec8ab51 100644 --- a/test/MSEHandshakeTest.cc +++ b/test/MSEHandshakeTest.cc @@ -35,7 +35,7 @@ public: memset(infoHash, 0, sizeof(infoHash)); BDE torrentAttrs = BDE::dict(); torrentAttrs[bittorrent::INFO_HASH] = - std::string(&infoHash[0], &infoHash[arrayLength(infoHash)]); + std::string(vbegin(infoHash), vend(infoHash)); _dctx->setAttribute(bittorrent::BITTORRENT, torrentAttrs); } diff --git a/test/MultiDiskAdaptorTest.cc b/test/MultiDiskAdaptorTest.cc index cac67471..4aa10a4e 100644 --- a/test/MultiDiskAdaptorTest.cc +++ b/test/MultiDiskAdaptorTest.cc @@ -68,8 +68,7 @@ std::vector > createEntries() { // *** file6 // |file7 // ** file8 - std::vector > entries(&array[0], - &array[arrayLength(array)]); + std::vector > entries(vbegin(array), vend(array)); for(std::vector >::const_iterator i = entries.begin(); i != entries.end(); ++i) { File((*i)->getPath()).remove(); @@ -376,7 +375,7 @@ void MultiDiskAdaptorTest::testCutTrailingGarbage() createFile(entries[i]->getPath(), entries[i]->getLength()+100); } std::vector > fileEntries - (&entries[0], &entries[arrayLength(entries)]); + (vbegin(entries), vend(entries)); MultiDiskAdaptor adaptor; adaptor.setFileEntries(fileEntries.begin(), fileEntries.end()); @@ -405,7 +404,7 @@ void MultiDiskAdaptorTest::testSize() createFile(entries[i]->getPath(), entries[i]->getLength()); } std::vector > fileEntries - (&entries[0], &entries[arrayLength(entries)]); + (vbegin(entries), vend(entries)); MultiDiskAdaptor adaptor; adaptor.setFileEntries(fileEntries.begin(), fileEntries.end()); @@ -435,7 +434,7 @@ void MultiDiskAdaptorTest::testUtime() entries[2]->setRequested(false); std::vector > fileEntries - (&entries[0], &entries[arrayLength(entries)]); + (vbegin(entries), vend(entries)); MultiDiskAdaptor adaptor; adaptor.setFileEntries(fileEntries.begin(), fileEntries.end()); diff --git a/test/MultiFileAllocationIteratorTest.cc b/test/MultiFileAllocationIteratorTest.cc index fa5ddfbe..83dcb189 100644 --- a/test/MultiFileAllocationIteratorTest.cc +++ b/test/MultiFileAllocationIteratorTest.cc @@ -64,7 +64,7 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries() createFile(storeDir+std::string("/file4"), 0); SharedHandle diskAdaptor(new MultiDiskAdaptor()); - diskAdaptor->setFileEntries(&fs[0], &fs[arrayLength(fs)]); + diskAdaptor->setFileEntries(vbegin(fs), vend(fs)); diskAdaptor->setPieceLength(1024); diskAdaptor->openFile(); diff --git a/test/PriorityPieceSelectorTest.cc b/test/PriorityPieceSelectorTest.cc index 58872083..0bd7eda4 100644 --- a/test/PriorityPieceSelectorTest.cc +++ b/test/PriorityPieceSelectorTest.cc @@ -30,7 +30,7 @@ void PriorityPieceSelectorTest::testSelect() } PriorityPieceSelector selector (SharedHandle(new MockPieceSelector())); - selector.setPriorityPiece(&A[0], &A[arrayLength(A)]); + selector.setPriorityPiece(vbegin(A), vend(A)); size_t index; CPPUNIT_ASSERT(selector.select(index, bf.getBitfield(), bf.countBlock())); diff --git a/test/RequestGroupManTest.cc b/test/RequestGroupManTest.cc index 12cc3c3f..dff34341 100644 --- a/test/RequestGroupManTest.cc +++ b/test/RequestGroupManTest.cc @@ -121,7 +121,7 @@ void RequestGroupManTest::testChangeReservedGroupPosition() SharedHandle(new RequestGroup(_option)), SharedHandle(new RequestGroup(_option)) }; - std::vector > groups(&gs[0], &gs[arrayLength(gs)]); + std::vector > groups(vbegin(gs), vend(gs)); RequestGroupMan rm(groups, 0, _option.get()); CPPUNIT_ASSERT_EQUAL diff --git a/test/UtilTest.cc b/test/UtilTest.cc index 44c78b0d..25c187de 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -846,33 +846,28 @@ void UtilTest::testJoinPath() const std::string dir1dir2file[] = { "dir1", "dir2", "file" }; CPPUNIT_ASSERT_EQUAL (std::string("dir1/dir2/file"), - util::joinPath(&dir1dir2file[0], - &dir1dir2file[arrayLength(dir1dir2file)])); + util::joinPath(vbegin(dir1dir2file), vend(dir1dir2file))); const std::string dirparentfile[] = { "dir", "..", "file" }; CPPUNIT_ASSERT_EQUAL (std::string("file"), - util::joinPath(&dirparentfile[0], - &dirparentfile[arrayLength(dirparentfile)])); + util::joinPath(vbegin(dirparentfile), vend(dirparentfile))); const std::string dirparentparentfile[] = { "dir", "..", "..", "file" }; CPPUNIT_ASSERT_EQUAL (std::string("file"), - util::joinPath(&dirparentparentfile[0], - &dirparentparentfile[arrayLength(dirparentparentfile)])); + util::joinPath(vbegin(dirparentparentfile), vend(dirparentparentfile))); const std::string dirdotfile[] = { "dir", ".", "file" }; CPPUNIT_ASSERT_EQUAL(std::string("dir/file"), - util::joinPath(&dirdotfile[0], - &dirdotfile[arrayLength(dirdotfile)])); + util::joinPath(vbegin(dirdotfile), vend(dirdotfile))); const std::string empty[] = {}; CPPUNIT_ASSERT_EQUAL(std::string(""), util::joinPath(&empty[0], &empty[0])); const std::string parentdot[] = { "..", "." }; CPPUNIT_ASSERT_EQUAL(std::string(""), - util::joinPath(&parentdot[0], - &parentdot[arrayLength(parentdot)])); + util::joinPath(vbegin(parentdot), vend(parentdot))); } void UtilTest::testParseIndexPath() diff --git a/test/XmlRpcMethodTest.cc b/test/XmlRpcMethodTest.cc index 79a25b9b..84c26474 100644 --- a/test/XmlRpcMethodTest.cc +++ b/test/XmlRpcMethodTest.cc @@ -692,7 +692,7 @@ void XmlRpcMethodTest::testGatherProgressCommon() { SharedHandle dctx(new DownloadContext(0, 0,"aria2.tar.bz2")); std::string uris[] = { "http://localhost/aria2.tar.bz2" }; - dctx->getFirstFileEntry()->addUris(&uris[0], &uris[arrayLength(uris)]); + dctx->getFirstFileEntry()->addUris(vbegin(uris), vend(uris)); SharedHandle group(new RequestGroup(_option)); group->setDownloadContext(dctx); diff --git a/test/a2algoTest.cc b/test/a2algoTest.cc index aa814c7d..94cd2115 100644 --- a/test/a2algoTest.cc +++ b/test/a2algoTest.cc @@ -26,7 +26,7 @@ void a2algoTest::testSelect() { size_t A[] = { 1,2,3,4,7,10,11,12,13,14,15,100,112,113,114 }; - std::pair p = max_sequence(&A[0], &A[arrayLength(A)]); + std::pair p = max_sequence(vbegin(A), vend(A)); CPPUNIT_ASSERT_EQUAL(&A[5], p.first); CPPUNIT_ASSERT_EQUAL((size_t)6, p.second); diff --git a/test/array_funTest.cc b/test/array_funTest.cc index 3854f325..7497b311 100644 --- a/test/array_funTest.cc +++ b/test/array_funTest.cc @@ -13,6 +13,7 @@ class array_funTest:public CppUnit::TestFixture { CPPUNIT_TEST(testArrayLength); CPPUNIT_TEST(testArrayPtr); CPPUNIT_TEST(testArrayWrapper); + CPPUNIT_TEST(testVbeginVend); CPPUNIT_TEST_SUITE_END(); public: @@ -23,6 +24,7 @@ public: void testArrayLength(); void testArrayPtr(); void testArrayWrapper(); + void testVbeginVend(); struct X{ int m; @@ -116,4 +118,11 @@ void array_funTest::testArrayWrapper() arrayPtrConstCast(x1); } +void array_funTest::testVbeginVend() +{ + int a[] = {1,2,3}; + CPPUNIT_ASSERT_EQUAL(&a[0], vbegin(a)); + CPPUNIT_ASSERT_EQUAL(a+3, vend(a)); +} + } // namespace aria2