diff --git a/.clang-tidy b/.clang-tidy index a330c09b07d..1041b30dce0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,6 +8,7 @@ Checks: -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, -modernize-concat-nested-namespaces, + -modernize-use-default-member-init, performance-*, -performance-avoid-endl ' diff --git a/cpp/include/DataStorm/DataStorm.h b/cpp/include/DataStorm/DataStorm.h index e032fdf4f54..638b5ee92e3 100644 --- a/cpp/include/DataStorm/DataStorm.h +++ b/cpp/include/DataStorm/DataStorm.h @@ -1371,9 +1371,9 @@ namespace DataStorm auto unread = _impl->getAllUnread(); std::vector> samples; samples.reserve(unread.size()); - for (auto sample : unread) + for (const auto& sample : unread) { - samples.emplace_back(sample); + samples.push_back(sample); } return samples; } @@ -1658,9 +1658,9 @@ namespace DataStorm auto all = _impl->getAll(); std::vector> samples; samples.reserve(all.size()); - for (auto sample : all) + for (const auto& sample : all) { - samples.emplace_back(sample); + samples.push_back(sample); } return samples; } diff --git a/cpp/include/Ice/Communicator.h b/cpp/include/Ice/Communicator.h index f1f6cedcf04..7744ab73cd0 100644 --- a/cpp/include/Ice/Communicator.h +++ b/cpp/include/Ice/Communicator.h @@ -357,7 +357,7 @@ namespace Ice * @return A proxy to the main ("") facet of the Admin object, or nullopt if no Admin object is configured. * @see #createAdmin */ - std::optional getAdmin() const; // NOLINT:modernize-use-nodiscard + std::optional getAdmin() const; // NOLINT(modernize-use-nodiscard) /** * Add a new facet to the Admin object. Adding a servant with a facet that is already registered throws diff --git a/cpp/include/Ice/Config.h b/cpp/include/Ice/Config.h index b18a3fa8c39..4132f090973 100644 --- a/cpp/include/Ice/Config.h +++ b/cpp/include/Ice/Config.h @@ -38,9 +38,11 @@ #endif // The Ice version. +// NOLINTBEGIN(modernize-macro-to-enum) #define ICE_STRING_VERSION "3.8.0-alpha.0" // "A.B.C", with A=major, B=minor, C=patch #define ICE_INT_VERSION 30850 // AABBCC, with AA=major, BB=minor, CC=patch #define ICE_SO_VERSION "38a0" // "ABC", with A=major, B=minor, C=patch +// NOLINTEND(modernize-macro-to-enum) #if !defined(ICE_BUILDING_ICE) && defined(ICE_API_EXPORTS) # define ICE_BUILDING_ICE diff --git a/cpp/include/Ice/IconvStringConverter.h b/cpp/include/Ice/IconvStringConverter.h index 135e8ff805e..9353f3eb50f 100644 --- a/cpp/include/Ice/IconvStringConverter.h +++ b/cpp/include/Ice/IconvStringConverter.h @@ -154,7 +154,7 @@ namespace IceInternal assert(rs == 0); char* inbuf = reinterpret_cast(const_cast(sourceStart)); assert(sourceEnd > sourceStart); - size_t inbytesleft = static_cast(sourceEnd - sourceStart); + auto inbytesleft = static_cast(sourceEnd - sourceStart); char* outbuf = nullptr; size_t outbytesleft = 0; diff --git a/cpp/include/Ice/InputStream.h b/cpp/include/Ice/InputStream.h index 35e77e561f0..9f8e1fd6699 100644 --- a/cpp/include/Ice/InputStream.h +++ b/cpp/include/Ice/InputStream.h @@ -36,7 +36,7 @@ namespace Ice /// \cond INTERNAL template inline void patchValue(void* addr, const ValuePtr& v) { - std::shared_ptr* ptr = static_cast*>(addr); + auto* ptr = static_cast*>(addr); *ptr = std::dynamic_pointer_cast(v); if (v && !(*ptr)) { @@ -124,7 +124,7 @@ namespace Ice clear(); // Not inlined. } - for (auto d : _deleters) + for (const auto& d : _deleters) { d(); } @@ -313,7 +313,7 @@ namespace Ice { std::uint8_t byte; read(byte); - unsigned char val = static_cast(byte); + auto val = static_cast(byte); if (val == 255) { std::int32_t v; diff --git a/cpp/include/Ice/MetricsAdminI.h b/cpp/include/Ice/MetricsAdminI.h index 87910682f6e..7e102fc9e1a 100644 --- a/cpp/include/Ice/MetricsAdminI.h +++ b/cpp/include/Ice/MetricsAdminI.h @@ -125,12 +125,9 @@ namespace IceInternal ~EntryT() { assert(_object->total > 0); - for (typename std::map>::const_iterator p = - _subMaps.begin(); - p != _subMaps.end(); - ++p) + for (const auto& subMap : _subMaps) { - p->second.first->destroy(); // Break cyclic reference counts. + subMap.second.first->destroy(); // Break cyclic reference counts. } } @@ -148,8 +145,7 @@ namespace IceInternal MetricsMapIPtr m; { std::lock_guard lock(_map->_mutex); - typename std::map>::iterator p = - _subMaps.find(mapName); + auto p = _subMaps.find(mapName); if (p == _subMaps.end()) { std::pair map = _map->createSubMap(mapName); @@ -200,10 +196,7 @@ namespace IceInternal [[nodiscard]] IceMX::MetricsPtr clone() const { TPtr metrics = std::dynamic_pointer_cast(_object->ice_clone()); - for (typename std::map>::const_iterator p = - _subMaps.begin(); - p != _subMaps.end(); - ++p) + for (auto p = _subMaps.begin(); p != _subMaps.end(); ++p) { metrics.get()->*p->second.second = p->second.first->getMetrics(); } @@ -278,10 +271,9 @@ namespace IceInternal IceMX::MetricsMap objects; std::lock_guard lock(_mutex); - for (typename std::map::const_iterator p = _objects.begin(); p != _objects.end(); - ++p) + for (const auto& object : _objects) { - objects.push_back(p->second->clone()); + objects.push_back(object.second->clone()); } return objects; } @@ -291,10 +283,9 @@ namespace IceInternal IceMX::MetricsFailuresSeq failures; std::lock_guard lock(_mutex); - for (typename std::map::const_iterator p = _objects.begin(); p != _objects.end(); - ++p) + for (const auto& object : _objects) { - IceMX::MetricsFailures f = p->second->getFailures(); + IceMX::MetricsFailures f = object.second->getFailures(); if (!f.failures.empty()) { failures.push_back(f); @@ -306,7 +297,7 @@ namespace IceInternal IceMX::MetricsFailures getFailures(const std::string& id) override { std::lock_guard lock(_mutex); - typename std::map::const_iterator p = _objects.find(id); + auto p = _objects.find(id); if (p != _objects.end()) { return p->second->getFailures(); @@ -316,8 +307,7 @@ namespace IceInternal std::pair createSubMap(const std::string& subMapName) { - typename std::map>::const_iterator p = - _subMaps.find(subMapName); + auto p = _subMaps.find(subMapName); if (p != _subMaps.end()) { return std::pair( @@ -332,17 +322,17 @@ namespace IceInternal // // Check the accept and reject filters. // - for (std::vector::const_iterator p = _accept.begin(); p != _accept.end(); ++p) + for (const auto& filter : _accept) { - if (!(*p)->match(helper, false)) + if (!filter->match(helper, false)) { return nullptr; } } - for (std::vector::const_iterator p = _reject.begin(); p != _reject.end(); ++p) + for (const auto& filter : _reject) { - if ((*p)->match(helper, true)) + if (filter->match(helper, true)) { return nullptr; } @@ -361,10 +351,8 @@ namespace IceInternal else { std::ostringstream os; - std::vector::const_iterator q = _groupBySeparators.begin(); - for (std::vector::const_iterator p = _groupByAttributes.begin(); - p != _groupByAttributes.end(); - ++p) + auto q = _groupBySeparators.begin(); + for (auto p = _groupByAttributes.begin(); p != _groupByAttributes.end(); ++p) { os << helper(*p); if (q != _groupBySeparators.end()) @@ -395,7 +383,7 @@ namespace IceInternal return previous; } - typename std::map::const_iterator p = _objects.find(key); + auto p = _objects.find(key); if (p == _objects.end()) { TPtr t = std::make_shared(); @@ -443,7 +431,7 @@ namespace IceInternal if (static_cast(_detachedQueue.size()) == _retain) { // Remove entries which are no longer detached - typename std::list::iterator p = _detachedQueue.begin(); + auto p = _detachedQueue.begin(); while (p != _detachedQueue.end()) { if (!(*p)->isDetached()) @@ -563,7 +551,7 @@ namespace IceInternal std::shared_ptr> factory; { std::lock_guard lock(_mutex); - std::map::const_iterator p = _factories.find(map); + auto p = _factories.find(map); if (p == _factories.end()) { return; diff --git a/cpp/include/Ice/MetricsObserverI.h b/cpp/include/Ice/MetricsObserverI.h index 7221ac9b3ec..c7325ef7755 100644 --- a/cpp/include/Ice/MetricsObserverI.h +++ b/cpp/include/Ice/MetricsObserverI.h @@ -82,17 +82,15 @@ namespace IceMX ~AttributeResolverT() { - for (typename std::map::iterator p = _attributes.begin(); - p != _attributes.end(); - ++p) + for (const auto& attribute : _attributes) { - delete p->second; + delete attribute.second; } } std::string operator()(const Helper* helper, const std::string& attribute) const { - typename std::map::const_iterator p = _attributes.find(attribute); + auto p = _attributes.find(attribute); if (p == _attributes.end()) { if (attribute == "none") @@ -344,25 +342,25 @@ namespace IceMX void detach() override { std::chrono::microseconds lifetime = _previousDelay + _watch.stop(); - for (typename EntrySeqType::const_iterator p = _objects.begin(); p != _objects.end(); ++p) + for (const auto& object : _objects) { - (*p)->detach(lifetime.count()); + object->detach(lifetime.count()); } } void failed(const std::string& exceptionName) override { - for (typename EntrySeqType::const_iterator p = _objects.begin(); p != _objects.end(); ++p) + for (const auto& object : _objects) { - (*p)->failed(exceptionName); + object->failed(exceptionName); } } template void forEach(const Function& func) { - for (typename EntrySeqType::const_iterator p = _objects.begin(); p != _objects.end(); ++p) + for (const auto& object : _objects) { - (*p)->execute(func); + object->execute(func); } } @@ -380,23 +378,22 @@ namespace IceMX // Detach entries from previous observer which are no longer // attached to this new observer. // - for (typename EntrySeqType::const_iterator p = previous->_objects.begin(); p != previous->_objects.end(); - ++p) + for (const auto& previousObject : previous->_objects) { - if (find(_objects.begin(), _objects.end(), *p) == _objects.end()) + if (find(_objects.begin(), _objects.end(), previousObject) == _objects.end()) { - (*p)->detach(_previousDelay.count()); + previousObject->detach(_previousDelay.count()); } } } EntryPtrType getEntry(IceInternal::MetricsMapT* map) { - for (typename EntrySeqType::const_iterator p = _objects.begin(); p != _objects.end(); ++p) + for (const auto& object : _objects) { - if ((*p)->getMap() == map) + if (object->getMap() == map) { - return *p; + return object; } } return nullptr; @@ -407,10 +404,10 @@ namespace IceMX getObserver(const std::string& mapName, const MetricsHelperT& helper) { std::vector::EntryTPtr> metricsObjects; - for (typename EntrySeqType::const_iterator p = _objects.begin(); p != _objects.end(); ++p) + for (const auto& object : _objects) { typename IceInternal::MetricsMapT::EntryTPtr e = - (*p)->getMatching(mapName, helper); + object->getMatching(mapName, helper); if (e) { metricsObjects.push_back(e); @@ -465,9 +462,9 @@ namespace IceMX } typename ObserverImplType::EntrySeqType metricsObjects; - for (typename MetricsMapSeqType::const_iterator p = _maps.begin(); p != _maps.end(); ++p) + for (const auto& map : _maps) { - typename ObserverImplType::EntryPtrType entry = (*p)->getMatching(helper); + typename ObserverImplType::EntryPtrType entry = map->getMatching(helper); if (entry) { metricsObjects.push_back(entry); @@ -501,9 +498,9 @@ namespace IceMX } typename ObserverImplType::EntrySeqType metricsObjects; - for (typename MetricsMapSeqType::const_iterator p = _maps.begin(); p != _maps.end(); ++p) + for (const auto& map : _maps) { - typename ObserverImplType::EntryPtrType entry = (*p)->getMatching(helper, old->getEntry(p->get())); + typename ObserverImplType::EntryPtrType entry = map->getMatching(helper, old->getEntry(map.get())); if (entry) { metricsObjects.push_back(entry); @@ -541,9 +538,9 @@ namespace IceMX std::vector maps = _metrics->getMaps(_name); _maps.clear(); - for (std::vector::const_iterator p = maps.begin(); p != maps.end(); ++p) + for (auto& map : maps) { - _maps.push_back(std::dynamic_pointer_cast>(*p)); + _maps.push_back(std::dynamic_pointer_cast>(map)); assert(_maps.back()); } _enabled.exchange(_maps.empty() ? 0 : 1); diff --git a/cpp/include/Ice/OutputStream.h b/cpp/include/Ice/OutputStream.h index e76fa0353ce..cfeae143cbc 100644 --- a/cpp/include/Ice/OutputStream.h +++ b/cpp/include/Ice/OutputStream.h @@ -619,7 +619,7 @@ namespace Ice */ void write(std::string_view v, bool convert = true) { - std::int32_t sz = static_cast(v.size()); + auto sz = static_cast(v.size()); if (convert && sz > 0) { writeConverted(v.data(), static_cast(sz)); @@ -645,7 +645,7 @@ namespace Ice */ void write(const char* vdata, size_t vsize, bool convert = true) { - std::int32_t sz = static_cast(vsize); + auto sz = static_cast(vsize); if (convert && sz > 0) { writeConverted(vdata, vsize); diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 307b060a3d2..6869f67b4d6 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -325,7 +325,7 @@ namespace Ice * @param context The context map for the invocation. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_isAAsync( std::string_view typeId, std::function response, @@ -361,7 +361,7 @@ namespace Ice * @param context The context map for the invocation. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_pingAsync( std::function response, std::function ex = nullptr, @@ -394,7 +394,7 @@ namespace Ice * @param context The context map for the invocation. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_idsAsync( std::function)> response, std::function ex = nullptr, @@ -430,7 +430,7 @@ namespace Ice * @param context The context map for the invocation. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_idAsync( std::function response, std::function ex = nullptr, @@ -492,7 +492,7 @@ namespace Ice * @param context The context map for the invocation. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_invokeAsync( std::string_view operation, Ice::OperationMode mode, @@ -546,7 +546,7 @@ namespace Ice * @param context The context map for the invocation. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_invokeAsync( std::string_view operation, Ice::OperationMode mode, @@ -563,7 +563,7 @@ namespace Ice * @remarks You can call this function to establish a connection or associate the proxy with an existing * connection and ignore the return value. */ - Ice::ConnectionPtr ice_getConnection() const; // NOLINT:modernize-use-nodiscard + Ice::ConnectionPtr ice_getConnection() const; // NOLINT(modernize-use-nodiscard) /** * Obtains the Connection for this proxy. If the proxy does not yet have an established connection, @@ -573,7 +573,7 @@ namespace Ice * @param sent The sent callback. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_getConnectionAsync( std::function response, std::function ex = nullptr, @@ -609,7 +609,7 @@ namespace Ice * @param sent The sent callback. * @return A function that can be called to cancel the invocation locally. */ - // NOLINTNEXTLINE:modernize-use-nodiscard + // NOLINTNEXTLINE(modernize-use-nodiscard) std::function ice_flushBatchRequestsAsync( std::function ex, std::function sent = nullptr) const; diff --git a/cpp/include/Ice/StreamHelpers.h b/cpp/include/Ice/StreamHelpers.h index d31152f04bd..1acb7cb3d90 100644 --- a/cpp/include/Ice/StreamHelpers.h +++ b/cpp/include/Ice/StreamHelpers.h @@ -124,9 +124,9 @@ namespace Ice static void write(OutputStream* stream, const T& v) { stream->writeSize(static_cast(v.size())); - for (typename T::const_iterator p = v.begin(); p != v.end(); ++p) + for (const auto& element : v) { - stream->write(*p); + stream->write(element); } } @@ -134,9 +134,9 @@ namespace Ice { std::int32_t sz = stream->readAndCheckSeqSize(StreamableTraits::minWireSize); T(static_cast(sz)).swap(v); - for (typename T::iterator p = v.begin(); p != v.end(); ++p) + for (auto& element : v) { - stream->read(*p); + stream->read(element); } } }; @@ -174,10 +174,10 @@ namespace Ice static void write(OutputStream* stream, const T& v) { stream->writeSize(static_cast(v.size())); - for (typename T::const_iterator p = v.begin(); p != v.end(); ++p) + for (const auto& entry : v) { - stream->write(p->first); - stream->write(p->second); + stream->write(entry.first); + stream->write(entry.second); } } @@ -189,7 +189,7 @@ namespace Ice { typename T::value_type p; stream->read(const_cast(p.first)); - typename T::iterator i = v.insert(v.end(), p); + auto i = v.insert(v.end(), p); stream->read(i->second); } } @@ -490,7 +490,7 @@ namespace Ice static void write(OutputStream* stream, const P& v) { - std::int32_t n = static_cast(v.second - v.first); + auto n = static_cast(v.second - v.first); StreamOptionalContainerHelper::write(stream, v, n); } diff --git a/cpp/include/Ice/StreamableTraits.h b/cpp/include/Ice/StreamableTraits.h index 98153127913..678972224e0 100644 --- a/cpp/include/Ice/StreamableTraits.h +++ b/cpp/include/Ice/StreamableTraits.h @@ -85,7 +85,7 @@ namespace Ice template static long test(...) noexcept; - static const bool value = sizeof(test(0)) == sizeof(char); + static const bool value = sizeof(test(nullptr)) == sizeof(char); }; /** @@ -99,7 +99,7 @@ namespace Ice template static long test(...) noexcept; - static const bool value = IsContainer::value && sizeof(test(0)) == sizeof(char); + static const bool value = IsContainer::value && sizeof(test(nullptr)) == sizeof(char); }; /** diff --git a/cpp/src/DataStorm/SessionI.cpp b/cpp/src/DataStorm/SessionI.cpp index e32f3e00afa..f0e9679f7b9 100644 --- a/cpp/src/DataStorm/SessionI.cpp +++ b/cpp/src/DataStorm/SessionI.cpp @@ -96,7 +96,7 @@ SessionI::announceTopics(TopicInfoSeq topics, bool, const Current&) retained, [&](const shared_ptr& topic) { - for (auto id : info.ids) + for (const auto& id : info.ids) { topic->attach(id, shared_from_this(), *_session); } @@ -258,7 +258,7 @@ SessionI::detachTags(int64_t topicId, LongSeq tags, const Current&) out << _id << ": detaching tags '[" << tags << "]@" << topicId << "' on topic '" << topic << "'"; } - for (auto tag : tags) + for (const auto& tag : tags) { subscriber.tags.erase(tag); } diff --git a/cpp/src/DataStorm/TopicI.cpp b/cpp/src/DataStorm/TopicI.cpp index 345a481cf7d..22f2bb159ab 100644 --- a/cpp/src/DataStorm/TopicI.cpp +++ b/cpp/src/DataStorm/TopicI.cpp @@ -14,7 +14,7 @@ using namespace Ice; namespace { - static Topic::Updater noOpUpdater = // NOLINT:cert-err58-cpp + static Topic::Updater noOpUpdater = // NOLINT(cert-err58-cpp) [](const shared_ptr& previous, const shared_ptr& next, const CommunicatorPtr&) { next->setValue(previous); }; @@ -39,7 +39,7 @@ namespace [[nodiscard]] bool match(const shared_ptr&) const final { return true; } }; - const auto alwaysMatchFilter = make_shared(); // NOLINT:cert-err58-cpp + const auto alwaysMatchFilter = make_shared(); // NOLINT(cert-err58-cpp) DataStorm::ClearHistoryPolicy parseClearHistory(const std::string& value) { @@ -794,7 +794,7 @@ TopicI::disconnect() for (const auto& [session, listener] : listeners) { - for (auto id : listener.topics) + for (const auto& id : listener.topics) { session->disconnect(id, this); } diff --git a/cpp/src/DataStorm/TraceUtil.h b/cpp/src/DataStorm/TraceUtil.h index 4b3a1c287c2..6c6e6909294 100644 --- a/cpp/src/DataStorm/TraceUtil.h +++ b/cpp/src/DataStorm/TraceUtil.h @@ -12,7 +12,7 @@ #include "TopicI.h" // Use namespace std for operator<< overloads of std types to enable ADL to find them. -// NOLINTBEGIN:cert-dcl58-cpp +// NOLINTBEGIN(cert-dcl58-cpp) namespace std { template inline std::ostream& operator<<(std::ostream& os, const std::vector& p) @@ -47,7 +47,7 @@ namespace std return os; } } -// NOLINTEND:cert-dcl58-cpp +// NOLINTEND(cert-dcl58-cpp) namespace Ice { @@ -203,7 +203,7 @@ namespace DataStormI return os; } - class TraceLevels // NOLINT:clang-analyzer-optin.performance.Padding + class TraceLevels // NOLINT(clang-analyzer-optin.performance.Padding) { public: TraceLevels(const Ice::PropertiesPtr&, Ice::LoggerPtr); diff --git a/cpp/src/Glacier2/Blobject.cpp b/cpp/src/Glacier2/Blobject.cpp index 49d564d4c51..1194bfd3a0a 100644 --- a/cpp/src/Glacier2/Blobject.cpp +++ b/cpp/src/Glacier2/Blobject.cpp @@ -64,7 +64,7 @@ Glacier2::Blobject::invoke( // // Modify the proxy according to the _fwd context field. // - Context::const_iterator p = current.ctx.find("_fwd"); + auto p = current.ctx.find("_fwd"); if (p != current.ctx.end()) { for (unsigned int i = 0; i < p->second.length(); ++i) @@ -144,7 +144,7 @@ Glacier2::Blobject::invoke( } out << "\noperation = " << current.operation; out << "\ncontext = "; - Context::const_iterator q = current.ctx.begin(); + auto q = current.ctx.begin(); while (q != current.ctx.end()) { out << q->first << '/' << q->second; diff --git a/cpp/src/Glacier2/FilterT.h b/cpp/src/Glacier2/FilterT.h index 63fdadf9639..6bb07751fe7 100644 --- a/cpp/src/Glacier2/FilterT.h +++ b/cpp/src/Glacier2/FilterT.h @@ -98,13 +98,13 @@ namespace Glacier2 // itemwise. // - typename std::vector::const_iterator r = toRemove.begin(); - typename std::vector::iterator mark = _items.begin(); + auto r = toRemove.begin(); + auto mark = _items.begin(); std::list::iterator> deleteList; while (r != toRemove.end()) { - typename std::vector::iterator i = mark; + auto i = mark; while (i != _items.end() && r != toRemove.end()) { if (*r == *i) diff --git a/cpp/src/Glacier2/Glacier2Router.cpp b/cpp/src/Glacier2/Glacier2Router.cpp index 32eeeadfcf6..df7edf51dea 100644 --- a/cpp/src/Glacier2/Glacier2Router.cpp +++ b/cpp/src/Glacier2/Glacier2Router.cpp @@ -157,8 +157,8 @@ RouterService::start(int argc, char* argv[], int& status) string instanceName = communicator()->getProperties()->getIceProperty("Glacier2.InstanceName"); vector verifierProperties; - verifierProperties.push_back("Glacier2.PermissionsVerifier"); - verifierProperties.push_back("Glacier2.SSLPermissionsVerifier"); + verifierProperties.emplace_back("Glacier2.PermissionsVerifier"); + verifierProperties.emplace_back("Glacier2.SSLPermissionsVerifier"); try { diff --git a/cpp/src/Glacier2/ProxyVerifier.cpp b/cpp/src/Glacier2/ProxyVerifier.cpp index f5c59cb9eca..258187dd4fc 100644 --- a/cpp/src/Glacier2/ProxyVerifier.cpp +++ b/cpp/src/Glacier2/ProxyVerifier.cpp @@ -244,7 +244,7 @@ namespace Glacier2 ostr << descriptionPrefix; { bool start = true; - for (vector::const_iterator i = values.begin(); i != values.end(); ++i) + for (auto i = values.begin(); i != values.end(); ++i) { if (start) { @@ -268,7 +268,7 @@ namespace Glacier2 } { bool start = true; - for (vector::const_iterator i = ranges.begin(); i != ranges.end(); ++i) + for (const auto& range : ranges) { if (start) { @@ -278,7 +278,7 @@ namespace Glacier2 { ostr << ", or"; } - ostr << i->start << " up to " << i->end; + ostr << range.start << " up to " << range.end; } } ostr << ends; @@ -295,18 +295,18 @@ namespace Glacier2 } pos += static_cast(istr.tellg()); { - for (vector::const_iterator i = _values.begin(); i != _values.end(); ++i) + for (int value : _values) { - if (val == *i) + if (val == value) { return true; } } } { - for (vector::const_iterator i = _ranges.begin(); i != _ranges.end(); ++i) + for (const auto& range : _ranges) { - if ((val >= i->start) && (val <= i->end)) + if ((val >= range.start) && (val <= range.end)) { return true; } @@ -453,9 +453,9 @@ namespace Glacier2 ~AddressRule() override { - for (vector::const_iterator i = _addressRules.begin(); i != _addressRules.end(); ++i) + for (const auto& addressRule : _addressRules) { - delete *i; + delete addressRule; } delete _portMatcher; } @@ -711,9 +711,9 @@ namespace Glacier2 } catch (...) { - for (vector::const_iterator i = allRules.begin(); i != allRules.end(); ++i) + for (const auto& allRule : allRules) { - delete *i; + delete allRule; } throw; } @@ -725,9 +725,9 @@ namespace Glacier2 // static bool match(const vector& rules, const ObjectPrx& proxy) { - for (vector::const_iterator i = rules.begin(); i != rules.end(); ++i) + for (auto rule : rules) { - if ((*i)->check(proxy)) + if (rule->check(proxy)) { return true; } @@ -833,13 +833,13 @@ Glacier2::ProxyVerifier::ProxyVerifier(CommunicatorPtr communicator) Glacier2::ProxyVerifier::~ProxyVerifier() { - for (vector::const_iterator i = _acceptRules.begin(); i != _acceptRules.end(); ++i) + for (const auto& acceptRule : _acceptRules) { - delete (*i); + delete acceptRule; } - for (vector::const_iterator j = _rejectRules.begin(); j != _rejectRules.end(); ++j) + for (const auto& rejectRule : _rejectRules) { - delete (*j); + delete rejectRule; } } diff --git a/cpp/src/Glacier2/RouterI.cpp b/cpp/src/Glacier2/RouterI.cpp index 424de5f9ec6..eea68f5a3f1 100644 --- a/cpp/src/Glacier2/RouterI.cpp +++ b/cpp/src/Glacier2/RouterI.cpp @@ -44,7 +44,7 @@ Glacier2::RouterI::RouterI( const_cast&>(_serverProxy) = _instance->serverObjectAdapter()->createProxy(ident); - shared_ptr& serverBlobject = const_cast&>(_serverBlobject); + auto& serverBlobject = const_cast&>(_serverBlobject); serverBlobject = make_shared(_instance, _connection); } diff --git a/cpp/src/Glacier2/RoutingTable.cpp b/cpp/src/Glacier2/RoutingTable.cpp index e4af6509359..9c09933a880 100644 --- a/cpp/src/Glacier2/RoutingTable.cpp +++ b/cpp/src/Glacier2/RoutingTable.cpp @@ -72,7 +72,7 @@ Glacier2::RoutingTable::add(const ObjectProxySeq& unfiltered, const Current& cur ObjectProxySeq evictedProxies; for (const auto& proxy : proxies) { - EvictorMap::iterator p = _map.find(proxy->ice_getIdentity()); + auto p = _map.find(proxy->ice_getIdentity()); if (p == _map.end()) { @@ -83,7 +83,7 @@ Glacier2::RoutingTable::add(const ObjectProxySeq& unfiltered, const Current& cur } p = _map.insert(_map.begin(), make_pair(proxy->ice_getIdentity(), EvictorEntry{proxy, _queue.end()})); - EvictorQueue::iterator q = _queue.insert(_queue.end(), p); + auto q = _queue.insert(_queue.end(), p); p->second.pos = q; } else @@ -96,7 +96,7 @@ Glacier2::RoutingTable::add(const ObjectProxySeq& unfiltered, const Current& cur auto& entry = p->second; _queue.erase(entry.pos); - EvictorQueue::iterator q = _queue.insert(_queue.end(), p); + auto q = _queue.insert(_queue.end(), p); entry.pos = q; } @@ -110,7 +110,7 @@ Glacier2::RoutingTable::add(const ObjectProxySeq& unfiltered, const Current& cur out << "evicting proxy from routing table:\n" << p->second.proxy; } - evictedProxies.push_back(p->second.proxy); + evictedProxies.emplace_back(p->second.proxy); _map.erase(p); _queue.pop_front(); @@ -130,7 +130,7 @@ Glacier2::RoutingTable::get(const Identity& ident) { lock_guard lock(_mutex); - EvictorMap::iterator p = _map.find(ident); + auto p = _map.find(ident); if (p == _map.end()) { @@ -140,7 +140,7 @@ Glacier2::RoutingTable::get(const Identity& ident) { auto& entry = p->second; _queue.erase(entry.pos); - EvictorQueue::iterator q = _queue.insert(_queue.end(), p); + auto q = _queue.insert(_queue.end(), p); entry.pos = q; return entry.proxy; diff --git a/cpp/src/Glacier2/SessionRouterI.cpp b/cpp/src/Glacier2/SessionRouterI.cpp index 2d9c413d076..381e7eb2a5c 100644 --- a/cpp/src/Glacier2/SessionRouterI.cpp +++ b/cpp/src/Glacier2/SessionRouterI.cpp @@ -553,7 +553,7 @@ SessionRouterI::destroy() // We destroy the routers outside the thread synchronization to // avoid deadlocks. // - for (auto& router : routers) + for (const auto& router : routers) { router.second->destroy([self = shared_from_this()](exception_ptr e) { self->sessionDestroyException(e); }); } @@ -761,7 +761,7 @@ SessionRouterI::updateSessionObservers() const auto& observer = _instance->getObserver(); assert(observer); - for (auto& router : _routersByConnection) + for (const auto& router : _routersByConnection) { router.second->updateObserver(observer); } diff --git a/cpp/src/Glacier2CryptPermissionsVerifier/CryptPermissionsVerifierI.cpp b/cpp/src/Glacier2CryptPermissionsVerifier/CryptPermissionsVerifierI.cpp index e6effff1f95..bc391a90e2c 100644 --- a/cpp/src/Glacier2CryptPermissionsVerifier/CryptPermissionsVerifierI.cpp +++ b/cpp/src/Glacier2CryptPermissionsVerifier/CryptPermissionsVerifierI.cpp @@ -133,7 +133,7 @@ namespace } bool CryptPermissionsVerifierI::checkPermissions(string userId, string password, string&, const Current&) const { - map::const_iterator p = _passwords.find(userId); + auto p = _passwords.find(userId); if (p == _passwords.end()) { diff --git a/cpp/src/Ice/BatchRequestQueue.cpp b/cpp/src/Ice/BatchRequestQueue.cpp index 81a1da561d7..877cd1c7aad 100644 --- a/cpp/src/Ice/BatchRequestQueue.cpp +++ b/cpp/src/Ice/BatchRequestQueue.cpp @@ -58,7 +58,7 @@ BatchRequestQueue::BatchRequestQueue(const InstancePtr& instance, bool datagram) if (_maxSize > 0 && datagram) { const Ice::InitializationData& initData = instance->initializationData(); - size_t udpSndSize = static_cast( + auto udpSndSize = static_cast( initData.properties->getPropertyAsIntWithDefault("Ice.UDP.SndSize", 65535 - udpOverhead)); if (udpSndSize < _maxSize) { diff --git a/cpp/src/Ice/CollocatedRequestHandler.cpp b/cpp/src/Ice/CollocatedRequestHandler.cpp index 86857a145b1..b5cd06dfff3 100644 --- a/cpp/src/Ice/CollocatedRequestHandler.cpp +++ b/cpp/src/Ice/CollocatedRequestHandler.cpp @@ -56,7 +56,7 @@ CollocatedRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAs { lock_guard lock(_mutex); - map::iterator p = _sendAsyncRequests.find(outAsync); + auto p = _sendAsyncRequests.find(outAsync); if (p != _sendAsyncRequests.end()) { if (p->second > 0) @@ -75,7 +75,7 @@ CollocatedRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAs OutgoingAsyncPtr o = dynamic_pointer_cast(outAsync); if (o) { - for (map::iterator q = _asyncRequests.begin(); q != _asyncRequests.end(); ++q) + for (auto q = _asyncRequests.begin(); q != _asyncRequests.end(); ++q) { if (q->second.get() == o.get()) { @@ -292,7 +292,7 @@ CollocatedRequestHandler::handleException(int32_t requestId, std::exception_ptr { lock_guard lock(_mutex); - map::iterator q = _asyncRequests.find(requestId); + auto q = _asyncRequests.find(requestId); if (q != _asyncRequests.end()) { if (q->second->exception(ex)) @@ -343,7 +343,7 @@ CollocatedRequestHandler::sendResponse(OutgoingResponse response) traceRecv(is, nullptr, _logger, _traceLevels); } - map::iterator q = _asyncRequests.find(response.current().requestId); + auto q = _asyncRequests.find(response.current().requestId); if (q != _asyncRequests.end()) { is.swap(*q->second->getIs()); diff --git a/cpp/src/Ice/Communicator.cpp b/cpp/src/Ice/Communicator.cpp index 5bcd65d230f..f197e53eee3 100644 --- a/cpp/src/Ice/Communicator.cpp +++ b/cpp/src/Ice/Communicator.cpp @@ -148,9 +148,9 @@ Ice::Communicator::createObjectAdapterWithRouter(string name, RouterPrx router) } PropertyDict properties = proxyToProperty(router, name + ".Router"); - for (PropertyDict::const_iterator p = properties.begin(); p != properties.end(); ++p) + for (const auto& prop : properties) { - getProperties()->setProperty(p->first, p->second); + getProperties()->setProperty(prop.first, prop.second); } return _instance->objectAdapterFactory()->createObjectAdapter(std::move(name), std::move(router), nullopt); diff --git a/cpp/src/Ice/ConnectRequestHandler.cpp b/cpp/src/Ice/ConnectRequestHandler.cpp index 7fc1795a827..d13050c828b 100644 --- a/cpp/src/Ice/ConnectRequestHandler.cpp +++ b/cpp/src/Ice/ConnectRequestHandler.cpp @@ -48,7 +48,7 @@ ConnectRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync if (!initialized(lock)) { - for (deque::iterator p = _requests.begin(); p != _requests.end(); ++p) + for (auto p = _requests.begin(); p != _requests.end(); ++p) { if (p->get() == outAsync.get()) { @@ -128,11 +128,11 @@ ConnectRequestHandler::setException(exception_ptr ex) _exception = ex; } - for (deque::const_iterator p = _requests.begin(); p != _requests.end(); ++p) + for (const auto& request : _requests) { - if ((*p)->exception(ex)) + if (request->exception(ex)) { - (*p)->invokeExceptionAsync(); + request->invokeExceptionAsync(); } } diff --git a/cpp/src/Ice/ConnectionFactory.cpp b/cpp/src/Ice/ConnectionFactory.cpp index d10d33a7e4d..b17d1fecb11 100644 --- a/cpp/src/Ice/ConnectionFactory.cpp +++ b/cpp/src/Ice/ConnectionFactory.cpp @@ -112,9 +112,9 @@ IceInternal::OutgoingConnectionFactory::destroy() return; } - for (const auto& p : _connections) + for (const auto& [_, connection] : _connections) { - p.second->destroy(ConnectionI::CommunicatorDestroyed); + connection->destroy(ConnectionI::CommunicatorDestroyed); } _destroyed = true; _communicator = nullptr; @@ -126,9 +126,9 @@ void IceInternal::OutgoingConnectionFactory::updateConnectionObservers() { lock_guard lock(_mutex); - for (const auto& p : _connections) + for (const auto& [_, connection] : _connections) { - p.second->updateObserver(); + connection->updateObserver(); } } @@ -226,10 +226,8 @@ IceInternal::OutgoingConnectionFactory::setRouterInfo(const RouterInfoPtr& route // callbacks from the router can be received over such // connections. // - for (vector::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) + for (auto endpoint : endpoints) { - EndpointIPtr endpoint = *p; - // // The Connection object does not take the compression flag of // endpoints into account, but instead gets the information @@ -242,12 +240,11 @@ IceInternal::OutgoingConnectionFactory::setRouterInfo(const RouterInfoPtr& route // endpoint = endpoint->compress(false)->timeout(-1); - for (multimap::const_iterator q = _connections.begin(); q != _connections.end(); - ++q) + for (const auto& [_, connection] : _connections) { - if (q->second->endpoint() == endpoint) + if (connection->endpoint() == endpoint) { - q->second->setAdapter(adapter); + connection->setAdapter(adapter); } } } @@ -263,11 +260,11 @@ IceInternal::OutgoingConnectionFactory::removeAdapter(const ObjectAdapterPtr& ad return; } - for (multimap::const_iterator p = _connections.begin(); p != _connections.end(); ++p) + for (const auto& [_, connection] : _connections) { - if (p->second->getAdapter() == adapter) + if (connection->getAdapter() == adapter) { - p->second->setAdapter(nullptr); + connection->setAdapter(nullptr); } } } @@ -281,21 +278,20 @@ IceInternal::OutgoingConnectionFactory::flushAsyncBatchRequests( { lock_guard lock(_mutex); - for (multimap::const_iterator p = _connections.begin(); p != _connections.end(); - ++p) + for (const auto& [_, connection] : _connections) { - if (p->second->isActiveOrHolding()) + if (connection->isActiveOrHolding()) { - c.push_back(p->second); + c.push_back(connection); } } } - for (list::const_iterator p = c.begin(); p != c.end(); ++p) + for (const auto& p : c) { try { - outAsync->flushConnection(*p, compress); + outAsync->flushConnection(p, compress); } catch (const LocalException&) { @@ -560,34 +556,34 @@ IceInternal::OutgoingConnectionFactory::finishGetConnection( ConnectCallbackSet callbacks; { lock_guard lock(_mutex); - for (vector::const_iterator p = connectors.begin(); p != connectors.end(); ++p) + for (const auto& connector : connectors) { - auto q = _pending.find(p->connector); + auto q = _pending.find(connector.connector); if (q != _pending.end()) { - for (auto r = q->second.begin(); r != q->second.end(); ++r) + for (const auto& r : q->second) { - if ((*r)->hasConnector(ci)) + if (r->hasConnector(ci)) { - connectionCallbacks.insert(*r); + connectionCallbacks.insert(r); } else { - callbacks.insert(*r); + callbacks.insert(r); } } _pending.erase(q); } } - for (auto r = connectionCallbacks.begin(); r != connectionCallbacks.end(); ++r) + for (const auto& connectionCallback : connectionCallbacks) { - (*r)->removeFromPending(); - callbacks.erase(*r); + connectionCallback->removeFromPending(); + callbacks.erase(connectionCallback); } - for (auto r = callbacks.begin(); r != callbacks.end(); ++r) + for (const auto& callback : callbacks) { - (*r)->removeFromPending(); + callback->removeFromPending(); } _conditionVariable.notify_all(); } @@ -603,13 +599,13 @@ IceInternal::OutgoingConnectionFactory::finishGetConnection( compress = ci.endpoint->compress(); } - for (auto p = callbacks.begin(); p != callbacks.end(); ++p) + for (const auto& callback : callbacks) { - (*p)->getConnection(); + callback->getConnection(); } - for (auto p = connectionCallbacks.begin(); p != connectionCallbacks.end(); ++p) + for (const auto& connectionCallback : connectionCallbacks) { - (*p)->setConnection(connection, compress); + connectionCallback->setConnection(connection, compress); } } @@ -633,36 +629,36 @@ IceInternal::OutgoingConnectionFactory::finishGetConnection( auto q = _pending.find(p->connector); if (q != _pending.end()) { - for (auto r = q->second.begin(); r != q->second.end(); ++r) + for (const auto& r : q->second) { - if ((*r)->removeConnectors(connectors)) + if (r->removeConnectors(connectors)) { - failedCallbacks.insert(*r); + failedCallbacks.insert(r); } else { - callbacks.insert(*r); + callbacks.insert(r); } } _pending.erase(q); } } - for (auto r = callbacks.begin(); r != callbacks.end(); ++r) + for (const auto& callback : callbacks) { - assert(failedCallbacks.find(*r) == failedCallbacks.end()); - (*r)->removeFromPending(); + assert(failedCallbacks.find(callback) == failedCallbacks.end()); + callback->removeFromPending(); } _conditionVariable.notify_all(); } - for (auto p = callbacks.begin(); p != callbacks.end(); ++p) + for (const auto& callback : callbacks) { - (*p)->getConnection(); + callback->getConnection(); } - for (auto p = failedCallbacks.begin(); p != failedCallbacks.end(); ++p) + for (const auto& failedCallback : failedCallbacks) { - (*p)->setException(ex); + failedCallback->setException(ex); } } @@ -675,9 +671,9 @@ IceInternal::OutgoingConnectionFactory::addToPending( // Add the callback to each connector pending list. // bool found = false; - for (auto p = connectors.begin(); p != connectors.end(); ++p) + for (const auto& connector : connectors) { - auto q = _pending.find(p->connector); + auto q = _pending.find(connector.connector); if (q != _pending.end()) { found = true; @@ -698,11 +694,11 @@ IceInternal::OutgoingConnectionFactory::addToPending( // responsible for its establishment. We add empty pending lists, // other callbacks to the same connectors will be queued. // - for (vector::const_iterator r = connectors.begin(); r != connectors.end(); ++r) + for (const auto& connector : connectors) { - if (_pending.find(r->connector) == _pending.end()) + if (_pending.find(connector.connector) == _pending.end()) { - _pending.insert(make_pair(r->connector, ConnectCallbackSet())); + _pending.insert(make_pair(connector.connector, ConnectCallbackSet())); } } return false; @@ -713,9 +709,9 @@ IceInternal::OutgoingConnectionFactory::removeFromPending( const ConnectCallbackPtr& cb, const vector& connectors) { - for (auto p = connectors.begin(); p != connectors.end(); ++p) + for (const auto& connector : connectors) { - auto q = _pending.find(p->connector); + auto q = _pending.find(connector.connector); if (q != _pending.end()) { q->second.erase(cb); @@ -841,9 +837,9 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::connectionStartFailed( void IceInternal::OutgoingConnectionFactory::ConnectCallback::connectors(const vector& connectors) { - for (vector::const_iterator p = connectors.begin(); p != connectors.end(); ++p) + for (const auto& connector : connectors) { - _connectors.push_back(ConnectorInfo(*p, *_endpointsIter)); + _connectors.emplace_back(connector, *_endpointsIter); } if (++_endpointsIter != _endpoints.end()) @@ -1123,9 +1119,9 @@ void IceInternal::IncomingConnectionFactory::updateConnectionObservers() { lock_guard lock(_mutex); - for (const auto& conn : _connections) + for (const auto& connection : _connections) { - conn->updateObserver(); + connection->updateObserver(); } } @@ -1237,11 +1233,11 @@ IceInternal::IncomingConnectionFactory::flushAsyncBatchRequests( { list c = connections(); // connections() is synchronized, so no need to synchronize here. - for (list::const_iterator p = c.begin(); p != c.end(); ++p) + for (const auto& p : c) { try { - outAsync->flushConnection(*p, compress); + outAsync->flushConnection(p, compress); } catch (const LocalException&) { @@ -1702,9 +1698,9 @@ IceInternal::IncomingConnectionFactory::setState(State state) _adapter->getThreadPool()->_register(shared_from_this(), SocketOperationRead); } - for (const auto& conn : _connections) + for (const auto& connection : _connections) { - conn->activate(); + connection->activate(); } break; } @@ -1724,9 +1720,9 @@ IceInternal::IncomingConnectionFactory::setState(State state) } _adapter->getThreadPool()->unregister(shared_from_this(), SocketOperationRead); } - for (const auto& conn : _connections) + for (const auto& connection : _connections) { - conn->hold(); + connection->hold(); } break; } @@ -1756,9 +1752,9 @@ IceInternal::IncomingConnectionFactory::setState(State state) state = StateFinished; } - for (const auto& conn : _connections) + for (const auto& connection : _connections) { - conn->destroy(ConnectionI::ObjectAdapterDeactivated); + connection->destroy(ConnectionI::ObjectAdapterDeactivated); } break; } diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index ef5c1a197fb..2416fd348e7 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -492,7 +492,7 @@ Ice::ConnectionI::close(function response, function::iterator o = _sendStreams.begin(); o != _sendStreams.end(); ++o) + for (auto o = _sendStreams.begin(); o != _sendStreams.end(); ++o) { if (o->outAsync.get() == outAsync.get()) { @@ -918,7 +918,7 @@ Ice::ConnectionI::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, exc } } - for (map::iterator p = _asyncRequests.begin(); p != _asyncRequests.end(); ++p) + for (auto p = _asyncRequests.begin(); p != _asyncRequests.end(); ++p) { if (p->second.get() == outAsync.get()) { @@ -1338,11 +1338,11 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current) // readOp and writeOp are set to the operations that the transport read or write calls from above returned. // They indicate which operations will need to be monitored by the thread pool's selector when this method // returns. - SocketOperation newOp = static_cast(readOp | writeOp); + auto newOp = static_cast(readOp | writeOp); // Operations that are ready. For example, if message was called with SocketOperationRead and the transport // read returned SocketOperationNone, reads are considered done: there's no additional data to read. - SocketOperation readyOp = static_cast(current.operation & ~newOp); + auto readyOp = static_cast(current.operation & ~newOp); if (_state <= StateNotValidated) { @@ -1515,23 +1515,23 @@ ConnectionI::upcall( // if (!sentCBs.empty()) { - for (vector::const_iterator p = sentCBs.begin(); p != sentCBs.end(); ++p) + for (const auto& sentCB : sentCBs) { #if defined(ICE_USE_IOCP) - if (p->invokeSent) + if (sentCB.invokeSent) { - p->outAsync->invokeSent(); + sentCB.outAsync->invokeSent(); } - if (p->receivedReply) + if (sentCB.receivedReply) { - auto o = dynamic_pointer_cast(p->outAsync); + auto o = dynamic_pointer_cast(sentCB.outAsync); if (o->response()) { o->invokeResponse(); } } #else - p->outAsync->invokeSent(); + sentCB.outAsync->invokeSent(); #endif } ++completedUpcallCount; @@ -1732,23 +1732,23 @@ Ice::ConnectionI::finish(bool close) #endif } - for (deque::iterator o = _sendStreams.begin(); o != _sendStreams.end(); ++o) + for (auto& sendStream : _sendStreams) { - o->completed(_exception); - if (o->requestId) // Make sure finished isn't called twice. + sendStream.completed(_exception); + if (sendStream.requestId) // Make sure finished isn't called twice. { - _asyncRequests.erase(o->requestId); + _asyncRequests.erase(sendStream.requestId); } } _sendStreams.clear(); } - for (map::const_iterator q = _asyncRequests.begin(); q != _asyncRequests.end(); ++q) + for (const auto& asyncRequest : _asyncRequests) { - if (q->second->exception(_exception)) + if (asyncRequest.second->exception(_exception)) { - q->second->invokeException(); + asyncRequest.second->invokeException(); } } @@ -1794,7 +1794,7 @@ Ice::ConnectionI::finish(bool close) success = false; } - for (auto& pair : _onClosedList) + for (const auto& pair : _onClosedList) { if (success) { @@ -2823,7 +2823,7 @@ Ice::ConnectionI::sendNextMessages(vector& callbacks) // // No compression, just fill in the message size. // - int32_t sz = static_cast(message->stream->b.size()); + auto sz = static_cast(message->stream->b.size()); const byte* p = reinterpret_cast(&sz); if constexpr (endian::native == endian::big) { @@ -2957,7 +2957,7 @@ Ice::ConnectionI::sendMessage(OutgoingMessage& message) // // No compression, just fill in the message size. // - int32_t sz = static_cast(message.stream->b.size()); + auto sz = static_cast(message.stream->b.size()); const byte* p = reinterpret_cast(&sz); if constexpr (endian::native == endian::big) { @@ -3076,8 +3076,8 @@ Ice::ConnectionI::doCompress(OutputStream& uncompressed, OutputStream& compresse // // Compress the message body, but not the header. // - unsigned int uncompressedLen = static_cast(uncompressed.b.size() - headerSize); - unsigned int compressedLen = static_cast(uncompressedLen * 1.01 + 600); + auto uncompressedLen = static_cast(uncompressed.b.size() - headerSize); + auto compressedLen = static_cast(uncompressedLen * 1.01 + 600); compressed.b.resize(headerSize + sizeof(int32_t) + compressedLen); int bzError = BZ2_bzBuffToBuffCompress( reinterpret_cast(&compressed.b[0]) + headerSize + sizeof(int32_t), @@ -3101,7 +3101,7 @@ Ice::ConnectionI::doCompress(OutputStream& uncompressed, OutputStream& compresse // uncompressed stream. Since the header will be copied, this size // will also be in the header of the compressed stream. // - int32_t compressedSize = static_cast(compressed.b.size()); + auto compressedSize = static_cast(compressed.b.size()); p = reinterpret_cast(&compressedSize); if constexpr (endian::native == endian::big) { @@ -3116,7 +3116,7 @@ Ice::ConnectionI::doCompress(OutputStream& uncompressed, OutputStream& compresse // Add the size of the uncompressed stream before the message body // of the compressed stream. // - int32_t uncompressedSize = static_cast(uncompressed.b.size()); + auto uncompressedSize = static_cast(uncompressed.b.size()); p = reinterpret_cast(&uncompressedSize); if constexpr (endian::native == endian::big) { @@ -3153,8 +3153,8 @@ Ice::ConnectionI::doUncompress(InputStream& compressed, InputStream& uncompresse } uncompressed.resize(static_cast(uncompressedSize)); - unsigned int uncompressedLen = static_cast(uncompressedSize - headerSize); - unsigned int compressedLen = static_cast(compressed.b.size() - headerSize - sizeof(int32_t)); + auto uncompressedLen = static_cast(uncompressedSize - headerSize); + auto compressedLen = static_cast(compressed.b.size() - headerSize - sizeof(int32_t)); int bzError = BZ2_bzBuffToBuffDecompress( reinterpret_cast(&uncompressed.b[0]) + headerSize, &uncompressedLen, @@ -3326,7 +3326,7 @@ Ice::ConnectionI::parseMessage(int32_t& upcallCount, function::iterator q = _asyncRequests.end(); + auto q = _asyncRequests.end(); if (_asyncRequestsHint != _asyncRequests.end()) { diff --git a/cpp/src/Ice/CtrlCHandler.cpp b/cpp/src/Ice/CtrlCHandler.cpp index 626e2f4a05b..c1d4de63977 100644 --- a/cpp/src/Ice/CtrlCHandler.cpp +++ b/cpp/src/Ice/CtrlCHandler.cpp @@ -205,12 +205,12 @@ CtrlCHandler::~CtrlCHandler() // void* status = nullptr; # ifndef NDEBUG - int rc = pthread_kill(_tid, SIGTERM); // NOLINT:cert-pos44-c + int rc = pthread_kill(_tid, SIGTERM); // NOLINT(cert-pos44-c) assert(rc == 0); rc = pthread_join(_tid, &status); assert(rc == 0); # else - pthread_kill(_tid, SIGTERM); // NOLINT:cert-pos44-c + pthread_kill(_tid, SIGTERM); // NOLINT(cert-pos44-c) pthread_join(_tid, &status); # endif } diff --git a/cpp/src/Ice/EndpointFactoryManager.cpp b/cpp/src/Ice/EndpointFactoryManager.cpp index 757457b1d43..1d32c98b3bc 100644 --- a/cpp/src/Ice/EndpointFactoryManager.cpp +++ b/cpp/src/Ice/EndpointFactoryManager.cpp @@ -20,9 +20,9 @@ IceInternal::EndpointFactoryManager::EndpointFactoryManager(InstancePtr instance void IceInternal::EndpointFactoryManager::initialize() const { - for (vector::size_type i = 0; i < _factories.size(); i++) + for (const auto& fact : _factories) { - _factories[i]->initialize(); + fact->initialize(); } } @@ -33,9 +33,9 @@ IceInternal::EndpointFactoryManager::add(const EndpointFactoryPtr& factory) // // TODO: Optimize with a map? // - for (vector::size_type i = 0; i < _factories.size(); i++) + for (const auto& fact : _factories) { - if (_factories[i]->type() == factory->type()) + if (fact->type() == factory->type()) { assert(false); // TODO: Exception? } @@ -50,11 +50,11 @@ IceInternal::EndpointFactoryManager::get(int16_t type) const // // TODO: Optimize with a map? // - for (vector::size_type i = 0; i < _factories.size(); i++) + for (const auto& fact : _factories) { - if (_factories[i]->type() == type) + if (fact->type() == type) { - return _factories[i]; + return fact; } } return nullptr; @@ -89,11 +89,11 @@ IceInternal::EndpointFactoryManager::create(string_view str, bool oaEndpoint) co // // TODO: Optimize with a map? // - for (vector::size_type i = 0; i < _factories.size(); i++) + for (const auto& fact : _factories) { - if (_factories[i]->protocol() == protocol) + if (fact->protocol() == protocol) { - factory = _factories[i]; + factory = fact; } } } diff --git a/cpp/src/Ice/EndpointI.cpp b/cpp/src/Ice/EndpointI.cpp index 65d902d755b..09149c5079b 100644 --- a/cpp/src/Ice/EndpointI.cpp +++ b/cpp/src/Ice/EndpointI.cpp @@ -69,15 +69,15 @@ IceInternal::EndpointI::initWithOptions(vector& args) ostringstream ostr; ostr << '`' << protocol() << " "; - for (vector::iterator p = args.begin(); p != args.end(); ++p) + for (const auto& arg : args) { - if (p->find_first_of(" \t\n\r") != string::npos) + if (arg.find_first_of(" \t\n\r") != string::npos) { - ostr << " \"" << *p << "\""; + ostr << " \"" << arg << "\""; } else { - ostr << " " << *p; + ostr << " " << arg; } } ostr << "'"; diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp index aa032ad1603..6eecdc31c37 100644 --- a/cpp/src/Ice/Exception.cpp +++ b/cpp/src/Ice/Exception.cpp @@ -345,7 +345,7 @@ namespace #elif defined(ICE_LIBBACKTRACE) || defined(ICE_BACKTRACE) - vector::const_iterator p = stackFrames.begin(); + auto p = stackFrames.begin(); int frameIndex = 0; int offset = 0; char** backtraceStrings = nullptr; diff --git a/cpp/src/Ice/FactoryTable.cpp b/cpp/src/Ice/FactoryTable.cpp index df1dfcc508e..fc0341c4068 100644 --- a/cpp/src/Ice/FactoryTable.cpp +++ b/cpp/src/Ice/FactoryTable.cpp @@ -29,7 +29,7 @@ IceInternal::FactoryTable::addExceptionFactory(string_view t, Ice::UserException { lock_guard lock(_mutex); assert(f); - EFTable::iterator i = _eft.find(t); + auto i = _eft.find(t); if (i == _eft.end()) { _eft[string{t}] = EFPair(f, 1); @@ -47,7 +47,7 @@ Ice::UserExceptionFactory IceInternal::FactoryTable::getExceptionFactory(string_view t) const { lock_guard lock(_mutex); - EFTable::const_iterator i = _eft.find(t); + auto i = _eft.find(t); return i != _eft.end() ? i->second.first : Ice::UserExceptionFactory(); } @@ -61,7 +61,7 @@ void IceInternal::FactoryTable::removeExceptionFactory(string_view t) { lock_guard lock(_mutex); - EFTable::iterator i = _eft.find(t); + auto i = _eft.find(t); if (i != _eft.end()) { if (--i->second.second == 0) @@ -79,7 +79,7 @@ IceInternal::FactoryTable::addValueFactory(string_view t, Ice::ValueFactory f) { lock_guard lock(_mutex); assert(f); - VFTable::iterator i = _vft.find(t); + auto i = _vft.find(t); if (i == _vft.end()) { _vft[string{t}] = VFPair(f, 1); @@ -97,7 +97,7 @@ Ice::ValueFactory IceInternal::FactoryTable::getValueFactory(string_view t) const { lock_guard lock(_mutex); - VFTable::const_iterator i = _vft.find(t); + auto i = _vft.find(t); return i != _vft.end() ? i->second.first : nullptr; } @@ -111,7 +111,7 @@ void IceInternal::FactoryTable::removeValueFactory(string_view t) { lock_guard lock(_mutex); - VFTable::iterator i = _vft.find(t); + auto i = _vft.find(t); if (i != _vft.end()) { if (--i->second.second == 0) @@ -129,7 +129,7 @@ IceInternal::FactoryTable::addTypeId(int compactId, string_view typeId) { lock_guard lock(_mutex); assert(!typeId.empty() && compactId >= 0); - TypeIdTable::iterator i = _typeIdTable.find(compactId); + auto i = _typeIdTable.find(compactId); if (i == _typeIdTable.end()) { _typeIdTable[compactId] = TypeIdPair(string{typeId}, 1); @@ -147,7 +147,7 @@ string IceInternal::FactoryTable::getTypeId(int compactId) const { lock_guard lock(_mutex); - TypeIdTable::const_iterator i = _typeIdTable.find(compactId); + auto i = _typeIdTable.find(compactId); return i != _typeIdTable.end() ? i->second.first : string{}; } @@ -155,7 +155,7 @@ void IceInternal::FactoryTable::removeTypeId(int compactId) { lock_guard lock(_mutex); - TypeIdTable::iterator i = _typeIdTable.find(compactId); + auto i = _typeIdTable.find(compactId); if (i != _typeIdTable.end()) { if (--i->second.second == 0) diff --git a/cpp/src/Ice/HttpParser.cpp b/cpp/src/Ice/HttpParser.cpp index c79129ec24b..1233844deac 100644 --- a/cpp/src/Ice/HttpParser.cpp +++ b/cpp/src/Ice/HttpParser.cpp @@ -259,7 +259,7 @@ IceInternal::HttpParser::parse(const byte* begin, const byte* end) { throw WebSocketException("malformed header"); } - HeaderFields::iterator q = _headers.find(_headerName); + auto q = _headers.find(_headerName); assert(q != _headers.end()); q->second.second = q->second.second + " " + bytesToString(start, p); _state = c == CR ? StateHeaderFieldLF : StateHeaderFieldStart; @@ -301,7 +301,7 @@ IceInternal::HttpParser::parse(const byte* begin, const byte* end) if (_headerName.empty()) { _headerName = IceInternal::toLower(bytesToString(start, p)); - HeaderFields::iterator q = _headers.find(_headerName); + auto q = _headers.find(_headerName); // // Add a placeholder entry if necessary. // @@ -362,7 +362,7 @@ IceInternal::HttpParser::parse(const byte* begin, const byte* end) assert(c == CR || c == LF); if (p > start) { - HeaderFields::iterator q = _headers.find(_headerName); + auto q = _headers.find(_headerName); if (q == _headers.end()) { throw WebSocketException("malformed header"); @@ -667,7 +667,7 @@ IceInternal::HttpParser::reason() const bool IceInternal::HttpParser::getHeader(const string& name, string& value, bool toLower) const { - HeaderFields::const_iterator q = _headers.find(IceInternal::toLower(name)); + auto q = _headers.find(IceInternal::toLower(name)); if (q != _headers.end()) { value = IceInternal::trim(q->second.second); @@ -685,9 +685,9 @@ map IceInternal::HttpParser::getHeaders() const { map headers; - for (HeaderFields::const_iterator q = _headers.begin(); q != _headers.end(); ++q) + for (const auto& header : _headers) { - headers.insert(make_pair(q->second.first, IceInternal::trim(q->second.second))); + headers.insert(make_pair(header.second.first, IceInternal::trim(header.second.second))); } return headers; } diff --git a/cpp/src/Ice/IPEndpointI.cpp b/cpp/src/Ice/IPEndpointI.cpp index 182cc591992..3867311f1df 100644 --- a/cpp/src/Ice/IPEndpointI.cpp +++ b/cpp/src/Ice/IPEndpointI.cpp @@ -187,7 +187,7 @@ IceInternal::IPEndpointI::options() const bool IceInternal::IPEndpointI::operator==(const Endpoint& r) const { - const IPEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -223,10 +223,10 @@ IceInternal::IPEndpointI::operator==(const Endpoint& r) const bool IceInternal::IPEndpointI::operator<(const Endpoint& r) const { - const IPEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { - const EndpointI* e = dynamic_cast(&r); + const auto* e = dynamic_cast(&r); if (!e) { return false; @@ -292,9 +292,9 @@ vector IceInternal::IPEndpointI::connectors(const vector
& addresses, const NetworkProxyPtr& proxy) const { vector connectors; - for (unsigned int i = 0; i < addresses.size(); ++i) + for (const auto& address : addresses) { - connectors.push_back(createConnector(addresses[i], proxy)); + connectors.push_back(createConnector(address, proxy)); } return connectors; } @@ -567,15 +567,15 @@ IceInternal::EndpointHostResolver::run() } } - for (deque::const_iterator p = _queue.begin(); p != _queue.end(); ++p) + for (const auto& p : _queue) { Ice::CommunicatorDestroyedException ex(__FILE__, __LINE__); - if (p->observer) + if (p.observer) { - p->observer->failed(ex.ice_id()); - p->observer->detach(); + p.observer->failed(ex.ice_id()); + p.observer->detach(); } - p->exception(make_exception_ptr(ex)); + p.exception(make_exception_ptr(ex)); } _queue.clear(); diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp index 11f7e6cadc6..a926d641adb 100644 --- a/cpp/src/Ice/Initialize.cpp +++ b/cpp/src/Ice/Initialize.cpp @@ -32,7 +32,7 @@ Ice::argsToStringSeq(int argc, const char* const argv[]) StringSeq result; for (int i = 0; i < argc; i++) { - result.push_back(argv[i]); + result.emplace_back(argv[i]); } return result; } diff --git a/cpp/src/Ice/InputStream.cpp b/cpp/src/Ice/InputStream.cpp index 11c09b1bf64..ef23416b7be 100644 --- a/cpp/src/Ice/InputStream.cpp +++ b/cpp/src/Ice/InputStream.cpp @@ -1468,7 +1468,7 @@ Ice::InputStream::EncapsDecoder::unmarshal(int32_t index, const ValuePtr& v) // // Patch all pointers that refer to the instance. // - for (auto& k : patchPos->second) + for (const auto& k : patchPos->second) { k.patchFunc(k.patchAddr, v); } @@ -1494,7 +1494,7 @@ Ice::InputStream::EncapsDecoder::unmarshal(int32_t index, const ValuePtr& v) // each value. We must do this after all values have been // unmarshaled in order to ensure that any value data members // have been properly patched. - for (auto& value : _valueList) + for (const auto& value : _valueList) { value->ice_postUnmarshal(); } @@ -1783,7 +1783,7 @@ Ice::InputStream::EncapsDecoder10::readInstance() if (patchPos != _patchMap.end()) { assert(patchPos->second.size() > 0); - for (auto& k : patchPos->second) + for (const auto& k : patchPos->second) { if (k.classGraphDepth > _classGraphDepth) { diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 876502f31df..f382a8d6163 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -141,11 +141,9 @@ namespace lock_guard lock(staticMutex); int notDestroyedCount = 0; - for (std::list::const_iterator p = instanceList->begin(); - p != instanceList->end(); - ++p) + for (const auto& p : *instanceList) { - if (!(*p)->destroyed()) + if (!p->destroyed()) { notDestroyedCount++; } @@ -676,15 +674,15 @@ IceInternal::Instance::addAllAdminFacets() // FacetMap filteredFacets; - for (FacetMap::iterator p = _adminFacets.begin(); p != _adminFacets.end(); ++p) + for (const auto& adminFacet : _adminFacets) { - if (_adminFacetFilter.empty() || _adminFacetFilter.find(p->first) != _adminFacetFilter.end()) + if (_adminFacetFilter.empty() || _adminFacetFilter.find(adminFacet.first) != _adminFacetFilter.end()) { - _adminAdapter->addFacet(p->second, _adminIdentity, p->first); + _adminAdapter->addFacet(adminFacet.second, _adminIdentity, adminFacet.first); } else { - filteredFacets[p->first] = p->second; + filteredFacets[adminFacet.first] = adminFacet.second; } } _adminFacets.swap(filteredFacets); @@ -778,7 +776,7 @@ IceInternal::Instance::removeAdminFacet(string_view facet) if (_adminAdapter == nullptr || (!_adminFacetFilter.empty() && _adminFacetFilter.find(facet) == _adminFacetFilter.end())) { - FacetMap::iterator p = _adminFacets.find(facet); + auto p = _adminFacets.find(facet); if (p == _adminFacets.end()) { throw NotRegisteredException(__FILE__, __LINE__, "facet", string{facet}); @@ -814,7 +812,7 @@ IceInternal::Instance::findAdminFacet(string_view facet) // if (!_adminAdapter || (!_adminFacetFilter.empty() && _adminFacetFilter.find(facet) == _adminFacetFilter.end())) { - FacetMap::iterator p = _adminFacets.find(facet); + auto p = _adminFacets.find(facet); if (p != _adminFacets.end()) { result = p->second; @@ -1225,9 +1223,9 @@ IceInternal::Instance::initialize(const Ice::CommunicatorPtr& communicator) } else { - for (StringSeq::const_iterator p = retryValues.begin(); p != retryValues.end(); ++p) + for (const auto& retryValue : retryValues) { - istringstream value(*p); + istringstream value(retryValue); int v; if (!(value >> v) || !value.eof()) @@ -1278,7 +1276,7 @@ IceInternal::Instance::getImplicitContext() const auto it = perThreadImplicitContextMap.find(this); if (it == perThreadImplicitContextMap.end()) { - auto r = perThreadImplicitContextMap.emplace(make_pair(this, std::make_shared())); + auto r = perThreadImplicitContextMap.emplace(this, std::make_shared()); return r.first->second; } else @@ -1698,9 +1696,9 @@ IceInternal::Instance::destroy() { Warning out(_initData.logger); out << "The following properties were set but never read:"; - for (set::const_iterator p = unusedProperties.begin(); p != unusedProperties.end(); ++p) + for (const auto& unusedProp : unusedProperties) { - out << "\n " << *p; + out << "\n " << unusedProp; } } } @@ -1797,7 +1795,7 @@ BufSizeWarnInfo IceInternal::Instance::getBufSizeWarnInternal(int16_t type) { BufSizeWarnInfo info; - map::iterator p = _setBufSizeWarn.find(type); + auto p = _setBufSizeWarn.find(type); if (p == _setBufSizeWarn.end()) { info.sndWarn = false; diff --git a/cpp/src/Ice/InstrumentationI.cpp b/cpp/src/Ice/InstrumentationI.cpp index 3ea05f790e1..4311413cfdc 100644 --- a/cpp/src/Ice/InstrumentationI.cpp +++ b/cpp/src/Ice/InstrumentationI.cpp @@ -209,7 +209,7 @@ namespace { if (attribute.compare(0, 8, "context.") == 0) { - Context::const_iterator p = _current.ctx.find(attribute.substr(8)); + auto p = _current.ctx.find(attribute.substr(8)); if (p != _current.ctx.end()) { return p->second; @@ -314,7 +314,7 @@ namespace { if (attribute.compare(0, 8, "context.") == 0) { - Context::const_iterator p = _context.find(attribute.substr(8)); + auto p = _context.find(attribute.substr(8)); if (p != _context.end()) { return p->second; diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp index 2f0ac5eaf76..e7de37aafca 100644 --- a/cpp/src/Ice/LocatorInfo.cpp +++ b/cpp/src/Ice/LocatorInfo.cpp @@ -105,7 +105,7 @@ IceInternal::LocatorManager::get(const LocatorPrx& loc) lock_guard lock(_mutex); - LocatorInfoTable::iterator p = _table.end(); + auto p = _table.end(); if (_tableHint != _table.end()) { @@ -128,7 +128,7 @@ IceInternal::LocatorManager::get(const LocatorPrx& loc) // proxy). // pair locatorKey(locator->ice_getIdentity(), locator->ice_getEncodingVersion()); - map, LocatorTablePtr>::iterator t = _locatorTables.find(locatorKey); + auto t = _locatorTables.find(locatorKey); if (t == _locatorTables.end()) { t = _locatorTables.insert( @@ -412,9 +412,9 @@ IceInternal::LocatorInfo::Request::response(const optional& proxy) _response = true; _proxy = proxy; } - for (vector::const_iterator p = _callbacks.begin(); p != _callbacks.end(); ++p) + for (const auto& callback : _callbacks) { - (*p)->response(_locatorInfo, proxy); + callback->response(_locatorInfo, proxy); } } @@ -439,9 +439,9 @@ IceInternal::LocatorInfo::Request::exception(std::exception_ptr ex) _locatorInfo->finishRequest(_reference, _wellKnownRefs, nullopt, isUserException); _exception = ex; } - for (vector::const_iterator p = _callbacks.begin(); p != _callbacks.end(); ++p) + for (const auto& callback : _callbacks) { - (*p)->exception(_locatorInfo, ex); + callback->exception(_locatorInfo, ex); } } @@ -765,7 +765,7 @@ IceInternal::LocatorInfo::getAdapterRequest(const ReferencePtr& ref) out << "searching for adapter by id\nadapter = " << ref->getAdapterId(); } - map::const_iterator p = _adapterRequests.find(ref->getAdapterId()); + auto p = _adapterRequests.find(ref->getAdapterId()); if (p != _adapterRequests.end()) { return p->second; @@ -786,7 +786,7 @@ IceInternal::LocatorInfo::getObjectRequest(const ReferencePtr& ref) out << "searching for well-known object\nwell-known proxy = " << ref->toString(); } - map::const_iterator p = _objectRequests.find(ref->getIdentity()); + auto p = _objectRequests.find(ref->getIdentity()); if (p != _objectRequests.end()) { return p->second; @@ -809,9 +809,9 @@ IceInternal::LocatorInfo::finishRequest( // Remove the cached references of well-known objects for which we tried // to resolved the endpoints if these endpoints are empty. // - for (vector::const_iterator q = wellKnownRefs.begin(); q != wellKnownRefs.end(); ++q) + for (const auto& wellKnownRef : wellKnownRefs) { - _table->removeObjectReference((*q)->getIdentity()); + _table->removeObjectReference(wellKnownRef->getIdentity()); } } diff --git a/cpp/src/Ice/LoggerAdminI.cpp b/cpp/src/Ice/LoggerAdminI.cpp index 473ab47f4fe..a03a0ba3e04 100644 --- a/cpp/src/Ice/LoggerAdminI.cpp +++ b/cpp/src/Ice/LoggerAdminI.cpp @@ -156,7 +156,7 @@ namespace if (!messageTypes.empty() || !traceCategories.empty() || messageMax > 0) { int count = 0; - LogMessageSeq::reverse_iterator p = logMessages.rbegin(); + auto p = logMessages.rbegin(); while (p != logMessages.rend()) { bool keepIt = false; @@ -211,9 +211,9 @@ namespace void copyProperties(const string& prefix, const PropertiesPtr& from, const PropertiesPtr& to) { PropertyDict dict = from->getPropertiesForPrefix(prefix); - for (PropertyDict::const_iterator p = dict.begin(); p != dict.end(); ++p) + for (const auto& p : dict) { - to->setProperty(p->first, p->second); + to->setProperty(p.first, p.second); } } @@ -235,11 +235,11 @@ namespace if (!extraProps.empty()) { - for (vector::iterator p = extraProps.begin(); p != extraProps.end(); ++p) + for (auto& extraProp : extraProps) { - if (p->find("--") != 0) + if (extraProp.find("--") != 0) { - *p = "--" + *p; + extraProp = "--" + extraProp; } } initData.properties->parseCommandLineOptions("", extraProps); @@ -447,7 +447,7 @@ namespace if ((logMessage.type != LogMessageType::TraceMessage && _maxLogCount > 0) || (logMessage.type == LogMessageType::TraceMessage && _maxTraceCount > 0)) { - list::iterator p = _queue.insert(_queue.end(), logMessage); + auto p = _queue.insert(_queue.end(), logMessage); if (logMessage.type != LogMessageType::TraceMessage) { @@ -505,16 +505,16 @@ namespace // // Queue updated, now find which remote loggers want this message // - for (RemoteLoggerMap::const_iterator q = _remoteLoggerMap.begin(); q != _remoteLoggerMap.end(); ++q) + for (const auto& q : _remoteLoggerMap) { - const Filters& filters = q->second; + const Filters& filters = q.second; if (filters.messageTypes.empty() || filters.messageTypes.count(logMessage.type) != 0) { if (logMessage.type != LogMessageType::TraceMessage || filters.traceCategories.empty() || filters.traceCategories.count(logMessage.traceCategory) != 0) { - remoteLoggers.push_back(q->first); + remoteLoggers.push_back(q.first); } } } @@ -700,8 +700,7 @@ namespace _jobQueue.pop_front(); lock.unlock(); - for (vector::const_iterator p = job->remoteLoggers.begin(); p != job->remoteLoggers.end(); - ++p) + for (auto p = job->remoteLoggers.begin(); p != job->remoteLoggers.end(); ++p) { if (_loggerAdmin->getTraceLevel() > 1) { diff --git a/cpp/src/Ice/LoggerI.cpp b/cpp/src/Ice/LoggerI.cpp index 02229c9bdfe..c75ce9ec9da 100644 --- a/cpp/src/Ice/LoggerI.cpp +++ b/cpp/src/Ice/LoggerI.cpp @@ -22,7 +22,7 @@ namespace mutex outputMutex; // Timeout after which rename will be attempted in case of failures renaming files. That is set to 5 minutes. - const chrono::minutes retryTimeout = chrono::minutes(5); // NOLINT:cert-err58-cpp + const chrono::minutes retryTimeout = chrono::minutes(5); // NOLINT(cert-err58-cpp) } Ice::LoggerI::LoggerI(string prefix, string file, bool convert, size_t sizeMax) diff --git a/cpp/src/Ice/MetricsAdminI.cpp b/cpp/src/Ice/MetricsAdminI.cpp index 3a4e687c4e9..9c81097c62f 100644 --- a/cpp/src/Ice/MetricsAdminI.cpp +++ b/cpp/src/Ice/MetricsAdminI.cpp @@ -20,7 +20,7 @@ using namespace IceMX; namespace { const string suffixes[] = { - // NOLINT:cert-err58-cpp + // NOLINT(cert-err58-cpp) "Disabled", "GroupBy", "Accept.*", @@ -33,13 +33,13 @@ namespace { vector unknownProps; PropertyDict props = properties->getPropertiesForPrefix(prefix); - for (PropertyDict::const_iterator p = props.begin(); p != props.end(); ++p) + for (const auto& p : props) { bool valid = false; - for (size_t i = 0; i < sizeof(suffixes) / sizeof(*suffixes); ++i) + for (const auto& suffix : suffixes) { - string prop = prefix + suffixes[i]; - if (IceInternal::match(p->first, prop)) + string prop = prefix + suffix; + if (IceInternal::match(p.first, prop)) { valid = true; break; @@ -47,7 +47,7 @@ namespace } if (!valid) { - unknownProps.push_back(p->first); + unknownProps.push_back(p.first); } } @@ -67,15 +67,15 @@ namespace { vector regexps; PropertyDict rules = properties->getPropertiesForPrefix(name + '.'); - for (PropertyDict::const_iterator p = rules.begin(); p != rules.end(); ++p) + for (const auto& rule : rules) { try { - regexps.push_back(make_shared(p->first.substr(name.length() + 1), p->second)); + regexps.push_back(make_shared(rule.first.substr(name.length() + 1), rule.second)); } catch (const std::exception&) { - throw invalid_argument("invalid regular expression '" + p->second + "' for '" + p->first + "'"); + throw invalid_argument("invalid regular expression '" + rule.second + "' for '" + rule.first + "'"); } } return regexps; @@ -104,35 +104,35 @@ MetricsMapI::MetricsMapI(const std::string& mapPrefix, const PropertiesPtr& prop validateProperties(mapPrefix, properties); string groupBy = properties->getPropertyWithDefault(mapPrefix + "GroupBy", "id"); - vector& groupByAttributes = const_cast&>(_groupByAttributes); - vector& groupBySeparators = const_cast&>(_groupBySeparators); + auto& groupByAttributes = const_cast&>(_groupByAttributes); + auto& groupBySeparators = const_cast&>(_groupBySeparators); if (!groupBy.empty()) { string v; bool attribute = IceInternal::isAlpha(groupBy[0]) || IceInternal::isDigit(groupBy[0]); if (!attribute) { - groupByAttributes.push_back(""); + groupByAttributes.emplace_back(""); } - for (string::const_iterator p = groupBy.begin(); p != groupBy.end(); ++p) + for (char p : groupBy) { - bool isAlphaNum = IceInternal::isAlpha(*p) || IceInternal::isDigit(*p) || *p == '.'; + bool isAlphaNum = IceInternal::isAlpha(p) || IceInternal::isDigit(p) || p == '.'; if (attribute && !isAlphaNum) { groupByAttributes.push_back(v); - v = *p; + v = p; attribute = false; } else if (!attribute && isAlphaNum) { groupBySeparators.push_back(v); - v = *p; + v = p; attribute = true; } else { - v += *p; + v += p; } } @@ -180,9 +180,9 @@ MetricsViewI::MetricsViewI(string name) : _name(std::move(name)) {} void MetricsViewI::destroy() { - for (map::const_iterator p = _maps.begin(); p != _maps.end(); ++p) + for (const auto& map : _maps) { - p->second->destroy(); + map.second->destroy(); } } @@ -206,7 +206,7 @@ MetricsViewI::addOrUpdateMap( if (mapProps.empty()) { // This map isn't configured for this view. - map::iterator q = _maps.find(mapName); + auto q = _maps.find(mapName); if (q != _maps.end()) { q->second->destroy(); @@ -225,7 +225,7 @@ MetricsViewI::addOrUpdateMap( if (properties->getPropertyAsInt(mapPrefix + "Disabled") > 0) { // This map is disabled for this view. - map::iterator q = _maps.find(mapName); + auto q = _maps.find(mapName); if (q != _maps.end()) { q->second->destroy(); @@ -235,7 +235,7 @@ MetricsViewI::addOrUpdateMap( return false; } - map::iterator q = _maps.find(mapName); + auto q = _maps.find(mapName); if (q != _maps.end() && q->second->getProperties() == mapProps) { return false; // The map configuration didn't change, no need to re-create. @@ -263,7 +263,7 @@ MetricsViewI::addOrUpdateMap( bool MetricsViewI::removeMap(const string& mapName) { - map::iterator q = _maps.find(mapName); + auto q = _maps.find(mapName); if (q != _maps.end()) { q->second->destroy(); @@ -277,9 +277,9 @@ MetricsView MetricsViewI::getMetrics() { MetricsView metrics; - for (map::const_iterator p = _maps.begin(); p != _maps.end(); ++p) + for (const auto& map : _maps) { - metrics.insert(make_pair(p->first, p->second->getMetrics())); + metrics.insert(make_pair(map.first, map.second->getMetrics())); } return metrics; } @@ -287,7 +287,7 @@ MetricsViewI::getMetrics() MetricsFailuresSeq MetricsViewI::getFailures(const string& mapName) { - map::const_iterator p = _maps.find(mapName); + auto p = _maps.find(mapName); if (p != _maps.end()) { return p->second->getFailures(); @@ -298,7 +298,7 @@ MetricsViewI::getFailures(const string& mapName) MetricsFailures MetricsViewI::getFailures(const string& mapName, const string& id) { - map::const_iterator p = _maps.find(mapName); + auto p = _maps.find(mapName); if (p != _maps.end()) { return p->second->getFailures(id); @@ -310,9 +310,9 @@ vector MetricsViewI::getMaps() const { vector maps; - for (map::const_iterator p = _maps.begin(); p != _maps.end(); ++p) + for (const auto& map : _maps) { - maps.push_back(p->first); + maps.push_back(map.first); } return maps; } @@ -320,7 +320,7 @@ MetricsViewI::getMaps() const MetricsMapIPtr MetricsViewI::getMap(const string& mapName) const { - map::const_iterator p = _maps.find(mapName); + auto p = _maps.find(mapName); if (p != _maps.end()) { return p->second; @@ -341,9 +341,9 @@ void MetricsAdminI::destroy() { lock_guard lock(_mutex); - for (map::const_iterator p = _views.begin(); p != _views.end(); ++p) + for (const auto& view : _views) { - p->second->destroy(); + view.second->destroy(); } } @@ -357,9 +357,9 @@ MetricsAdminI::updateViews() PropertyDict viewsProps = _properties->getPropertiesForPrefix(viewsPrefix); map views; _disabledViews.clear(); - for (PropertyDict::const_iterator p = viewsProps.begin(); p != viewsProps.end(); ++p) + for (const auto& viewsProp : viewsProps) { - string viewName = p->first.substr(viewsPrefix.size()); + string viewName = viewsProp.first.substr(viewsPrefix.size()); string::size_type dotPos = viewName.find('.'); if (dotPos != string::npos) { @@ -382,7 +382,7 @@ MetricsAdminI::updateViews() // // Create the view or update it. // - map::const_iterator q = _views.find(viewName); + auto q = _views.find(viewName); if (q == _views.end()) { q = views @@ -394,11 +394,11 @@ MetricsAdminI::updateViews() q = views.insert(make_pair(viewName, q->second)).first; } - for (map::const_iterator r = _factories.begin(); r != _factories.end(); ++r) + for (const auto& fact : _factories) { - if (q->second->addOrUpdateMap(_properties, r->first, r->second, _logger)) + if (q->second->addOrUpdateMap(_properties, fact.first, fact.second, _logger)) { - updatedMaps.insert(r->second); + updatedMaps.insert(fact.second); } } } @@ -407,16 +407,16 @@ MetricsAdminI::updateViews() // // Go through removed views to collect maps to update. // - for (map::const_iterator p = views.begin(); p != views.end(); ++p) + for (const auto& view : views) { - if (_views.find(p->first) == _views.end()) + if (_views.find(view.first) == _views.end()) { - vector maps = p->second->getMaps(); - for (vector::const_iterator q = maps.begin(); q != maps.end(); ++q) + vector maps = view.second->getMaps(); + for (const auto& map : maps) { - updatedMaps.insert(_factories[*q]); + updatedMaps.insert(_factories[map]); } - p->second->destroy(); + view.second->destroy(); } } } @@ -424,9 +424,9 @@ MetricsAdminI::updateViews() // // Call the updaters to update the maps. // - for (set::const_iterator p = updatedMaps.begin(); p != updatedMaps.end(); ++p) + for (const auto& updatedMap : updatedMaps) { - (*p)->update(); + updatedMap->update(); } } @@ -437,7 +437,7 @@ MetricsAdminI::unregisterMap(const std::string& mapName) MetricsMapFactoryPtr factory; { lock_guard lock(_mutex); - map::iterator p = _factories.find(mapName); + auto p = _factories.find(mapName); if (p == _factories.end()) { return; @@ -458,9 +458,9 @@ MetricsAdminI::getMetricsViewNames(Ice::StringSeq& disabledViews, const Current& Ice::StringSeq enabledViews; lock_guard lock(_mutex); - for (map::const_iterator p = _views.begin(); p != _views.end(); ++p) + for (const auto& view : _views) { - enabledViews.push_back(p->first); + enabledViews.push_back(view.first); } disabledViews.insert(disabledViews.end(), _disabledViews.begin(), _disabledViews.end()); return enabledViews; @@ -531,9 +531,9 @@ MetricsAdminI::getMaps(const string& mapName) const { lock_guard lock(_mutex); vector maps; - for (std::map::const_iterator p = _views.begin(); p != _views.end(); ++p) + for (const auto& view : _views) { - MetricsMapIPtr map = p->second->getMap(mapName); + MetricsMapIPtr map = view.second->getMap(mapName); if (map) { maps.push_back(map); @@ -551,7 +551,7 @@ MetricsAdminI::getLogger() const MetricsViewIPtr MetricsAdminI::getMetricsView(const std::string& name) { - std::map::const_iterator p = _views.find(name); + auto p = _views.find(name); if (p == _views.end()) { if (_disabledViews.find(name) == _disabledViews.end()) @@ -566,9 +566,9 @@ MetricsAdminI::getMetricsView(const std::string& name) void MetricsAdminI::updated(const PropertyDict& props) { - for (PropertyDict::const_iterator p = props.begin(); p != props.end(); ++p) + for (const auto& prop : props) { - if (p->first.find("IceMX.") == 0) + if (prop.first.find("IceMX.") == 0) { // Update the metrics views using the new configuration. try @@ -589,9 +589,9 @@ bool MetricsAdminI::addOrUpdateMap(const std::string& mapName, const MetricsMapFactoryPtr& factory) { bool updated = false; - for (std::map::const_iterator p = _views.begin(); p != _views.end(); ++p) + for (const auto& view : _views) { - updated |= p->second->addOrUpdateMap(_properties, mapName, factory, _logger); + updated |= view.second->addOrUpdateMap(_properties, mapName, factory, _logger); } return updated; } @@ -600,9 +600,9 @@ bool MetricsAdminI::removeMap(const std::string& mapName) { bool updated = false; - for (std::map::const_iterator p = _views.begin(); p != _views.end(); ++p) + for (const auto& view : _views) { - updated |= p->second->removeMap(mapName); + updated |= view.second->removeMap(mapName); } return updated; } diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp index ff0da477652..6e14dc4e9e4 100644 --- a/cpp/src/Ice/Network.cpp +++ b/cpp/src/Ice/Network.cpp @@ -339,12 +339,12 @@ namespace set seen; vector
tmp; tmp.swap(result); - for (vector
::const_iterator p = tmp.begin(); p != tmp.end(); ++p) + for (const auto& p : tmp) { - if (seen.find(*p) == seen.end()) + if (seen.find(p) == seen.end()) { - result.push_back(*p); - seen.insert(*p); + result.push_back(p); + seen.insert(p); } } return result; @@ -496,7 +496,7 @@ namespace { if (curr->ifa_addr && curr->ifa_addr->sa_family == AF_INET6) { - struct sockaddr_in6* ipv6Addr = reinterpret_cast(curr->ifa_addr); + auto* ipv6Addr = reinterpret_cast(curr->ifa_addr); if (memcmp(&addr, &ipv6Addr->sin6_addr, sizeof(in6_addr)) == 0) { index = static_cast(if_nametoindex(curr->ifa_name)); @@ -847,9 +847,9 @@ IceInternal::getAddresses( } bool found = false; - for (unsigned int i = 0; i < result.size(); ++i) + for (const auto& i : result) { - if (compareAddress(result[i], addr) == 0) + if (compareAddress(i, addr) == 0) { found = true; break; @@ -1058,7 +1058,7 @@ IceInternal::addrToString(const Address& addr) void IceInternal::fdToLocalAddress(SOCKET fd, Address& addr) { - socklen_t len = static_cast(sizeof(sockaddr_storage)); + auto len = static_cast(sizeof(sockaddr_storage)); if (getsockname(fd, &addr.sa, &len) == SOCKET_ERROR) { throw SocketException(__FILE__, __LINE__, getSocketErrno()); @@ -1068,7 +1068,7 @@ IceInternal::fdToLocalAddress(SOCKET fd, Address& addr) bool IceInternal::fdToRemoteAddress(SOCKET fd, Address& addr) { - socklen_t len = static_cast(sizeof(sockaddr_storage)); + auto len = static_cast(sizeof(sockaddr_storage)); if (getpeername(fd, &addr.sa, &len) == SOCKET_ERROR) { if (notConnected()) @@ -1215,25 +1215,25 @@ IceInternal::getHostsForEndpointExpand(const string& host, ProtocolSupport proto if (isWildcard(host, protocolSupport, ipv4Wildcard)) { vector
addrs = getLocalAddresses(ipv4Wildcard ? EnableIPv4 : protocolSupport, includeLoopback, false); - for (vector
::const_iterator p = addrs.begin(); p != addrs.end(); ++p) + for (const auto& addr : addrs) { // // NOTE: We don't publish link-local addresses as in most cases // these are not desired to be published and in some cases // will not work without extra configuration. // - if (!isLinklocal(*p)) + if (!isLinklocal(addr)) { - hosts.push_back(inetAddrToString(*p)); + hosts.push_back(inetAddrToString(addr)); } } if (hosts.empty()) { // Return loopback if no other local addresses are available. addrs = getLoopbackAddresses(protocolSupport); - for (vector
::const_iterator p = addrs.begin(); p != addrs.end(); ++p) + for (const auto& addr : addrs) { - hosts.push_back(inetAddrToString(*p)); + hosts.push_back(inetAddrToString(addr)); } } } @@ -1248,9 +1248,9 @@ IceInternal::getInterfacesForMulticast(const string& intf, ProtocolSupport proto if (isWildcard(intf, protocolSupport, ipv4Wildcard)) { vector
addrs = getLocalAddresses(ipv4Wildcard ? EnableIPv4 : protocolSupport, true, true); - for (vector
::const_iterator p = addrs.begin(); p != addrs.end(); ++p) + for (const auto& addr : addrs) { - interfaces.push_back(inetAddrToString(*p)); // We keep link local addresses for multicast + interfaces.push_back(inetAddrToString(addr)); // We keep link local addresses for multicast } } if (interfaces.empty()) @@ -1498,19 +1498,19 @@ IceInternal::setMcastGroup(SOCKET fd, const Address& group, const string& intf) { vector interfaces = getInterfacesForMulticast(intf, getProtocolSupport(group)); set indexes; - for (vector::const_iterator p = interfaces.begin(); p != interfaces.end(); ++p) + for (const auto& interface : interfaces) { int rc = 0; if (group.saStorage.ss_family == AF_INET) { struct ip_mreq mreq; mreq.imr_multiaddr = group.saIn.sin_addr; - mreq.imr_interface = getInterfaceAddress(*p); + mreq.imr_interface = getInterfaceAddress(interface); rc = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, reinterpret_cast(&mreq), int(sizeof(mreq))); } else { - int index = getInterfaceIndex(*p); + int index = getInterfaceIndex(interface); if (indexes.find(index) == indexes.end()) // Don't join twice the same interface (if it has multiple IPs) { indexes.insert(index); @@ -1592,7 +1592,7 @@ IceInternal::doBind(SOCKET fd, const Address& addr, const string&) } Address local; - socklen_t len = static_cast(sizeof(sockaddr_storage)); + auto len = static_cast(sizeof(sockaddr_storage)); #ifdef NDEBUG getsockname(fd, &local.sa, &len); #else @@ -1851,7 +1851,7 @@ IceInternal::doFinishConnect(SOCKET fd) #endif int val; - socklen_t len = static_cast(sizeof(int)); + auto len = static_cast(sizeof(int)); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast(&val), &len) == SOCKET_ERROR) { throw SocketException(__FILE__, __LINE__, getSocketErrno()); diff --git a/cpp/src/Ice/ObjectAdapterFactory.cpp b/cpp/src/Ice/ObjectAdapterFactory.cpp index fd2ccb7d396..d7aeccec661 100644 --- a/cpp/src/Ice/ObjectAdapterFactory.cpp +++ b/cpp/src/Ice/ObjectAdapterFactory.cpp @@ -210,13 +210,13 @@ IceInternal::ObjectAdapterFactory::findObjectAdapter(const ReferencePtr& referen adapters = _adapters; } - for (list>::iterator p = adapters.begin(); p != adapters.end(); ++p) + for (const auto& adapter : adapters) { try { - if ((*p)->isLocal(reference)) + if (adapter->isLocal(reference)) { - return *p; + return adapter; } } catch (const ObjectAdapterDestroyedException&) @@ -238,7 +238,7 @@ IceInternal::ObjectAdapterFactory::removeObjectAdapter(const ObjectAdapterPtr& a return; } - for (list>::iterator p = _adapters.begin(); p != _adapters.end(); ++p) + for (auto p = _adapters.begin(); p != _adapters.end(); ++p) { if (*p == adapter) { @@ -261,9 +261,9 @@ IceInternal::ObjectAdapterFactory::flushAsyncBatchRequests( adapters = _adapters; } - for (list>::const_iterator p = adapters.begin(); p != adapters.end(); ++p) + for (const auto& adapter : adapters) { - (*p)->flushAsyncBatchRequests(outAsync, compressBatch); + adapter->flushAsyncBatchRequests(outAsync, compressBatch); } } diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index a9565ff9999..f8f24fa8fbf 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -700,9 +700,9 @@ Ice::ObjectAdapterI::flushAsyncBatchRequests(const CommunicatorFlushBatchAsyncPt f = _incomingConnectionFactories; } - for (vector::const_iterator p = f.begin(); p != f.end(); ++p) + for (const auto& p : f) { - (*p)->flushAsyncBatchRequests(outAsync, compress); + p->flushAsyncBatchRequests(outAsync, compress); } } diff --git a/cpp/src/Ice/OpaqueEndpointI.cpp b/cpp/src/Ice/OpaqueEndpointI.cpp index d561fc30c95..c3102ff0671 100644 --- a/cpp/src/Ice/OpaqueEndpointI.cpp +++ b/cpp/src/Ice/OpaqueEndpointI.cpp @@ -16,7 +16,7 @@ using namespace IceInternal; namespace { - static string opaqueEndpointProtocol = "opaque"; // NOLINT:cert-err58-cpp + static string opaqueEndpointProtocol = "opaque"; // NOLINT(cert-err58-cpp) static string opaqueEndpointConnectionId; } @@ -188,7 +188,7 @@ IceInternal::OpaqueEndpointI::options() const bool IceInternal::OpaqueEndpointI::operator==(const Endpoint& r) const { - const OpaqueEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -220,10 +220,10 @@ IceInternal::OpaqueEndpointI::operator==(const Endpoint& r) const bool IceInternal::OpaqueEndpointI::operator<(const Endpoint& r) const { - const OpaqueEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { - const EndpointI* e = dynamic_cast(&r); + const auto* e = dynamic_cast(&r); if (!e) { return false; @@ -323,13 +323,13 @@ IceInternal::OpaqueEndpointI::checkOption(const string& option, const string& ar __LINE__, "no argument provided for -v option in endpoint '" + endpoint + "'"); } - for (string::size_type i = 0; i < argument.size(); ++i) + for (char i : argument) { - if (!Base64::isBase64(argument[i])) + if (!Base64::isBase64(i)) { ostringstream os; - os << "invalid base64 character '" << argument[i] << "' (ordinal " << static_cast(argument[i]) - << ") in endpoint '" << endpoint << "'"; + os << "invalid base64 character '" << i << "' (ordinal " << static_cast(i) << ") in endpoint '" + << endpoint << "'"; throw ParseException(__FILE__, __LINE__, os.str()); } } diff --git a/cpp/src/Ice/Options.cpp b/cpp/src/Ice/Options.cpp index c1118f46e81..5fbe4ac0f87 100644 --- a/cpp/src/Ice/Options.cpp +++ b/cpp/src/Ice/Options.cpp @@ -552,7 +552,7 @@ IceInternal::Options::parse(const StringVector& args) if (pos->second->repeat == NoRepeat) { - set::iterator seenPos = seenNonRepeatableOpts.find(opt); + auto seenPos = seenNonRepeatableOpts.find(opt); if (seenPos != seenNonRepeatableOpts.end()) { string err = "`--"; @@ -600,7 +600,7 @@ IceInternal::Options::parse(const StringVector& args) if (pos->second->repeat == NoRepeat) { - set::iterator seenPos = seenNonRepeatableOpts.find(opt); + auto seenPos = seenNonRepeatableOpts.find(opt); if (seenPos != seenNonRepeatableOpts.end()) { string err = "`-"; @@ -686,7 +686,7 @@ IceInternal::Options::parse(int argc, const char* const argv[]) StringVector vec; for (int i = 0; i < argc; ++i) { - vec.push_back(argv[i]); + vec.emplace_back(argv[i]); } return parse(vec); } @@ -699,7 +699,7 @@ IceInternal::Options::isSet(const string& opt) const throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); } - ValidOpts::const_iterator pos = checkOptIsValid(opt); + auto pos = checkOptIsValid(opt); return pos->second->repeat == NoRepeat ? _opts.find(opt) != _opts.end() : _ropts.find(opt) != _ropts.end(); } @@ -711,7 +711,7 @@ IceInternal::Options::optArg(const string& opt) const throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); } - ValidOpts::const_iterator pos = checkOptHasArg(opt); + auto pos = checkOptHasArg(opt); if (pos->second->repeat == Repeat) { @@ -725,7 +725,7 @@ IceInternal::Options::optArg(const string& opt) const throw invalid_argument(err); } - Opts::const_iterator p = _opts.find(opt); + auto p = _opts.find(opt); if (p == _opts.end()) { return ""; @@ -741,7 +741,7 @@ IceInternal::Options::argVec(const string& opt) const throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); } - ValidOpts::const_iterator pos = checkOptHasArg(opt); + auto pos = checkOptHasArg(opt); if (pos->second->repeat == NoRepeat) { @@ -754,7 +754,7 @@ IceInternal::Options::argVec(const string& opt) const throw invalid_argument(err); } - ROpts::const_iterator p = _ropts.find(opt); + auto p = _ropts.find(opt); return p == _ropts.end() ? StringVector() : p->second->vals; } @@ -808,7 +808,7 @@ IceInternal::Options::addValidOpt( IceInternal::Options::ValidOpts::iterator IceInternal::Options::checkOpt(const string& opt, LengthType lt) { - ValidOpts::iterator pos = _validOpts.find(opt); + auto pos = _validOpts.find(opt); if (pos == _validOpts.end()) { string err = "invalid option: `-"; @@ -876,12 +876,12 @@ IceInternal::Options::setRepeatingOpt(const string& opt, const string& val) return; } - ValidOpts::const_iterator vpos = _validOpts.find(opt); + auto vpos = _validOpts.find(opt); assert(vpos != _validOpts.end()); - ROpts::iterator pos = _ropts.find(opt); + auto pos = _ropts.find(opt); const string synonym = getSynonym(opt); - ROpts::iterator spos = _ropts.find(synonym); + auto spos = _ropts.find(synonym); if (pos != _ropts.end()) { @@ -930,7 +930,7 @@ IceInternal::Options::setRepeatingOpt(const string& opt, const string& val) IceInternal::Options::ValidOpts::const_iterator IceInternal::Options::checkOptIsValid(const string& opt) const { - ValidOpts::const_iterator pos = _validOpts.find(opt); + auto pos = _validOpts.find(opt); if (pos == _validOpts.end()) { string err = "'"; @@ -944,7 +944,7 @@ IceInternal::Options::checkOptIsValid(const string& opt) const IceInternal::Options::ValidOpts::const_iterator IceInternal::Options::checkOptHasArg(const string& opt) const { - ValidOpts::const_iterator pos = checkOptIsValid(opt); + auto pos = checkOptIsValid(opt); if (pos->second->arg == NoArg) { string err = "`-"; @@ -972,6 +972,6 @@ IceInternal::Options::updateSynonyms(const ::std::string& shortOpt, const ::std: string IceInternal::Options::getSynonym(const ::std::string& optName) const { - Synonyms::const_iterator pos = _synonyms.find(optName); + auto pos = _synonyms.find(optName); return pos != _synonyms.end() ? pos->second : string(""); } diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index e32e769e1d9..1188fe694fb 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -184,14 +184,14 @@ OutgoingAsyncBase::cancel() void OutgoingAsyncBase::attachRemoteObserver(const ConnectionInfoPtr& c, const EndpointPtr& endpt, std::int32_t requestId) { - const std::int32_t size = static_cast(_os.b.size() - headerSize - 4); + const auto size = static_cast(_os.b.size() - headerSize - 4); _childObserver.attach(getObserver().getRemoteObserver(c, endpt, requestId, size)); } void OutgoingAsyncBase::attachCollocatedObserver(const ObjectAdapterPtr& adapter, std::int32_t requestId) { - const std::int32_t size = static_cast(_os.b.size() - headerSize - 4); + const auto size = static_cast(_os.b.size() - headerSize - 4); _childObserver.attach(getObserver().getCollocatedObserver(adapter, requestId, size)); } diff --git a/cpp/src/Ice/OutputUtil.h b/cpp/src/Ice/OutputUtil.h index ec0dbc1d057..733d68b7da3 100644 --- a/cpp/src/Ice/OutputUtil.h +++ b/cpp/src/Ice/OutputUtil.h @@ -113,9 +113,9 @@ namespace IceInternal template inline Output& operator<<(Output& out, const std::vector& val) { - for (typename std::vector::const_iterator p = val.begin(); p != val.end(); ++p) + for (const auto& element : val) { - out << *p; + out << element; } return out; } diff --git a/cpp/src/Ice/PluginManagerI.cpp b/cpp/src/Ice/PluginManagerI.cpp index c4156c36cff..a06ad68d948 100644 --- a/cpp/src/Ice/PluginManagerI.cpp +++ b/cpp/src/Ice/PluginManagerI.cpp @@ -74,11 +74,11 @@ Ice::PluginManagerI::initializePlugins() vector initializedPlugins; try { - for (PluginInfoList::iterator p = _plugins.begin(); p != _plugins.end(); ++p) + for (const auto& plugin : _plugins) { try { - p->plugin->initialize(); + plugin.plugin->initialize(); } catch (const Ice::PluginInitializationException&) { @@ -87,16 +87,16 @@ Ice::PluginManagerI::initializePlugins() catch (const std::exception& ex) { ostringstream os; - os << "plugin '" << p->name << "' initialization failed:\n" << ex.what(); + os << "plugin '" << plugin.name << "' initialization failed:\n" << ex.what(); throw PluginInitializationException(__FILE__, __LINE__, os.str()); } catch (...) { ostringstream os; - os << "plugin '" << p->name << "' initialization failed:\nunknown exception"; + os << "plugin '" << plugin.name << "' initialization failed:\nunknown exception"; throw PluginInitializationException(__FILE__, __LINE__, os.str()); } - initializedPlugins.push_back(p->plugin); + initializedPlugins.push_back(plugin.plugin); } } catch (...) @@ -105,7 +105,7 @@ Ice::PluginManagerI::initializePlugins() // Destroy the plug-ins that have been successfully initialized, in the // reverse order. // - for (vector::reverse_iterator p = initializedPlugins.rbegin(); p != initializedPlugins.rend(); ++p) + for (auto p = initializedPlugins.rbegin(); p != initializedPlugins.rend(); ++p) { try { @@ -128,9 +128,9 @@ Ice::PluginManagerI::getPlugins() lock_guard lock(_mutex); StringSeq names; - for (PluginInfoList::iterator p = _plugins.begin(); p != _plugins.end(); ++p) + for (const auto& plugin : _plugins) { - names.push_back(p->name); + names.push_back(plugin.name); } return names; } @@ -188,7 +188,7 @@ Ice::PluginManagerI::destroy() noexcept // Destroy the plug-ins that have been successfully initialized, in the // reverse order. // - for (PluginInfoList::reverse_iterator p = _plugins.rbegin(); p != _plugins.rend(); ++p) + for (auto p = _plugins.rbegin(); p != _plugins.rend(); ++p) { try { @@ -241,18 +241,18 @@ Ice::PluginManagerI::loadPlugins(int& argc, const char* argv[]) // if (loadOnInitialization) { - for (vector::const_iterator p = loadOnInitialization->begin(); p != loadOnInitialization->end(); ++p) + for (const auto& p : *loadOnInitialization) { - string property = prefix + *p; - PropertyDict::iterator r = plugins.find(property); + string property = prefix + p; + auto r = plugins.find(property); if (r != plugins.end()) { - loadPlugin(*p, r->second, cmdArgs); + loadPlugin(p, r->second, cmdArgs); plugins.erase(r); } else { - loadPlugin(*p, "", cmdArgs); + loadPlugin(p, "", cmdArgs); } } } @@ -269,17 +269,15 @@ Ice::PluginManagerI::loadPlugins(int& argc, const char* argv[]) // remaining plug-ins. // StringSeq loadOrder = properties->getIcePropertyAsList("Ice.PluginLoadOrder"); - for (StringSeq::const_iterator p = loadOrder.begin(); p != loadOrder.end(); ++p) + for (const auto& name : loadOrder) { - string name = *p; - if (findPlugin(name)) { throw PluginInitializationException(__FILE__, __LINE__, "plug-in '" + name + "' already loaded"); } string property = prefix + name; - PropertyDict::iterator r = plugins.find(property); + auto r = plugins.find(property); if (r != plugins.end()) { libraryLoaded |= loadPlugin(name, r->second, cmdArgs); @@ -358,7 +356,7 @@ Ice::PluginManagerI::loadPlugin(const string& name, const string& pluginSpec, St // if (factories) { - map::const_iterator p = factories->find(name); + auto p = factories->find(name); if (p != factories->end()) { factory = p->second; diff --git a/cpp/src/Ice/Properties.cpp b/cpp/src/Ice/Properties.cpp index 6ac85c3478a..363a5927e72 100644 --- a/cpp/src/Ice/Properties.cpp +++ b/cpp/src/Ice/Properties.cpp @@ -93,9 +93,9 @@ Ice::Properties::Properties(StringSeq& args, const PropertiesPtr& defaults) _optInPrefixes = defaults->_optInPrefixes; } - StringSeq::iterator q = args.begin(); + auto q = args.begin(); - map::iterator p = _properties.find("Ice.ProgramName"); + auto p = _properties.find("Ice.ProgramName"); if (p == _properties.end()) { if (q != args.end()) @@ -165,7 +165,7 @@ Ice::Properties::getProperty(string_view key) noexcept { lock_guard lock(_mutex); - map::iterator p = _properties.find(key); + auto p = _properties.find(key); if (p != _properties.end()) { p->second.used = true; @@ -189,7 +189,7 @@ Ice::Properties::getPropertyWithDefault(string_view key, string_view value) noex { lock_guard lock(_mutex); - map::iterator p = _properties.find(key); + auto p = _properties.find(key); if (p != _properties.end()) { p->second.used = true; @@ -228,7 +228,7 @@ Ice::Properties::getPropertyAsIntWithDefault(string_view key, int32_t value) { lock_guard lock(_mutex); - map::iterator p = _properties.find(key); + auto p = _properties.find(key); if (p != _properties.end()) { p->second.used = true; @@ -265,7 +265,7 @@ Ice::Properties::getPropertyAsListWithDefault(string_view key, const StringSeq& { lock_guard lock(_mutex); - map::iterator p = _properties.find(key); + auto p = _properties.find(key); if (p != _properties.end()) { p->second.used = true; @@ -294,12 +294,12 @@ Ice::Properties::getPropertiesForPrefix(string_view prefix) noexcept lock_guard lock(_mutex); PropertyDict result; - for (map::iterator p = _properties.begin(); p != _properties.end(); ++p) + for (auto& prop : _properties) { - if (prefix.empty() || p->first.compare(0, prefix.size(), prefix) == 0) + if (prefix.empty() || prop.first.compare(0, prefix.size(), prefix) == 0) { - p->second.used = true; - result[p->first] = p->second.value; + prop.second.used = true; + result[prop.first] = prop.second.value; } } @@ -351,7 +351,7 @@ Ice::Properties::setProperty(string_view key, string_view value) if (!value.empty()) { PropertyValue pv{string{value}, false}; - map::const_iterator p = _properties.find(currentKey); + auto p = _properties.find(currentKey); if (p != _properties.end()) { pv.used = p->second.used; @@ -371,9 +371,9 @@ Ice::Properties::getCommandLineOptions() noexcept StringSeq result; result.reserve(_properties.size()); - for (map::const_iterator p = _properties.begin(); p != _properties.end(); ++p) + for (const auto& prop : _properties) { - result.push_back("--" + p->first + "=" + p->second.value); + result.push_back("--" + prop.first + "=" + prop.second.value); } return result; } @@ -564,11 +564,11 @@ Ice::Properties::getUnusedProperties() { lock_guard lock(_mutex); set unusedProperties; - for (map::const_iterator p = _properties.begin(); p != _properties.end(); ++p) + for (const auto& prop : _properties) { - if (!p->second.used) + if (!prop.second.used) { - unusedProperties.insert(p->first); + unusedProperties.insert(prop.first); } } return unusedProperties; @@ -822,9 +822,9 @@ Ice::Properties::loadConfig() { vector files; IceInternal::splitString(value, ",", files); - for (vector::const_iterator i = files.begin(); i != files.end(); ++i) + for (const auto& file : files) { - load(IceInternal::trim(string{*i})); + load(IceInternal::trim(string{file})); } PropertyValue pv{std::move(value), true}; diff --git a/cpp/src/Ice/PropertiesAdminI.cpp b/cpp/src/Ice/PropertiesAdminI.cpp index 66b8e6c7d86..86e10cbc920 100644 --- a/cpp/src/Ice/PropertiesAdminI.cpp +++ b/cpp/src/Ice/PropertiesAdminI.cpp @@ -59,7 +59,7 @@ namespace IceInternal PropertyDict added, changed, removed; for (p = props.begin(); p != props.end(); ++p) { - PropertyDict::iterator q = old.find(p->first); + auto q = old.find(p->first); if (q == old.end()) { if (!p->second.empty()) diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 492cb180095..9baf17bd6e2 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -702,7 +702,7 @@ IceInternal::FixedReference::operator==(const Reference& r) const noexcept { return true; } - const FixedReference* rhs = dynamic_cast(&r); + const auto* rhs = dynamic_cast(&r); if (!rhs || !Reference::operator==(r)) { return false; @@ -726,7 +726,7 @@ IceInternal::FixedReference::operator<(const Reference& r) const noexcept return false; } - const FixedReference* rhs = dynamic_cast(&r); + const auto* rhs = dynamic_cast(&r); if (!rhs) { assert(dynamic_cast(&r)); @@ -879,9 +879,9 @@ IceInternal::RoutableReference::changeCompress(bool newCompress) const if (r.get() != const_cast(this) && !_endpoints.empty()) { vector newEndpoints; - for (vector::const_iterator p = _endpoints.begin(); p != _endpoints.end(); ++p) + for (const auto& endpoint : _endpoints) { - newEndpoints.push_back((*p)->compress(newCompress)); + newEndpoints.push_back(endpoint->compress(newCompress)); } dynamic_pointer_cast(r)->_endpoints = newEndpoints; } @@ -973,9 +973,9 @@ IceInternal::RoutableReference::changeConnectionId(string id) const if (!_endpoints.empty()) // Also override the connection id on the endpoints. { vector newEndpoints; - for (vector::const_iterator p = _endpoints.begin(); p != _endpoints.end(); ++p) + for (const auto& endpoint : _endpoints) { - newEndpoints.push_back((*p)->connectionId(id)); + newEndpoints.push_back(endpoint->connectionId(id)); } r->_endpoints = newEndpoints; } @@ -1017,15 +1017,15 @@ IceInternal::RoutableReference::streamWrite(OutputStream* s) const { Reference::streamWrite(s); - int32_t sz = static_cast(_endpoints.size()); + auto sz = static_cast(_endpoints.size()); s->writeSize(sz); if (sz) { assert(_adapterId.empty()); - for (vector::const_iterator p = _endpoints.begin(); p != _endpoints.end(); ++p) + for (const auto& endpoint : _endpoints) { - s->write((*p)->type()); - (*p)->streamWrite(s); + s->write(endpoint->type()); + endpoint->streamWrite(s); } } else @@ -1048,9 +1048,9 @@ IceInternal::RoutableReference::toString() const if (!_endpoints.empty()) { - for (vector::const_iterator p = _endpoints.begin(); p != _endpoints.end(); ++p) + for (const auto& endpoint : _endpoints) { - string endp = (*p)->toString(); + string endp = endpoint->toString(); if (!endp.empty()) { result.append(":"); @@ -1103,18 +1103,18 @@ IceInternal::RoutableReference::toProperty(string prefix) const if (_routerInfo) { PropertyDict routerProperties = _routerInfo->getRouter()->_getReference()->toProperty(prefix + ".Router"); - for (PropertyDict::const_iterator p = routerProperties.begin(); p != routerProperties.end(); ++p) + for (const auto& routerProp : routerProperties) { - properties[p->first] = p->second; + properties[routerProp.first] = routerProp.second; } } if (_locatorInfo) { PropertyDict locatorProperties = _locatorInfo->getLocator()->_getReference()->toProperty(prefix + ".Locator"); - for (PropertyDict::const_iterator p = locatorProperties.begin(); p != locatorProperties.end(); ++p) + for (const auto& locatorProp : locatorProperties) { - properties[p->first] = p->second; + properties[locatorProp.first] = locatorProp.second; } } @@ -1143,7 +1143,7 @@ IceInternal::RoutableReference::operator==(const Reference& r) const noexcept return true; } - const RoutableReference* rhs = dynamic_cast(&r); + const auto* rhs = dynamic_cast(&r); if (!rhs || !Reference::operator==(r)) { return false; @@ -1217,7 +1217,7 @@ IceInternal::RoutableReference::operator<(const Reference& r) const noexcept return false; } - const RoutableReference* rhs = dynamic_cast(&r); + const auto* rhs = dynamic_cast(&r); if (!rhs) { assert(dynamic_cast(&r)); @@ -1585,13 +1585,13 @@ IceInternal::RoutableReference::createConnectionAsync( void IceInternal::RoutableReference::applyOverrides(vector& endpoints) const { - for (vector::iterator p = endpoints.begin(); p != endpoints.end(); ++p) + for (auto& endpoint : endpoints) { - *p = (*p)->connectionId(_connectionId); + endpoint = endpoint->connectionId(_connectionId); optional compress = getCompress(); if (compress.has_value()) { - *p = (*p)->compress(*compress); + endpoint = endpoint->compress(*compress); } } } diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index a4fe6e4272d..7e5e90485d5 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -489,9 +489,9 @@ IceInternal::ReferenceFactory::create(string_view str, const string& propertyPre { Warning out(_instance->initializationData().logger); out << "Proxy contains unknown endpoints:"; - for (unsigned int idx = 0; idx < unknownEndpoints.size(); ++idx) + for (const auto& unknownEndpoint : unknownEndpoints) { - out << " '" << unknownEndpoints[idx] << "'"; + out << " '" << unknownEndpoint << "'"; } } @@ -592,7 +592,7 @@ IceInternal::ReferenceFactory::create(Identity ident, InputStream* s) uint8_t modeAsByte; s->read(modeAsByte); - Reference::Mode mode = static_cast(modeAsByte); + auto mode = static_cast(modeAsByte); if (mode < 0 || mode > Reference::ModeLast) { throw MarshalException{__FILE__, __LINE__, "received proxy with invalid mode " + to_string(mode)}; @@ -812,9 +812,9 @@ IceInternal::ReferenceFactory::create( property = propertyPrefix + ".Context."; PropertyDict contexts = properties->getPropertiesForPrefix(property); - for (PropertyDict::const_iterator p = contexts.begin(); p != contexts.end(); ++p) + for (const auto& context : contexts) { - ctx.insert(make_pair(p->first.substr(property.length()), p->second)); + ctx.insert(make_pair(context.first.substr(property.length()), context.second)); } } diff --git a/cpp/src/Ice/RetryQueue.cpp b/cpp/src/Ice/RetryQueue.cpp index 3721f1ac0a8..652203e0afb 100644 --- a/cpp/src/Ice/RetryQueue.cpp +++ b/cpp/src/Ice/RetryQueue.cpp @@ -102,7 +102,7 @@ IceInternal::RetryQueue::destroy() unique_lock lock(_mutex); assert(_instance); - set::iterator p = _requests.begin(); + auto p = _requests.begin(); while (p != _requests.end()) { if (_instance->timer()->cancel(*p)) diff --git a/cpp/src/Ice/RouterInfo.cpp b/cpp/src/Ice/RouterInfo.cpp index 57f251bd617..a4d929cb2b3 100644 --- a/cpp/src/Ice/RouterInfo.cpp +++ b/cpp/src/Ice/RouterInfo.cpp @@ -33,7 +33,7 @@ IceInternal::RouterManager::get(const RouterPrx& rtr) lock_guard lock(_mutex); - RouterInfoTable::iterator p = _table.end(); + auto p = _table.end(); if (_tableHint != _table.end()) { @@ -67,7 +67,7 @@ IceInternal::RouterManager::erase(const RouterPrx& router) lock_guard lock(_mutex); - RouterInfoTable::iterator p = _table.end(); + auto p = _table.end(); if (_tableHint != _table.end() && _tableHint->first == router) { p = _tableHint; @@ -186,7 +186,7 @@ IceInternal::RouterInfo::addProxyAsync( } Ice::ObjectProxySeq proxies; - proxies.push_back(ObjectPrx::_fromReference(reference)); + proxies.emplace_back(ObjectPrx::_fromReference(reference)); RouterInfoPtr self = shared_from_this(); _router->addProxiesAsync( @@ -242,7 +242,7 @@ IceInternal::RouterInfo::addAndEvictProxies(const Identity& identity, const Ice: // Check if the proxy hasn't already been evicted by a concurrent addProxies call. // If it's the case, don't add it to our local map. // - multiset::iterator p = _evictedIdentities.find(identity); + auto p = _evictedIdentities.find(identity); if (p != _evictedIdentities.end()) { _evictedIdentities.erase(p); @@ -259,16 +259,16 @@ IceInternal::RouterInfo::addAndEvictProxies(const Identity& identity, const Ice: // // We also must remove whatever proxies the router evicted. // - for (Ice::ObjectProxySeq::const_iterator q = evictedProxies.begin(); q != evictedProxies.end(); ++q) + for (const auto& evictedProxy : evictedProxies) { - if (_identities.erase((*q)->ice_getIdentity()) == 0) + if (_identities.erase(evictedProxy->ice_getIdentity()) == 0) { // // It's possible for the proxy to not have been // added yet in the local map if two threads // concurrently call addProxies. // - _evictedIdentities.insert((*q)->ice_getIdentity()); + _evictedIdentities.insert(evictedProxy->ice_getIdentity()); } } } diff --git a/cpp/src/Ice/SSL/DistinguishedName.cpp b/cpp/src/Ice/SSL/DistinguishedName.cpp index 9dfb1c3982b..02bc9c8e7b2 100644 --- a/cpp/src/Ice/SSL/DistinguishedName.cpp +++ b/cpp/src/Ice/SSL/DistinguishedName.cpp @@ -31,15 +31,15 @@ namespace Ice::SSL bool DistinguishedName::match(const DistinguishedName& other) const { - for (list>::const_iterator p = other._unescaped.begin(); p != other._unescaped.end(); ++p) + for (const auto& p : other._unescaped) { bool found = false; - for (list>::const_iterator q = _unescaped.begin(); q != _unescaped.end(); ++q) + for (const auto& q : _unescaped) { - if (p->first == q->first) + if (p.first == q.first) { found = true; - if (p->second != q->second) + if (p.second != q.second) { return false; } @@ -68,14 +68,14 @@ DistinguishedName::toString() const { ostringstream os; bool first = true; - for (list>::const_iterator p = _rdns.begin(); p != _rdns.end(); ++p) + for (const auto& rdn : _rdns) { if (!first) { os << ","; } first = false; - os << p->first << "=" << p->second; + os << rdn.first << "=" << rdn.second; } return os.str(); } @@ -83,9 +83,8 @@ DistinguishedName::toString() const void DistinguishedName::unescape() { - for (list>::const_iterator q = _rdns.begin(); q != _rdns.end(); ++q) + for (auto rdn : _rdns) { - pair rdn = *q; rdn.second = RFC2253::unescape(rdn.second); _unescaped.push_back(rdn); } diff --git a/cpp/src/Ice/SSL/RFC2253.cpp b/cpp/src/Ice/SSL/RFC2253.cpp index 983a0b6092a..266e5e30a64 100644 --- a/cpp/src/Ice/SSL/RFC2253.cpp +++ b/cpp/src/Ice/SSL/RFC2253.cpp @@ -18,8 +18,8 @@ namespace // See RFC 2253 and RFC 1779. // - const string special = ",=+<>#;"; // NOLINT:cert-err58-cpp - const string hexvalid = "0123456789abcdefABCDEF"; // NOLINT:cert-err58-cpp + const string special = ",=+<>#;"; // NOLINT(cert-err58-cpp) + const string hexvalid = "0123456789abcdefABCDEF"; // NOLINT(cert-err58-cpp) } static char unescapeHex(const string&, size_t); diff --git a/cpp/src/Ice/SSL/SSLConnectorI.cpp b/cpp/src/Ice/SSL/SSLConnectorI.cpp index 76e0957fd1f..efb58e22f87 100644 --- a/cpp/src/Ice/SSL/SSLConnectorI.cpp +++ b/cpp/src/Ice/SSL/SSLConnectorI.cpp @@ -52,7 +52,7 @@ Ice::SSL::ConnectorI::toString() const bool Ice::SSL::ConnectorI::operator==(const IceInternal::Connector& r) const { - const ConnectorI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -69,7 +69,7 @@ Ice::SSL::ConnectorI::operator==(const IceInternal::Connector& r) const bool Ice::SSL::ConnectorI::operator<(const IceInternal::Connector& r) const { - const ConnectorI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return type() < r.type(); diff --git a/cpp/src/Ice/SSL/SSLEndpointI.cpp b/cpp/src/Ice/SSL/SSLEndpointI.cpp index 5d3ae9fbaf1..4549f7afd85 100644 --- a/cpp/src/Ice/SSL/SSLEndpointI.cpp +++ b/cpp/src/Ice/SSL/SSLEndpointI.cpp @@ -189,9 +189,9 @@ Ice::SSL::EndpointI::connectorsAsync( selType, [response, this, host](vector connectors) { - for (vector::iterator it = connectors.begin(); it != connectors.end(); ++it) + for (auto& connector : connectors) { - *it = make_shared(_instance, *it, host); + connector = make_shared(_instance, connector, host); } response(std::move(connectors)); }, @@ -276,7 +276,7 @@ Ice::SSL::EndpointI::options() const bool Ice::SSL::EndpointI::operator==(const Ice::Endpoint& r) const { - const EndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -298,10 +298,10 @@ Ice::SSL::EndpointI::operator==(const Ice::Endpoint& r) const bool Ice::SSL::EndpointI::operator<(const Ice::Endpoint& r) const { - const EndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { - const IceInternal::EndpointI* e = dynamic_cast(&r); + const auto* e = dynamic_cast(&r); if (!e) { return false; diff --git a/cpp/src/Ice/SSL/SSLUtil.cpp b/cpp/src/Ice/SSL/SSLUtil.cpp index 75f2b0ed269..6e2eb70ab05 100644 --- a/cpp/src/Ice/SSL/SSLUtil.cpp +++ b/cpp/src/Ice/SSL/SSLUtil.cpp @@ -53,13 +53,13 @@ Ice::SSL::parseBytes(const string& arg, vector& buffer) // Remove any separator characters. ostringstream s; - for (string::const_iterator i = v.begin(); i != v.end(); ++i) + for (char i : v) { - if (*i == ' ' || *i == ':') + if (i == ' ' || i == ':') { continue; } - s << *i; + s << i; } v = s.str(); @@ -216,7 +216,6 @@ namespace {"1.2.840.113549.1.9.2", "unstructuredName"}, {"1.2.840.113549.1.9.1", "emailAddress"}, {"0.9.2342.19200300.100.1.25", "DC"}}; - const int certificateOIDSSize = sizeof(certificateOIDS) / sizeof(pair); } #if defined(ICE_USE_SCHANNEL) @@ -244,12 +243,10 @@ namespace } string s(&buffer[0]); - for (int i = 0; i < certificateOIDSSize; ++i) + for (const auto& certificateOID : certificateOIDS) { - const pair* certificateOID = &certificateOIDS[i]; - assert(certificateOID); - const string name = string(certificateOID->first) + "="; - const string alias = string(certificateOID->second) + "="; + const string name = string(certificateOID.first) + "="; + const string alias = string(certificateOID.second) + "="; size_t pos = 0; while ((pos = s.find(name, pos)) != string::npos) { @@ -441,13 +438,11 @@ Ice::SSL::decodeCertificate(const string& data) string Ice::SSL::certificateOIDAlias(const string& name) { - for (int i = 0; i < certificateOIDSSize; ++i) + for (const auto& certificateOID : certificateOIDS) { - const pair* certificateOID = &certificateOIDS[i]; - assert(certificateOID); - if (name == certificateOID->first) + if (name == certificateOID.first) { - return certificateOID->second; + return certificateOID.second; } } return name; diff --git a/cpp/src/Ice/SSL/SchannelEngine.cpp b/cpp/src/Ice/SSL/SchannelEngine.cpp index 4b39219354d..561edf4ed6f 100644 --- a/cpp/src/Ice/SSL/SchannelEngine.cpp +++ b/cpp/src/Ice/SSL/SchannelEngine.cpp @@ -1246,7 +1246,7 @@ Schannel::SSLEngine::createClientAuthenticationOptions(const string& host) const .clientCredentialsSelectionCallback = [this](const string&) { - for (auto& cert : _allCerts) + for (const auto& cert : _allCerts) { CertDuplicateCertificateContext(cert); } @@ -1291,7 +1291,7 @@ Schannel::SSLEngine::createServerAuthenticationOptions() const [this](const string&) { { - for (auto& cert : _allCerts) + for (const auto& cert : _allCerts) { CertDuplicateCertificateContext(cert); } diff --git a/cpp/src/Ice/SSL/SecureTransportTransceiverI.cpp b/cpp/src/Ice/SSL/SecureTransportTransceiverI.cpp index b497689ae2e..c05c7a24a63 100644 --- a/cpp/src/Ice/SSL/SecureTransportTransceiverI.cpp +++ b/cpp/src/Ice/SSL/SecureTransportTransceiverI.cpp @@ -49,7 +49,7 @@ namespace // OSStatus socketWrite(SSLConnectionRef connection, const void* data, size_t* length) { - const TransceiverI* transceiver = static_cast(connection); + const auto* transceiver = static_cast(connection); assert(transceiver); return transceiver->writeRaw(reinterpret_cast(data), length); } @@ -59,7 +59,7 @@ namespace // OSStatus socketRead(SSLConnectionRef connection, void* data, size_t* length) { - const TransceiverI* transceiver = static_cast(connection); + const auto* transceiver = static_cast(connection); assert(transceiver); return transceiver->readRaw(reinterpret_cast(data), length); } diff --git a/cpp/src/Ice/SSL/SecureTransportUtil.cpp b/cpp/src/Ice/SSL/SecureTransportUtil.cpp index cd5299d2a8c..21d52dd85a6 100644 --- a/cpp/src/Ice/SSL/SecureTransportUtil.cpp +++ b/cpp/src/Ice/SSL/SecureTransportUtil.cpp @@ -72,9 +72,9 @@ namespace string escapeX509Name(const string& name) { ostringstream os; - for (string::const_iterator i = name.begin(); i != name.end(); ++i) + for (char i : name) { - switch (*i) + switch (i) { case ',': case '=': @@ -91,7 +91,7 @@ namespace break; } } - os << *i; + os << i; } return os.str(); } @@ -121,16 +121,16 @@ namespace UniqueRef property(getCertificateProperty(cert, key)); if (property) { - CFArrayRef dn = static_cast(CFDictionaryGetValue(property.get(), kSecPropertyKeyValue)); + auto dn = static_cast(CFDictionaryGetValue(property.get(), kSecPropertyKeyValue)); CFIndex size = CFArrayGetCount(dn); for (CFIndex i = 0; i < size; ++i) { - CFDictionaryRef dict = static_cast(CFArrayGetValueAtIndex(dn, i)); - rdnPairs.push_front(make_pair( + auto dict = static_cast(CFArrayGetValueAtIndex(dn, i)); + rdnPairs.emplace_front( certificateOIDAlias( fromCFString((static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyLabel))))), escapeX509Name( - fromCFString(static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyValue)))))); + fromCFString(static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyValue))))); } } return DistinguishedName(rdnPairs); @@ -144,39 +144,37 @@ namespace vector> pairs; if (property) { - CFArrayRef names = static_cast(CFDictionaryGetValue(property.get(), kSecPropertyKeyValue)); + auto names = static_cast(CFDictionaryGetValue(property.get(), kSecPropertyKeyValue)); CFIndex size = CFArrayGetCount(names); for (CFIndex i = 0; i < size; ++i) { - CFDictionaryRef dict = static_cast(CFArrayGetValueAtIndex(names, i)); + auto dict = static_cast(CFArrayGetValueAtIndex(names, i)); int type = certificateAlternativeNameType( fromCFString(static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyLabel)))); if (type != -1) { - CFStringRef v = static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyValue)); - CFStringRef t = static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyType)); + auto v = static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyValue)); + auto t = static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyType)); if (CFEqual(t, kSecPropertyTypeString) || CFEqual(t, kSecPropertyTypeTitle)) { - pairs.push_back(make_pair(type, fromCFString(v))); + pairs.emplace_back(type, fromCFString(v)); } else if (CFEqual(t, kSecPropertyTypeURL)) { - pairs.push_back(make_pair(type, fromCFString(CFURLGetString((CFURLRef)v)))); + pairs.emplace_back(type, fromCFString(CFURLGetString((CFURLRef)v))); } else if (CFEqual(t, kSecPropertyTypeSection)) { - CFArrayRef section = (CFArrayRef)v; + auto section = (CFArrayRef)v; ostringstream os; for (CFIndex j = 0, count = CFArrayGetCount(section); j < count;) { - CFDictionaryRef d = (CFDictionaryRef)CFArrayGetValueAtIndex(section, j); + auto d = (CFDictionaryRef)CFArrayGetValueAtIndex(section, j); - CFStringRef sectionLabel = - static_cast(CFDictionaryGetValue(d, kSecPropertyKeyLabel)); - CFStringRef sectionValue = - static_cast(CFDictionaryGetValue(d, kSecPropertyKeyValue)); + auto sectionLabel = static_cast(CFDictionaryGetValue(d, kSecPropertyKeyLabel)); + auto sectionValue = static_cast(CFDictionaryGetValue(d, kSecPropertyKeyValue)); os << certificateOIDAlias(fromCFString(sectionLabel)) << "=" << fromCFString(sectionValue); if (++j < count) @@ -184,7 +182,7 @@ namespace os << ","; } } - pairs.push_back(make_pair(type, os.str())); + pairs.emplace_back(type, os.str()); } } } @@ -252,12 +250,11 @@ namespace UniqueRef property(getCertificateProperty(cert, kSecOIDBasicConstraints)); if (property) { - CFArrayRef propertyValues = - static_cast(CFDictionaryGetValue(property.get(), kSecPropertyKeyValue)); + auto propertyValues = static_cast(CFDictionaryGetValue(property.get(), kSecPropertyKeyValue)); for (CFIndex i = 0, size = CFArrayGetCount(propertyValues); i < size; ++i) { - CFDictionaryRef dict = static_cast(CFArrayGetValueAtIndex(propertyValues, i)); - CFStringRef label = static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyLabel)); + auto dict = static_cast(CFArrayGetValueAtIndex(propertyValues, i)); + auto label = static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyLabel)); if (CFEqual(label, CFSTR("Certificate Authority"))) { return CFEqual( @@ -427,11 +424,10 @@ namespace UniqueRef subjectKeyProperty(getCertificateProperty(cert, kSecOIDSubjectKeyIdentifier)); if (subjectKeyProperty) { - CFArrayRef values = - static_cast(CFDictionaryGetValue(subjectKeyProperty.get(), kSecPropertyKeyValue)); + auto values = static_cast(CFDictionaryGetValue(subjectKeyProperty.get(), kSecPropertyKeyValue)); for (int i = 0; i < CFArrayGetCount(values); ++i) { - CFDictionaryRef dict = static_cast(CFArrayGetValueAtIndex(values, i)); + auto dict = static_cast(CFArrayGetValueAtIndex(values, i)); if (CFEqual(CFDictionaryGetValue(dict, kSecPropertyKeyLabel), CFSTR("Key Identifier"))) { hash.retain(static_cast(CFDictionaryGetValue(dict, kSecPropertyKeyValue))); @@ -487,8 +483,7 @@ namespace UniqueRef key; for (CFIndex i = 0; i < count; ++i) { - SecKeychainItemRef itemRef = - static_cast(const_cast(CFArrayGetValueAtIndex(items.get(), 0))); + auto itemRef = static_cast(const_cast(CFArrayGetValueAtIndex(items.get(), 0))); if (SecKeyGetTypeID() == CFGetTypeID(itemRef)) { key.retain(reinterpret_cast(itemRef)); @@ -714,8 +709,7 @@ Ice::SSL::SecureTransport::loadCertificateChain( { // Load the certificate, don't load into the keychain as it might already have been imported. UniqueRef items(loadKeychainItems(file, kSecItemTypeCertificate, nullptr, password)); - SecCertificateRef cert = - static_cast(const_cast(CFArrayGetValueAtIndex(items.get(), 0))); + auto cert = static_cast(const_cast(CFArrayGetValueAtIndex(items.get(), 0))); if (SecCertificateGetTypeID() != CFGetTypeID(cert)) { ostringstream os; @@ -762,8 +756,7 @@ Ice::SSL::SecureTransport::loadCACertificates(const string& file) CFIndex count = CFArrayGetCount(items.get()); for (CFIndex i = 0; i < count; ++i) { - SecCertificateRef cert = - static_cast(const_cast(CFArrayGetValueAtIndex(items.get(), i))); + auto cert = static_cast(const_cast(CFArrayGetValueAtIndex(items.get(), i))); assert(SecCertificateGetTypeID() == CFGetTypeID(cert)); if (isCA(cert)) { diff --git a/cpp/src/Ice/SSL/TrustManager.cpp b/cpp/src/Ice/SSL/TrustManager.cpp index a3ea484db63..ff108b08d21 100644 --- a/cpp/src/Ice/SSL/TrustManager.cpp +++ b/cpp/src/Ice/SSL/TrustManager.cpp @@ -28,12 +28,12 @@ TrustManager::TrustManager(IceInternal::InstancePtr instance) : _instance(std::m key = "IceSSL.TrustOnly.Server"; parse(properties->getProperty(key), _rejectAllServer, _acceptAllServer); Ice::PropertyDict dict = properties->getPropertiesForPrefix("IceSSL.TrustOnly.Server."); - for (Ice::PropertyDict::const_iterator p = dict.begin(); p != dict.end(); ++p) + for (const auto& p : dict) { - string name = p->first.substr(string("IceSSL.TrustOnly.Server.").size()); - key = p->first; + string name = p.first.substr(string("IceSSL.TrustOnly.Server.").size()); + key = p.first; list reject, accept; - parse(p->second, reject, accept); + parse(p.second, reject, accept); if (!reject.empty()) { _rejectServer[name] = reject; @@ -70,7 +70,7 @@ TrustManager::verify(const ConnectionInfoPtr& info) const } if (info->adapterName.size() > 0) { - map>::const_iterator p = _rejectServer.find(info->adapterName); + auto p = _rejectServer.find(info->adapterName); if (p != _rejectServer.end()) { reject.push_back(p->second); @@ -97,7 +97,7 @@ TrustManager::verify(const ConnectionInfoPtr& info) const } if (info->adapterName.size() > 0) { - map>::const_iterator p = _acceptServer.find(info->adapterName); + auto p = _acceptServer.find(info->adapterName); if (p != _acceptServer.end()) { accept.push_back(p->second); @@ -139,44 +139,44 @@ TrustManager::verify(const ConnectionInfoPtr& info) const } // Fail if we match anything in the reject set. - for (list>::const_iterator p = reject.begin(); p != reject.end(); ++p) + for (const auto& p : reject) { if (_traceLevel > 1) { Ice::Trace trace(_instance->initializationData().logger, "Security"); trace << "trust manager rejecting PDNs:\n"; - for (list::const_iterator r = p->begin(); r != p->end(); ++r) + for (auto r = p.begin(); r != p.end(); ++r) { - if (r != p->begin()) + if (r != p.begin()) { trace << ';'; } trace << string(*r); } } - if (match(*p, subject)) + if (match(p, subject)) { return false; } } // Succeed if we match anything in the accept set. - for (list>::const_iterator p = accept.begin(); p != accept.end(); ++p) + for (const auto& p : accept) { if (_traceLevel > 1) { Ice::Trace trace(_instance->initializationData().logger, "Security"); trace << "trust manager accepting PDNs:\n"; - for (list::const_iterator r = p->begin(); r != p->end(); ++r) + for (auto r = p.begin(); r != p.end(); ++r) { - if (r != p->begin()) + if (r != p.begin()) { trace << ';'; } trace << string(*r); } } - if (match(*p, subject)) + if (match(p, subject)) { return true; } @@ -192,9 +192,9 @@ TrustManager::verify(const ConnectionInfoPtr& info) const bool TrustManager::match(const list& matchSet, const DistinguishedName& subject) const { - for (list::const_iterator r = matchSet.begin(); r != matchSet.end(); ++r) + for (const auto& r : matchSet) { - if (subject.match(*r)) + if (subject.match(r)) { return true; } @@ -209,15 +209,15 @@ TrustManager::parse(const string& value, list& reject, listnegate) + if (dn.negate) { - reject.push_back(DistinguishedName(p->rdn)); + reject.emplace_back(dn.rdn); } else { - accept.push_back(DistinguishedName(p->rdn)); + accept.emplace_back(dn.rdn); } } } diff --git a/cpp/src/Ice/Selector.cpp b/cpp/src/Ice/Selector.cpp index b29faa172d5..3bcc7c40aac 100644 --- a/cpp/src/Ice/Selector.cpp +++ b/cpp/src/Ice/Selector.cpp @@ -570,7 +570,7 @@ Selector::finishSelect(vector>& handlers) continue; // Interrupted } - map::iterator q = _readyHandlers.find(p.first->shared_from_this()); + auto q = _readyHandlers.find(p.first->shared_from_this()); if (q != _readyHandlers.end()) // Handler will be added by the loop below { @@ -582,22 +582,22 @@ Selector::finishSelect(vector>& handlers) } } - for (map::iterator q = _readyHandlers.begin(); q != _readyHandlers.end(); ++q) + for (auto& readyHandler : _readyHandlers) { pair p; - p.first = q->first.get(); + p.first = readyHandler.first.get(); p.second = static_cast(p.first->_ready & ~p.first->_disabled & p.first->_registered); - p.second = static_cast(p.second | q->second); + p.second = static_cast(p.second | readyHandler.second); if (p.second) { handlers.push_back(p); } // - // Reset the operation, it's only used by this method to temporarly store the socket status + // Reset the operation, it's only used by this method to temporarily store the socket status // return by the select operation above. // - q->second = SocketOperationNone; + readyHandler.second = SocketOperationNone; } } @@ -681,7 +681,7 @@ Selector::checkReady(EventHandler* handler) } else { - map::iterator p = _readyHandlers.find(handler->shared_from_this()); + auto p = _readyHandlers.find(handler->shared_from_this()); if (p != _readyHandlers.end()) { _readyHandlers.erase(p); diff --git a/cpp/src/Ice/ServantManager.cpp b/cpp/src/Ice/ServantManager.cpp index f0855741e83..c9ae2303423 100644 --- a/cpp/src/Ice/ServantManager.cpp +++ b/cpp/src/Ice/ServantManager.cpp @@ -21,7 +21,7 @@ IceInternal::ServantManager::addServant(ObjectPtr object, Identity ident, string assert(_instance); // Must not be called after destruction. - ServantMapMap::iterator p = _servantMapMapHint; + auto p = _servantMapMapHint; if (p == _servantMapMap.end() || p->first != ident) { @@ -59,7 +59,7 @@ IceInternal::ServantManager::addDefaultServant(ObjectPtr object, string category assert(_instance); // Must not be called after destruction. - DefaultServantMap::iterator p = _defaultServantMap.find(category); + auto p = _defaultServantMap.find(category); if (p != _defaultServantMap.end()) { throw AlreadyRegisteredException(__FILE__, __LINE__, "default servant", category); @@ -79,7 +79,7 @@ IceInternal::ServantManager::removeServant(const Identity& ident, const string_v assert(_instance); // Must not be called after destruction. - ServantMapMap::iterator p = _servantMapMapHint; + auto p = _servantMapMapHint; FacetMap::iterator q; if (p == _servantMapMap.end() || p->first != ident) @@ -128,7 +128,7 @@ IceInternal::ServantManager::removeDefaultServant(const string_view category) assert(_instance); // Must not be called after destruction. - DefaultServantMap::iterator p = _defaultServantMap.find(category); + auto p = _defaultServantMap.find(category); if (p == _defaultServantMap.end()) { throw NotRegisteredException(__FILE__, __LINE__, "default servant", string{category}); @@ -147,7 +147,7 @@ IceInternal::ServantManager::removeAllFacets(const Identity& ident) assert(_instance); // Must not be called after destruction. - ServantMapMap::iterator p = _servantMapMapHint; + auto p = _servantMapMapHint; if (p == _servantMapMap.end() || p->first != ident) { @@ -191,10 +191,10 @@ IceInternal::ServantManager::findServant(const Identity& ident, const string_vie // // assert(_instance); // Must not be called after destruction. - ServantMapMap::iterator p = _servantMapMapHint; + auto p = _servantMapMapHint; FacetMap::iterator q; - ServantMapMap& servantMapMap = const_cast(_servantMapMap); + auto& servantMapMap = const_cast(_servantMapMap); if (p == servantMapMap.end() || p->first != ident) { @@ -203,7 +203,7 @@ IceInternal::ServantManager::findServant(const Identity& ident, const string_vie if (p == servantMapMap.end() || (q = p->second.find(facet)) == p->second.end()) { - DefaultServantMap::const_iterator d = _defaultServantMap.find(ident.category); + auto d = _defaultServantMap.find(ident.category); if (d == _defaultServantMap.end()) { d = _defaultServantMap.find(""); @@ -233,7 +233,7 @@ IceInternal::ServantManager::findDefaultServant(const string_view category) cons { lock_guard lock(_mutex); - DefaultServantMap::const_iterator p = _defaultServantMap.find(category); + auto p = _defaultServantMap.find(category); if (p == _defaultServantMap.end()) { return nullptr; @@ -251,9 +251,9 @@ IceInternal::ServantManager::findAllFacets(const Identity& ident) const assert(_instance); // Must not be called after destruction. - ServantMapMap::iterator p = _servantMapMapHint; + auto p = _servantMapMapHint; - ServantMapMap& servantMapMap = const_cast(_servantMapMap); + auto& servantMapMap = const_cast(_servantMapMap); if (p == servantMapMap.end() || p->first != ident) { @@ -284,8 +284,8 @@ IceInternal::ServantManager::hasServant(const Identity& ident) const // // assert(_instance); // Must not be called after destruction. - ServantMapMap::iterator p = _servantMapMapHint; - ServantMapMap& servantMapMap = const_cast(_servantMapMap); + auto p = _servantMapMapHint; + auto& servantMapMap = const_cast(_servantMapMap); if (p == servantMapMap.end() || p->first != ident) { @@ -435,18 +435,18 @@ IceInternal::ServantManager::destroy() _instance = nullptr; } - for (auto p = locatorMap.begin(); p != locatorMap.end(); ++p) + for (const auto& p : locatorMap) { try { - p->second->deactivate(p->first); + p.second->deactivate(p.first); } catch (const Exception& ex) { Error out(logger); out << "exception during locator deactivation:\n" << "object adapter: '" << _adapterName << "'\n" - << "locator category: '" << p->first << "'\n" + << "locator category: '" << p.first << "'\n" << ex; } catch (...) @@ -454,7 +454,7 @@ IceInternal::ServantManager::destroy() Error out(logger); out << "unknown exception during locator deactivation:\n" << "object adapter: '" << _adapterName << "'\n" - << "locator category: '" << p->first << "'"; + << "locator category: '" << p.first << "'"; } } diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp index 518a694c135..53b575d73cc 100644 --- a/cpp/src/Ice/Service.cpp +++ b/cpp/src/Ice/Service.cpp @@ -1562,7 +1562,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa // Ignore SIGHUP so that the grandchild process is not sent SIGHUP when this // process exits. // - signal(SIGHUP, SIG_IGN); // NOLINT:cert-err33-c + signal(SIGHUP, SIG_IGN); // NOLINT(cert-err33-c) // // Fork again to eliminate the possibility of acquiring a controlling terminal. @@ -1641,16 +1641,16 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa string stdOut = properties->getIceProperty("Ice.StdOut"); string stdErr = properties->getIceProperty("Ice.StdErr"); - for (vector::const_iterator p = fdsToClose.begin(); p != fdsToClose.end(); ++p) + for (int& p : fdsToClose) { // // NOTE: Do not close stdout if Ice.StdOut is defined. Likewise for Ice.StdErr. // - if ((*p == 1 && !stdOut.empty()) || (*p == 2 && !stdErr.empty())) + if ((p == 1 && !stdOut.empty()) || (p == 2 && !stdErr.empty())) { continue; } - close(*p); + close(p); } // diff --git a/cpp/src/Ice/SlicedData.cpp b/cpp/src/Ice/SlicedData.cpp index c98dfe2fd3f..d3c333bbdae 100644 --- a/cpp/src/Ice/SlicedData.cpp +++ b/cpp/src/Ice/SlicedData.cpp @@ -16,11 +16,11 @@ Ice::SlicedData::clear() { SliceInfoSeq tmp; tmp.swap(const_cast(slices)); - for (SliceInfoSeq::const_iterator p = tmp.begin(); p != tmp.end(); ++p) + for (const auto& p : tmp) { - for (vector>::const_iterator q = (*p)->instances.begin(); q != (*p)->instances.end(); ++q) + for (const auto& instance : p->instances) { - Ice::SlicedDataPtr slicedData = (*q)->ice_getSlicedData(); + Ice::SlicedDataPtr slicedData = instance->ice_getSlicedData(); if (slicedData) { slicedData->clear(); diff --git a/cpp/src/Ice/StringConverter.cpp b/cpp/src/Ice/StringConverter.cpp index 1c29e88c58c..a5533fe9a9d 100644 --- a/cpp/src/Ice/StringConverter.cpp +++ b/cpp/src/Ice/StringConverter.cpp @@ -134,7 +134,7 @@ namespace void fromUTF8(const byte* sourceStart, const byte* sourceEnd, wstring& target) const final { - const size_t sourceSize = static_cast(sourceEnd - sourceStart); + const auto sourceSize = static_cast(sourceEnd - sourceStart); if (sourceSize == 0) { @@ -143,7 +143,7 @@ namespace else { target.resize(sourceSize); - wchar_t* targetStart = const_cast(target.data()); + auto* targetStart = const_cast(target.data()); wchar_t* targetEnd = targetStart + sourceSize; wchar_t* targetNext = targetStart; diff --git a/cpp/src/Ice/StringUtil.cpp b/cpp/src/Ice/StringUtil.cpp index 2786ac80b88..33c37f63a9c 100644 --- a/cpp/src/Ice/StringUtil.cpp +++ b/cpp/src/Ice/StringUtil.cpp @@ -58,7 +58,7 @@ namespace { unsigned int codePoint; - uint8_t b = static_cast(c); + auto b = static_cast(c); if ((b >> 5) == 0x06) { // 2 bytes @@ -112,9 +112,9 @@ namespace string IceInternal::escapeString(string_view s, string_view special, ToStringMode toStringMode) { - for (string::size_type i = 0; i < special.size(); ++i) + for (char i : special) { - if (static_cast(special[i]) < 32 || static_cast(special[i]) > 126) + if (static_cast(i) < 32 || static_cast(i) > 126) { throw invalid_argument("Special characters must be in ASCII range 32-126"); } @@ -210,7 +210,7 @@ IceInternal::escapeString(string_view s, string_view special, ToStringMode toStr } else { - unsigned char i = static_cast(c); + auto i = static_cast(c); if (i < 32 || i > 126) { @@ -274,7 +274,7 @@ namespace { char checkChar(const string& s, string::size_type pos) { - unsigned char c = static_cast(s[pos]); + auto c = static_cast(s[pos]); if (c < 32 || c == 127) { ostringstream ostr; @@ -570,9 +570,9 @@ IceInternal::unescapeString( assert(start <= end && end <= s.size()); - for (string::size_type i = 0; i < special.size(); ++i) + for (char i : special) { - if (static_cast(special[i]) < 32 || static_cast(special[i]) > 126) + if (static_cast(i) < 32 || static_cast(i) > 126) { throw invalid_argument("Special characters must be in ASCII range 32-126"); } diff --git a/cpp/src/Ice/TcpConnector.cpp b/cpp/src/Ice/TcpConnector.cpp index 593cbea792c..343a7bc12ce 100644 --- a/cpp/src/Ice/TcpConnector.cpp +++ b/cpp/src/Ice/TcpConnector.cpp @@ -42,7 +42,7 @@ IceInternal::TcpConnector::toString() const bool IceInternal::TcpConnector::operator==(const Connector& r) const { - const TcpConnector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -74,7 +74,7 @@ IceInternal::TcpConnector::operator==(const Connector& r) const bool IceInternal::TcpConnector::operator<(const Connector& r) const { - const TcpConnector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return type() < r.type(); diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp index 5f02482fd97..a50fa3357f4 100644 --- a/cpp/src/Ice/TcpEndpointI.cpp +++ b/cpp/src/Ice/TcpEndpointI.cpp @@ -213,7 +213,7 @@ IceInternal::TcpEndpointI::operator==(const Endpoint& r) const return false; } - const TcpEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -239,10 +239,10 @@ IceInternal::TcpEndpointI::operator==(const Endpoint& r) const bool IceInternal::TcpEndpointI::operator<(const Endpoint& r) const { - const TcpEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { - const EndpointI* e = dynamic_cast(&r); + const auto* e = dynamic_cast(&r); if (!e) { return false; diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index cc2453371ab..1cb60b06ca3 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -307,7 +307,7 @@ void IceInternal::ThreadPool::updateObservers() { lock_guard lock(_mutex); - for (auto& p : _threads) + for (const auto& p : _threads) { p->updateObserver(); } @@ -479,9 +479,9 @@ IceInternal::ThreadPool::joinWithAllThreads() // wouldn't be possible here anyway, because otherwise the other // threads would never terminate.) // - for (set::iterator p = _threads.begin(); p != _threads.end(); ++p) + for (const auto& thread : _threads) { - (*p)->join(); + thread->join(); } _selector.destroy(); } diff --git a/cpp/src/Ice/ThreadPool.h b/cpp/src/Ice/ThreadPool.h index 99b6c82d68c..6a2ad17a2f9 100644 --- a/cpp/src/Ice/ThreadPool.h +++ b/cpp/src/Ice/ThreadPool.h @@ -140,7 +140,7 @@ namespace IceInternal SocketOperation operation; - bool ioCompleted() const // NOLINT:modernize-use-nodiscard + bool ioCompleted() const // NOLINT(modernize-use-nodiscard) { return _threadPool->ioCompleted(const_cast(*this)); } diff --git a/cpp/src/Ice/TraceUtil.cpp b/cpp/src/Ice/TraceUtil.cpp index 258a3fa8b6c..3453930743a 100644 --- a/cpp/src/Ice/TraceUtil.cpp +++ b/cpp/src/Ice/TraceUtil.cpp @@ -419,7 +419,7 @@ IceInternal::traceSend( { if (tl->protocol >= 1) { - OutputStream& stream = const_cast(str); + auto& stream = const_cast(str); InputStream is{instance.get(), stream.getEncoding(), stream, false}; is.i = is.b.begin(); @@ -439,7 +439,7 @@ IceInternal::traceRecv( { if (tl->protocol >= 1) { - InputStream& stream = const_cast(str); + auto& stream = const_cast(str); InputStream::Container::iterator p = stream.i; stream.i = stream.b.begin(); @@ -461,7 +461,7 @@ IceInternal::trace( { if (tl->protocol >= 1) { - InputStream& stream = const_cast(str); + auto& stream = const_cast(str); InputStream::Container::iterator p = stream.i; stream.i = stream.b.begin(); diff --git a/cpp/src/Ice/UdpConnector.cpp b/cpp/src/Ice/UdpConnector.cpp index cf72a426399..542e918ce7e 100644 --- a/cpp/src/Ice/UdpConnector.cpp +++ b/cpp/src/Ice/UdpConnector.cpp @@ -33,7 +33,7 @@ IceInternal::UdpConnector::toString() const bool IceInternal::UdpConnector::operator==(const Connector& r) const { - const UdpConnector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -69,7 +69,7 @@ IceInternal::UdpConnector::operator==(const Connector& r) const bool IceInternal::UdpConnector::operator<(const Connector& r) const { - const UdpConnector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return type() < r.type(); diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp index 3dcbfe0eba5..7a7cd6bbc97 100644 --- a/cpp/src/Ice/UdpEndpointI.cpp +++ b/cpp/src/Ice/UdpEndpointI.cpp @@ -253,7 +253,7 @@ IceInternal::UdpEndpointI::operator==(const Endpoint& r) const return false; } - const UdpEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -285,10 +285,10 @@ IceInternal::UdpEndpointI::operator==(const Endpoint& r) const bool IceInternal::UdpEndpointI::operator<(const Endpoint& r) const { - const UdpEndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { - const EndpointI* e = dynamic_cast(&r); + const auto* e = dynamic_cast(&r); if (!e) { return false; diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index 363dd5fa819..61d1aa09b99 100644 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -155,7 +155,7 @@ IceInternal::UdpTransceiver::write(Buffer& buf) } else { - socklen_t len = static_cast(sizeof(sockaddr_storage)); + auto len = static_cast(sizeof(sockaddr_storage)); if (_peerAddr.saStorage.ss_family == AF_INET) { len = static_cast(sizeof(sockaddr_in)); @@ -238,7 +238,7 @@ IceInternal::UdpTransceiver::read(Buffer& buf) Address peerAddr; memset(&peerAddr.saStorage, 0, sizeof(sockaddr_storage)); - socklen_t len = static_cast(sizeof(sockaddr_storage)); + auto len = static_cast(sizeof(sockaddr_storage)); ret = recvfrom(_fd, reinterpret_cast(&buf.b[0]), packetSize, 0, &peerAddr.sa, &len); diff --git a/cpp/src/Ice/ValueFactoryManagerI.cpp b/cpp/src/Ice/ValueFactoryManagerI.cpp index 77e245fce0d..3a006c6684b 100644 --- a/cpp/src/Ice/ValueFactoryManagerI.cpp +++ b/cpp/src/Ice/ValueFactoryManagerI.cpp @@ -28,9 +28,9 @@ IceInternal::ValueFactoryManagerI::find(string_view id) const noexcept { lock_guard lock(_mutex); - FactoryFuncMap& factoryFuncMap = const_cast(_factoryFuncMap); + auto& factoryFuncMap = const_cast(_factoryFuncMap); - FactoryFuncMap::iterator p = factoryFuncMap.end(); + auto p = factoryFuncMap.end(); if (_factoryFuncMapHint != factoryFuncMap.end()) { if (_factoryFuncMapHint->first == id) diff --git a/cpp/src/Ice/WSConnector.cpp b/cpp/src/Ice/WSConnector.cpp index 16dbab11426..e2f74513905 100644 --- a/cpp/src/Ice/WSConnector.cpp +++ b/cpp/src/Ice/WSConnector.cpp @@ -32,7 +32,7 @@ IceInternal::WSConnector::toString() const bool IceInternal::WSConnector::operator==(const Connector& r) const { - const WSConnector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -54,7 +54,7 @@ IceInternal::WSConnector::operator==(const Connector& r) const bool IceInternal::WSConnector::operator<(const Connector& r) const { - const WSConnector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return type() < r.type(); diff --git a/cpp/src/Ice/WSEndpoint.cpp b/cpp/src/Ice/WSEndpoint.cpp index bb2c7dbbbcf..c5599fdba35 100644 --- a/cpp/src/Ice/WSEndpoint.cpp +++ b/cpp/src/Ice/WSEndpoint.cpp @@ -224,9 +224,9 @@ IceInternal::WSEndpoint::connectorsAsync( selType, [response, host, self](vector connectors) { - for (vector::iterator it = connectors.begin(); it != connectors.end(); it++) + for (auto& connector : connectors) { - *it = make_shared(self->_instance, *it, host, self->_resource); + connector = make_shared(self->_instance, connector, host, self->_resource); } response(std::move(connectors)); }, @@ -334,7 +334,7 @@ IceInternal::WSEndpoint::options() const bool IceInternal::WSEndpoint::operator==(const Endpoint& r) const { - const WSEndpoint* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -361,10 +361,10 @@ IceInternal::WSEndpoint::operator==(const Endpoint& r) const bool IceInternal::WSEndpoint::operator<(const Endpoint& r) const { - const WSEndpoint* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { - const EndpointI* e = dynamic_cast(&r); + const auto* e = dynamic_cast(&r); if (!e) { return false; diff --git a/cpp/src/Ice/WSTransceiver.cpp b/cpp/src/Ice/WSTransceiver.cpp index 3913458d039..86c4227e545 100644 --- a/cpp/src/Ice/WSTransceiver.cpp +++ b/cpp/src/Ice/WSTransceiver.cpp @@ -50,8 +50,8 @@ using namespace IceInternal; namespace { - const string _iceProtocol = "ice.zeroc.com"; // NOLINT:cert-err58-cpp - const string _wsUUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; // NOLINT:cert-err58-cpp + const string _iceProtocol = "ice.zeroc.com"; // NOLINT(cert-err58-cpp) + const string _wsUUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; // NOLINT(cert-err58-cpp) // // Rename to avoid conflict with OS 10.10 htonll @@ -255,7 +255,7 @@ IceInternal::WSTransceiver::initialize(Buffer& readBuffer, Buffer& writeBuffer) // // Enlarge the buffer and try to read more. // - const size_t oldSize = static_cast(_readBuffer.i - _readBuffer.b.begin()); + const auto oldSize = static_cast(_readBuffer.i - _readBuffer.b.begin()); if (oldSize + 1024 > _instance->messageSizeMax()) { Ex::throwMemoryLimitException(__FILE__, __LINE__, oldSize + 1024, _instance->messageSizeMax()); @@ -937,11 +937,11 @@ IceInternal::WSTransceiver::handleRequest(Buffer& responseBuffer) { throw WebSocketException("invalid value '" + val + "' for WebSocket protocol"); } - for (vector::iterator p = protocols.begin(); p != protocols.end(); ++p) + for (const auto& protocol : protocols) { - if (IceInternal::trim(*p) != _iceProtocol) + if (IceInternal::trim(protocol) != _iceProtocol) { - throw WebSocketException("unknown value '" + *p + "' for WebSocket protocol"); + throw WebSocketException("unknown value '" + protocol + "' for WebSocket protocol"); } addProtocol = true; } @@ -1403,7 +1403,7 @@ IceInternal::WSTransceiver::postRead(Buffer& buf) // Unmask the data we just read. // IceInternal::Buffer::Container::iterator p = _readStart; - for (size_t n = static_cast(_readStart - _readFrameStart); p < buf.i; ++p, ++n) + for (auto n = static_cast(_readStart - _readFrameStart); p < buf.i; ++p, ++n) { *p ^= _readMask[n % 4]; } @@ -1451,7 +1451,7 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) prepareWriteHeader(OP_PONG, _pingPayload.size()); if (_pingPayload.size() > static_cast(_writeBuffer.b.end() - _writeBuffer.i)) { - size_t pos = static_cast(_writeBuffer.i - _writeBuffer.b.begin()); + auto pos = static_cast(_writeBuffer.i - _writeBuffer.b.begin()); _writeBuffer.b.resize(pos + _pingPayload.size()); _writeBuffer.i = _writeBuffer.b.begin() + pos; } @@ -1512,7 +1512,7 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) _writeBuffer.i = _writeBuffer.b.begin(); } - size_t n = static_cast(buf.i - buf.b.begin()); + auto n = static_cast(buf.i - buf.b.begin()); for (; n < buf.b.size() && _writeBuffer.i < _writeBuffer.b.end(); ++_writeBuffer.i, ++n) { *_writeBuffer.i = buf.b[n] ^ _writeMask[n % 4]; @@ -1641,7 +1641,7 @@ IceInternal::WSTransceiver::readBuffered(IceInternal::Buffer::Container::size_ty } else { - size_t available = static_cast(_readBuffer.i - _readI); + auto available = static_cast(_readBuffer.i - _readI); if (available < sz) { if (_readI != &_readBuffer.b[0]) diff --git a/cpp/src/IceBox/Admin.cpp b/cpp/src/IceBox/Admin.cpp index 0ec84282088..bcf3cf666c7 100644 --- a/cpp/src/IceBox/Admin.cpp +++ b/cpp/src/IceBox/Admin.cpp @@ -101,7 +101,7 @@ run(const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args) return 1; } - for (vector::const_iterator r = commands.begin(); r != commands.end(); ++r) + for (auto r = commands.begin(); r != commands.end(); ++r) { if ((*r) == "shutdown") { diff --git a/cpp/src/IceBox/IceBoxService.cpp b/cpp/src/IceBox/IceBoxService.cpp index 4de807dc6f1..9e098b5559d 100644 --- a/cpp/src/IceBox/IceBoxService.cpp +++ b/cpp/src/IceBox/IceBoxService.cpp @@ -33,10 +33,10 @@ IceBox::IceBoxService::start(int argc, char* argv[], int& status) PropertiesPtr properties = communicator()->getProperties(); const string prefix = "IceBox.Service."; PropertyDict services = properties->getPropertiesForPrefix(prefix); - for (PropertyDict::const_iterator p = services.begin(); p != services.end(); ++p) + for (const auto& service : services) { - string name = p->first.substr(prefix.size()); - StringSeq::iterator q = args.begin(); + string name = service.first.substr(prefix.size()); + auto q = args.begin(); while (q != args.end()) { if (q->find("--" + name + ".") == 0) diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index de866d6e5dd..163832166e7 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -50,11 +50,11 @@ namespace entryPoint = args[0]; args.erase(args.begin()); - for (Ice::StringSeq::const_iterator p = serverArgs.begin(); p != serverArgs.end(); ++p) + for (const auto& serverArg : serverArgs) { - if (p->find("--" + name + ".") == 0) + if (serverArg.find("--" + name + ".") == 0) { - args.push_back(*p); + args.push_back(serverArg); } } } @@ -107,7 +107,7 @@ IceBox::ServiceManagerI::ServiceManagerI(CommunicatorPtr communicator, int& argc for (int i = 1; i < argc; i++) { - _argv.push_back(argv[i]); + _argv.emplace_back(argv[i]); } } @@ -163,13 +163,13 @@ IceBox::ServiceManagerI::startService(string name, const Current&) { lock_guard lock(_mutex); - for (vector::iterator p = _services.begin(); p != _services.end(); ++p) + for (auto& service : _services) { - if (p->name == name) + if (service.name == name) { if (started) { - p->status = Started; + service.status = Started; vector services; services.push_back(name); @@ -177,7 +177,7 @@ IceBox::ServiceManagerI::startService(string name, const Current&) } else { - p->status = Stopped; + service.status = Stopped; } break; } @@ -239,13 +239,13 @@ IceBox::ServiceManagerI::stopService(string name, const Current&) { lock_guard lock(_mutex); - for (vector::iterator p = _services.begin(); p != _services.end(); ++p) + for (auto& service : _services) { - if (p->name == name) + if (service.name == name) { if (stopped) { - p->status = Stopped; + service.status = Stopped; vector services; services.push_back(name); @@ -253,7 +253,7 @@ IceBox::ServiceManagerI::stopService(string name, const Current&) } else { - p->status = Started; + service.status = Started; } break; } @@ -288,9 +288,8 @@ IceBox::ServiceManagerI::addObserver(ServiceObserverPrx observer) } vector activeServices; - for (vector::iterator p = _services.begin(); p != _services.end(); ++p) + for (const auto& info : _services) { - const ServiceInfo& info = *p; if (info.status == Started) { activeServices.push_back(info.name); @@ -339,19 +338,19 @@ IceBox::ServiceManagerI::start() StringSeq loadOrder = properties->getIcePropertyAsList("IceBox.LoadOrder"); vector servicesInfo; - for (StringSeq::const_iterator q = loadOrder.begin(); q != loadOrder.end(); ++q) + for (const auto& q : loadOrder) { - PropertyDict::iterator p = services.find(prefix + *q); + auto p = services.find(prefix + q); if (p == services.end()) { - throw FailureException(__FILE__, __LINE__, "ServiceManager: no service definition for '" + *q + "'"); + throw FailureException(__FILE__, __LINE__, "ServiceManager: no service definition for '" + q + "'"); } - servicesInfo.push_back(StartServiceInfo(*q, p->second, _argv)); + servicesInfo.emplace_back(q, p->second, _argv); services.erase(p); } - for (PropertyDict::iterator p = services.begin(); p != services.end(); ++p) + for (const auto& service : services) { - servicesInfo.push_back(StartServiceInfo(p->first.substr(prefix.size()), p->second, _argv)); + servicesInfo.emplace_back(service.first.substr(prefix.size()), service.second, _argv); } // @@ -383,7 +382,7 @@ IceBox::ServiceManagerI::start() // Remove properties from the shared property set that a service explicitly clears. // PropertyDict allProps = initData.properties->getPropertiesForPrefix(""); - for (auto& p : allProps) + for (const auto& p : allProps) { if (svcProperties->getProperty(p.first) == "") { @@ -395,7 +394,7 @@ IceBox::ServiceManagerI::start() // Add the service properties to the shared communicator properties. // PropertyDict props = svcProperties->getPropertiesForPrefix(""); - for (auto& r : props) + for (const auto& r : props) { initData.properties->setProperty(r.first, r.second); } @@ -419,11 +418,11 @@ IceBox::ServiceManagerI::start() // never added. FacetMap facets = _sharedCommunicator->findAllAdminFacets(); - for (FacetMap::const_iterator p = facets.begin(); p != facets.end(); ++p) + for (const auto& facet : facets) { - if (p->first != "Process") + if (facet.first != "Process") { - _communicator->addAdminFacet(p->second, facetNamePrefix + p->first); + _communicator->addAdminFacet(facet.second, facetNamePrefix + facet.first); } } } @@ -432,9 +431,9 @@ IceBox::ServiceManagerI::start() // // Start the services. // - for (vector::const_iterator r = servicesInfo.begin(); r != servicesInfo.end(); ++r) + for (const auto& r : servicesInfo) { - start(r->name, r->entryPoint, r->args); + start(r.name, r.entryPoint, r.args); } // Refresh module list after loading dynamic libraries if stack trace collection is enabled. @@ -620,11 +619,11 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, // which is never added FacetMap facets = communicator->findAllAdminFacets(); - for (FacetMap::const_iterator p = facets.begin(); p != facets.end(); ++p) + for (const auto& facet : facets) { - if (p->first != "Process") + if (facet.first != "Process") { - _communicator->addAdminFacet(p->second, serviceFacetNamePrefix + p->first); + _communicator->addAdminFacet(facet.second, serviceFacetNamePrefix + facet.first); } } } @@ -645,7 +644,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, // Invoke the factory function. // - ServiceFactory factory = reinterpret_cast(sym); + auto factory = reinterpret_cast(sym); try { info.service = ServicePtr(factory(_communicator)); @@ -738,7 +737,7 @@ IceBox::ServiceManagerI::stopAll() // First, for each service, we call stop on the service and flush its database environment to // the disk. // - for (vector::reverse_iterator p = _services.rbegin(); p != _services.rend(); ++p) + for (auto p = _services.rbegin(); p != _services.rend(); ++p) { ServiceInfo& info = *p; @@ -764,7 +763,7 @@ IceBox::ServiceManagerI::stopAll() } } - for (vector::reverse_iterator p = _services.rbegin(); p != _services.rend(); ++p) + for (auto p = _services.rbegin(); p != _services.rend(); ++p) { ServiceInfo& info = *p; @@ -833,9 +832,9 @@ IceBox::ServiceManagerI::servicesStarted(const vector& services, const s { if (services.size() > 0) { - for (auto p : observers) + for (const auto& observer : observers) { - p->servicesStartedAsync(services, nullptr, makeObserverCompletedCallback(p)); + observer->servicesStartedAsync(services, nullptr, makeObserverCompletedCallback(observer)); } } } @@ -845,9 +844,9 @@ IceBox::ServiceManagerI::servicesStopped(const vector& services, const s { if (services.size() > 0) { - for (auto p : observers) + for (const auto& observer : observers) { - p->servicesStoppedAsync(services, nullptr, makeObserverCompletedCallback(p)); + observer->servicesStoppedAsync(services, nullptr, makeObserverCompletedCallback(observer)); } } } @@ -951,11 +950,11 @@ IceBox::ServiceManagerI::configureAdmin(const PropertiesPtr& properties, const s if (_adminEnabled && properties->getIceProperty("Ice.Admin.Enabled").empty()) { StringSeq facetNames; - for (set::const_iterator p = _adminFacetFilter.begin(); p != _adminFacetFilter.end(); ++p) + for (const auto& p : _adminFacetFilter) { - if (p->find(prefix) == 0) // found + if (p.find(prefix) == 0) // found { - facetNames.push_back(p->substr(prefix.size())); + facetNames.push_back(p.substr(prefix.size())); } } @@ -981,11 +980,11 @@ IceBox::ServiceManagerI::removeAdminFacets(const string& prefix) { FacetMap facets = _communicator->findAllAdminFacets(); - for (FacetMap::const_iterator p = facets.begin(); p != facets.end(); ++p) + for (const auto& facet : facets) { - if (p->first.find(prefix) == 0) + if (facet.first.find(prefix) == 0) { - _communicator->removeAdminFacet(p->first); + _communicator->removeAdminFacet(facet.first); } } } diff --git a/cpp/src/IceBridge/IceBridge.cpp b/cpp/src/IceBridge/IceBridge.cpp index 92a4dd4e761..f9ca847f7c3 100644 --- a/cpp/src/IceBridge/IceBridge.cpp +++ b/cpp/src/IceBridge/IceBridge.cpp @@ -197,7 +197,7 @@ BridgeConnection::outgoingSuccess(ConnectionPtr outgoing) // // Flush any queued dispatches // - for (auto& p : _queue) + for (const auto& p : _queue) { auto inParams = make_pair(p.inParams.data(), p.inParams.data() + p.inParams.size()); send(_outgoing, inParams, std::move(p.response), std::move(p.error), p.current); diff --git a/cpp/src/IceDB/IceDB.cpp b/cpp/src/IceDB/IceDB.cpp index 85f714ddfa1..a4248143a14 100644 --- a/cpp/src/IceDB/IceDB.cpp +++ b/cpp/src/IceDB/IceDB.cpp @@ -124,7 +124,7 @@ Env::Env(const string& path, MDB_dbi maxDbs, size_t mapSize, unsigned int maxRea throw LMDBException(__FILE__, __LINE__, rc); } - size_t envMaxKeySize = static_cast(mdb_env_get_maxkeysize(_menv)); + auto envMaxKeySize = static_cast(mdb_env_get_maxkeysize(_menv)); if (maxKeySize > envMaxKeySize) { throw BadEnvException(__FILE__, __LINE__, envMaxKeySize); diff --git a/cpp/src/IceDiscovery/LocatorI.cpp b/cpp/src/IceDiscovery/LocatorI.cpp index 825f78ff32a..ce691d8f911 100644 --- a/cpp/src/IceDiscovery/LocatorI.cpp +++ b/cpp/src/IceDiscovery/LocatorI.cpp @@ -54,7 +54,7 @@ LocatorRegistryI::setReplicatedAdapterDirectProxyAsync( if (proxy) { _adapters.insert({adapterId, std::move(*proxy)}); - map>::iterator p = _replicaGroups.find(replicaGroupId); + auto p = _replicaGroups.find(replicaGroupId); if (p == _replicaGroups.end()) { p = _replicaGroups.insert(make_pair(replicaGroupId, set())).first; @@ -64,7 +64,7 @@ LocatorRegistryI::setReplicatedAdapterDirectProxyAsync( else { _adapters.erase(adapterId); - map>::iterator p = _replicaGroups.find(replicaGroupId); + auto p = _replicaGroups.find(replicaGroupId); if (p != _replicaGroups.end()) { p->second.erase(adapterId); @@ -143,21 +143,21 @@ LocatorRegistryI::findAdapter(const string& adapterId, bool& isReplicaGroup) con { lock_guard lock(_mutex); - map::const_iterator p = _adapters.find(adapterId); + auto p = _adapters.find(adapterId); if (p != _adapters.end()) { isReplicaGroup = false; return p->second; } - map>::const_iterator q = _replicaGroups.find(adapterId); + auto q = _replicaGroups.find(adapterId); if (q != _replicaGroups.end()) { Ice::EndpointSeq endpoints; optional prx; - for (set::const_iterator r = q->second.begin(); r != q->second.end(); ++r) + for (const auto& r : q->second) { - map::const_iterator s = _adapters.find(*r); + auto s = _adapters.find(r); if (s == _adapters.end()) { continue; // TODO: Inconsistency diff --git a/cpp/src/IceDiscovery/LookupI.cpp b/cpp/src/IceDiscovery/LookupI.cpp index 15feff734d0..8f81c4b6bbe 100644 --- a/cpp/src/IceDiscovery/LookupI.cpp +++ b/cpp/src/IceDiscovery/LookupI.cpp @@ -185,17 +185,17 @@ void LookupI::destroy() { lock_guard lock(_mutex); - for (map::const_iterator p = _objectRequests.begin(); p != _objectRequests.end(); ++p) + for (const auto& objectRequest : _objectRequests) { - p->second->finished(nullopt); - _timer->cancel(p->second); + objectRequest.second->finished(nullopt); + _timer->cancel(objectRequest.second); } _objectRequests.clear(); - for (map::const_iterator p = _adapterRequests.begin(); p != _adapterRequests.end(); ++p) + for (const auto& adapterRequest : _adapterRequests) { - p->second->finished(nullopt); - _timer->cancel(p->second); + adapterRequest.second->finished(nullopt); + _timer->cancel(adapterRequest.second); } _adapterRequests.clear(); } @@ -225,7 +225,7 @@ LookupI::setLookupReply(const LookupReplyPrx& lookupReply) } } - _lookups.push_back(make_pair(_lookup->ice_endpoints(EndpointSeq{lookupEndpoint}), reply)); + _lookups.emplace_back(_lookup->ice_endpoints(EndpointSeq{lookupEndpoint}), reply); } assert(!_lookups.empty()); } @@ -283,7 +283,7 @@ void LookupI::findObject(const ObjectCB& cb, const Ice::Identity& id) { lock_guard lock(_mutex); - map::iterator p = _objectRequests.find(id); + auto p = _objectRequests.find(id); if (p == _objectRequests.end()) { p = _objectRequests @@ -310,7 +310,7 @@ void LookupI::findAdapter(const AdapterCB& cb, const std::string& adapterId) { lock_guard lock(_mutex); - map::iterator p = _adapterRequests.find(adapterId); + auto p = _adapterRequests.find(adapterId); if (p == _adapterRequests.end()) { p = _adapterRequests @@ -339,7 +339,7 @@ void LookupI::foundObject(const Ice::Identity& id, const string& requestId, const ObjectPrx& proxy) { lock_guard lock(_mutex); - map::iterator p = _objectRequests.find(id); + auto p = _objectRequests.find(id); // Ignore responses from old requests if (p != _objectRequests.end() && p->second->getRequestId() == requestId) { @@ -354,7 +354,7 @@ LookupI::foundAdapter(const string& adapterId, const string& requestId, const Ob { lock_guard lock(_mutex); - map::iterator p = _adapterRequests.find(adapterId); + auto p = _adapterRequests.find(adapterId); if (p != _adapterRequests.end() && p->second->getRequestId() == requestId) // Ignore responses from old requests { if (p->second->response(proxy, isReplicaGroup)) @@ -369,7 +369,7 @@ void LookupI::objectRequestTimedOut(const ObjectRequestPtr& request) { lock_guard lock(_mutex); - map::iterator p = _objectRequests.find(request->getId()); + auto p = _objectRequests.find(request->getId()); if (p == _objectRequests.end() || p->second.get() != request.get()) { return; @@ -397,7 +397,7 @@ void LookupI::adapterRequestException(const AdapterRequestPtr& request, exception_ptr ex) { lock_guard lock(_mutex); - map::iterator p = _adapterRequests.find(request->getId()); + auto p = _adapterRequests.find(request->getId()); if (p == _adapterRequests.end() || p->second.get() != request.get()) { return; @@ -427,7 +427,7 @@ void LookupI::adapterRequestTimedOut(const AdapterRequestPtr& request) { lock_guard lock(_mutex); - map::iterator p = _adapterRequests.find(request->getId()); + auto p = _adapterRequests.find(request->getId()); if (p == _adapterRequests.end() || p->second.get() != request.get()) { return; @@ -455,7 +455,7 @@ void LookupI::objectRequestException(const ObjectRequestPtr& request, exception_ptr ex) { lock_guard lock(_mutex); - map::iterator p = _objectRequests.find(request->getId()); + auto p = _objectRequests.find(request->getId()); if (p == _objectRequests.end() || p->second.get() != request.get()) { return; diff --git a/cpp/src/IceDiscovery/LookupI.h b/cpp/src/IceDiscovery/LookupI.h index 844c5c2e5a2..f97b2086594 100644 --- a/cpp/src/IceDiscovery/LookupI.h +++ b/cpp/src/IceDiscovery/LookupI.h @@ -56,9 +56,9 @@ namespace IceDiscovery void finished(const std::optional& proxy) override { - for (typename std::vector::const_iterator p = _callbacks.begin(); p != _callbacks.end(); ++p) + for (const auto& callback : _callbacks) { - p->first(proxy); + callback.first(proxy); } _callbacks.clear(); } diff --git a/cpp/src/IceDiscovery/PluginI.cpp b/cpp/src/IceDiscovery/PluginI.cpp index 9d11b2740d9..2d2c874a4e6 100644 --- a/cpp/src/IceDiscovery/PluginI.cpp +++ b/cpp/src/IceDiscovery/PluginI.cpp @@ -77,7 +77,7 @@ PluginI::initialize() IceInternal::ProtocolSupport protocol = ipv4 && !preferIPv6 ? IceInternal::EnableIPv4 : IceInternal::EnableIPv6; vector interfaces = IceInternal::getInterfacesForMulticast(intf, protocol); ostringstream lookup; - for (vector::const_iterator p = interfaces.begin(); p != interfaces.end(); ++p) + for (auto p = interfaces.begin(); p != interfaces.end(); ++p) { if (p != interfaces.begin()) { diff --git a/cpp/src/IceGrid/Activator.cpp b/cpp/src/IceGrid/Activator.cpp index a12290bb294..be81513a346 100644 --- a/cpp/src/IceGrid/Activator.cpp +++ b/cpp/src/IceGrid/Activator.cpp @@ -745,7 +745,7 @@ Activator::activate( if (getuid() == 0 && setgroups(static_cast(groups.size()), &groups[0]) == -1) { ostringstream os; - for (vector::const_iterator p = groups.begin(); p != groups.end(); ++p) + for (auto p = groups.begin(); p != groups.end(); ++p) { os << *p; if (p + 1 != groups.end()) @@ -1267,9 +1267,9 @@ Activator::terminationListener() { lock_guard lock(_mutex); - for (map::iterator p = _processes.begin(); p != _processes.end(); ++p) + for (const auto& p : _processes) { - int fd = p->second.pipeFd; + int fd = p.second.pipeFd; FD_SET(fd, &fdSet); if (maxFd < fd) { @@ -1314,7 +1314,7 @@ Activator::terminationListener() } } - map::iterator p = _processes.begin(); + auto p = _processes.begin(); while (p != _processes.end()) { int fd = p->second.pipeFd; @@ -1372,16 +1372,16 @@ Activator::terminationListener() deactivated = _deactivating && _processes.empty(); } - for (vector::const_iterator p = terminated.begin(); p != terminated.end(); ++p) + for (const auto& p : terminated) { - int status = waitPid(p->pid); + int status = waitPid(p.pid); if (_traceLevels->activator > 0) { Ice::Trace out(_traceLevels->logger, _traceLevels->activatorCat); - out << "detected termination of server '" << p->server->getId() << "'"; - if (!p->msg.empty()) + out << "detected termination of server '" << p.server->getId() << "'"; + if (!p.msg.empty()) { - out << "\nreason = " << p->msg; + out << "\nreason = " << p.msg; } if (WIFEXITED(status) && status != 0) { @@ -1395,12 +1395,12 @@ Activator::terminationListener() try { - p->server->terminated(p->msg, status); + p.server->terminated(p.msg, status); } catch (const Ice::LocalException& ex) { Ice::Warning out(_traceLevels->logger); - out << "unexpected exception raised by server '" << p->server->getId() << "' termination:\n" << ex; + out << "unexpected exception raised by server '" << p.server->getId() << "' termination:\n" << ex; } } diff --git a/cpp/src/IceGrid/AdapterCache.cpp b/cpp/src/IceGrid/AdapterCache.cpp index 56f4b95dfb8..6b5ed1b02e1 100644 --- a/cpp/src/IceGrid/AdapterCache.cpp +++ b/cpp/src/IceGrid/AdapterCache.cpp @@ -134,18 +134,18 @@ GetAdapterInfoResult::add(const ServerAdapterEntry* adapter) _adapters.push_back(info); try { - _results.push_back(adapter->getProxy("", true)->getDirectProxyAsync()); + _results.emplace_back(adapter->getProxy("", true)->getDirectProxyAsync()); } catch (const Ice::Exception&) { - _results.push_back(nullopt); + _results.emplace_back(nullopt); } } AdapterInfoSeq GetAdapterInfoResult::get() { - vector::iterator q = _adapters.begin(); + auto q = _adapters.begin(); for (auto p = _results.begin(); p != _results.end(); ++p, ++q) { try diff --git a/cpp/src/IceGrid/Allocatable.cpp b/cpp/src/IceGrid/Allocatable.cpp index 1d58e4d90a5..726a64da143 100644 --- a/cpp/src/IceGrid/Allocatable.cpp +++ b/cpp/src/IceGrid/Allocatable.cpp @@ -345,12 +345,12 @@ Allocatable::queueAllocationAttempt( { if (request->pending()) { - _requests.push_back({allocatable, request}); + _requests.emplace_back(allocatable, request); } } else { - _requests.push_back({allocatable, nullptr}); + _requests.emplace_back(allocatable, nullptr); } } @@ -364,7 +364,7 @@ Allocatable::queueAllocationAttemptFromChild(const shared_ptr& allo } lock_guard lock(_mutex); - _requests.push_back({allocatable, nullptr}); + _requests.emplace_back(allocatable, nullptr); } shared_ptr diff --git a/cpp/src/IceGrid/AllocatableObjectCache.cpp b/cpp/src/IceGrid/AllocatableObjectCache.cpp index 57f7ac74ab6..18f2f356e40 100644 --- a/cpp/src/IceGrid/AllocatableObjectCache.cpp +++ b/cpp/src/IceGrid/AllocatableObjectCache.cpp @@ -131,7 +131,7 @@ AllocatableObjectCache::add(const ObjectInfo& info, const shared_ptr(*this, info, parent); addImpl(id, entry); - map::iterator p = _types.find(entry->getType()); + auto p = _types.find(entry->getType()); if (p == _types.end()) { p = _types.insert(p, map::value_type(entry->getType(), TypeEntry())); diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp index 5d74cc7416e..040cb44818c 100644 --- a/cpp/src/IceGrid/Database.cpp +++ b/cpp/src/IceGrid/Database.cpp @@ -31,7 +31,7 @@ using ObjectsMapROCursor = IceDB::ReadOnlyCursor vector toVector(const IceDB::ReadOnlyTxn& txn, const IceDB::Dbi& m) @@ -391,9 +391,9 @@ Database::syncApplications(const ApplicationInfoSeq& newApplications, int64_t db oldApplications = toMap(txn, _applications); _applications.clear(txn); - for (ApplicationInfoSeq::const_iterator p = newApplications.begin(); p != newApplications.end(); ++p) + for (const auto& newApplication : newApplications) { - _applications.put(txn, p->descriptor.name, *p); + _applications.put(txn, newApplication.descriptor.name, newApplication); } dbSerial = updateSerial(txn, applicationsDbName, dbSerial); @@ -408,35 +408,39 @@ Database::syncApplications(const ApplicationInfoSeq& newApplications, int64_t db ServerEntrySeq entries; set names; - for (ApplicationInfoSeq::const_iterator p = newApplications.begin(); p != newApplications.end(); ++p) + for (const auto& newApplication : newApplications) { try { - map::const_iterator q = oldApplications.find(p->descriptor.name); + auto q = oldApplications.find(newApplication.descriptor.name); if (q != oldApplications.end()) { ApplicationHelper previous(_communicator, q->second.descriptor); - ApplicationHelper helper(_communicator, p->descriptor); - reload(previous, helper, entries, p->uuid, p->revision, false); + ApplicationHelper helper(_communicator, newApplication.descriptor); + reload(previous, helper, entries, newApplication.uuid, newApplication.revision, false); } else { - load(ApplicationHelper(_communicator, p->descriptor), entries, p->uuid, p->revision); + load( + ApplicationHelper(_communicator, newApplication.descriptor), + entries, + newApplication.uuid, + newApplication.revision); } } catch (const DeploymentException& ex) { Ice::Warning warn(_traceLevels->logger); - warn << "invalid application '" << p->descriptor.name << "':\n" << ex.reason; + warn << "invalid application '" << newApplication.descriptor.name << "':\n" << ex.reason; } - names.insert(p->descriptor.name); + names.insert(newApplication.descriptor.name); } - for (map::iterator s = oldApplications.begin(); s != oldApplications.end(); ++s) + for (const auto& oldApplication : oldApplications) { - if (names.find(s->first) == names.end()) + if (names.find(oldApplication.first) == names.end()) { - unload(ApplicationHelper(_communicator, s->second.descriptor), entries); + unload(ApplicationHelper(_communicator, oldApplication.second.descriptor), entries); } } @@ -649,7 +653,7 @@ Database::addApplication(const ApplicationInfo& info, AdminSessionI* session, in { lock_guard lock(_mutex); - vector::iterator p = find(_updating.begin(), _updating.end(), info.descriptor.name); + auto p = find(_updating.begin(), _updating.end(), info.descriptor.name); assert(p != _updating.end()); p->markUpdated(); } @@ -658,11 +662,11 @@ Database::addApplication(const ApplicationInfo& info, AdminSessionI* session, in { try { - for (ServerEntrySeq::const_iterator p = entries.begin(); p != entries.end(); ++p) + for (const auto& entry : entries) { try { - (*p)->waitForSync(); + entry->waitForSync(); } catch (const NodeUnreachableException&) { @@ -954,10 +958,10 @@ Database::waitForApplicationUpdate( { lock_guard lock(_mutex); - vector::iterator p = find(_updating.begin(), _updating.end(), make_pair(uuid, revision)); + auto p = find(_updating.begin(), _updating.end(), make_pair(uuid, revision)); if (p != _updating.end() && !p->updated) { - p->cbs.push_back({response, exception}); + p->cbs.emplace_back(response, exception); } else { @@ -1132,11 +1136,11 @@ Database::getAdapterDirectProxy( } filterAdapterInfos("", id, _pluginFacade, con, ctx, infos); - for (unsigned int i = 0; i < infos.size(); ++i) + for (const auto& p : infos) { - if (IceInternal::isSupported(encoding, infos[i].proxy->ice_getEncodingVersion())) + if (IceInternal::isSupported(encoding, p.proxy->ice_getEncodingVersion())) { - Ice::EndpointSeq edpts = infos[i].proxy->ice_getEndpoints(); + Ice::EndpointSeq edpts = p.proxy->ice_getEndpoints(); endpoints.insert(endpoints.end(), edpts.begin(), edpts.end()); } } @@ -1255,9 +1259,9 @@ Database::getLocatorAdapterInfo( if (!filters.empty()) { Ice::StringSeq adapterIds; - for (LocatorAdapterInfoSeq::const_iterator q = adpts.begin(); q != adpts.end(); ++q) + for (const auto& adpt : adpts) { - adapterIds.push_back(q->id); + adapterIds.push_back(adpt.id); } for (const auto& f : filters) @@ -1267,13 +1271,13 @@ Database::getLocatorAdapterInfo( LocatorAdapterInfoSeq filteredAdpts; filteredAdpts.reserve(adpts.size()); - for (Ice::StringSeq::const_iterator q = adapterIds.begin(); q != adapterIds.end(); ++q) + for (const auto& adapterId : adapterIds) { - for (LocatorAdapterInfoSeq::const_iterator r = adpts.begin(); r != adpts.end(); ++r) + for (const auto& adpt : adpts) { - if (*q == r->id) + if (adapterId == adpt.id) { - filteredAdpts.push_back(*r); + filteredAdpts.push_back(adpt); break; } } @@ -1482,9 +1486,9 @@ Database::getAllAdapters(const string& expression) // COMPILERFIX: We're not using result.insert() here, this doesn't compile on Sun. // // result.insert(result.end(), groups.begin(), groups.end()) - for (set::const_iterator q = groups.begin(); q != groups.end(); ++q) + for (const auto& group : groups) { - result.push_back(*q); + result.push_back(group); } return result; } @@ -1805,7 +1809,7 @@ Database::getObjectByTypeOnLeastLoadedNode( { } } - objectsWithLoad.push_back(make_pair(obj, load)); + objectsWithLoad.emplace_back(obj, load); } return min_element( objectsWithLoad.begin(), @@ -1825,7 +1829,7 @@ Database::getObjectsByType(const string& type, const shared_ptr { if (_nodeObserverTopic->isServerEnabled(obj->getServer())) // Only return proxies from enabled servers. { - proxies.push_back(obj->getProxy()); + proxies.emplace_back(obj->getProxy()); } } @@ -1897,9 +1901,9 @@ Database::getObjectInfosByType(const string& type) IceDB::ReadOnlyTxn txn(_env); ObjectInfoSeq dbInfos = findByType(txn, _objects, _objectsByType, type); - for (unsigned int i = 0; i < dbInfos.size(); ++i) + for (const auto& dbInfo : dbInfos) { - infos.push_back(dbInfos[i]); + infos.push_back(dbInfo); } return infos; } @@ -1966,9 +1970,9 @@ Database::getInternalObjectsByType(const string& type) IceDB::ReadOnlyTxn txn(_env); vector infos = findByType(txn, _internalObjects, _internalObjectsByType, type); - for (unsigned int i = 0; i < infos.size(); ++i) + for (const auto& info : infos) { - proxies.push_back(infos[i].proxy); + proxies.push_back(info.proxy); } return proxies; } @@ -1989,16 +1993,16 @@ Database::checkForAddition(const ApplicationHelper& app, const IceDB::ReadWriteT if (!adapterIds.empty()) { - for (set::const_iterator p = adapterIds.begin(); p != adapterIds.end(); ++p) + for (const auto& adapterId : adapterIds) { - checkAdapterForAddition(*p, txn); + checkAdapterForAddition(adapterId, txn); } } if (!objectIds.empty()) { - for (set::const_iterator p = objectIds.begin(); p != objectIds.end(); ++p) + for (const auto& objectId : objectIds) { - checkObjectForAddition(*p, txn); + checkObjectForAddition(objectId, txn); } } @@ -2246,9 +2250,9 @@ Database::unload(const ApplicationHelper& app, ServerEntrySeq& entries) for (const auto& adpt : app.getInstance().replicaGroups) { - for (ObjectDescriptorSeq::const_iterator o = adpt.objects.begin(); o != adpt.objects.end(); ++o) + for (const auto& object : adpt.objects) { - _objectCache.remove(o->id); + _objectCache.remove(object.id); } _adapterCache.removeReplicaGroup(adpt.id); } @@ -2278,31 +2282,31 @@ Database::reload( auto oldServers = oldApp.getServerInfos(uuid, revision); auto newServers = newApp.getServerInfos(uuid, revision); vector> load; - for (map::const_iterator p = newServers.begin(); p != newServers.end(); ++p) + for (const auto& newServer : newServers) { - map::const_iterator q = oldServers.find(p->first); + auto q = oldServers.find(newServer.first); if (q == oldServers.end()) { - load.push_back(make_pair(false, p->second)); + load.emplace_back(false, newServer.second); } - else if (isServerUpdated(p->second, q->second)) + else if (isServerUpdated(newServer.second, q->second)) { - _serverCache.preUpdate(p->second, noRestart); - load.push_back(make_pair(true, p->second)); + _serverCache.preUpdate(newServer.second, noRestart); + load.emplace_back(true, newServer.second); } else { - auto server = _serverCache.get(p->first); + auto server = _serverCache.get(newServer.first); server->update(q->second, noRestart); // Just update the server revision on the node. entries.push_back(server); } } - for (map::const_iterator p = oldServers.begin(); p != oldServers.end(); ++p) + for (const auto& oldServer : oldServers) { - map::const_iterator q = newServers.find(p->first); + auto q = newServers.find(oldServer.first); if (q == newServers.end()) { - entries.push_back(_serverCache.remove(p->first, noRestart)); + entries.push_back(_serverCache.remove(oldServer.first, noRestart)); } } @@ -2311,23 +2315,23 @@ Database::reload( // const ReplicaGroupDescriptorSeq& oldAdpts = oldApp.getInstance().replicaGroups; const ReplicaGroupDescriptorSeq& newAdpts = newApp.getInstance().replicaGroups; - for (ReplicaGroupDescriptorSeq::const_iterator r = oldAdpts.begin(); r != oldAdpts.end(); ++r) + for (const auto& oldAdpt : oldAdpts) { ReplicaGroupDescriptorSeq::const_iterator t; for (t = newAdpts.begin(); t != newAdpts.end(); ++t) { - if (t->id == r->id) + if (t->id == oldAdpt.id) { break; } } - for (ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o) + for (const auto& object : oldAdpt.objects) { - _objectCache.remove(o->id); + _objectCache.remove(object.id); } if (t == newAdpts.end()) { - _adapterCache.removeReplicaGroup(r->id); + _adapterCache.removeReplicaGroup(oldAdpt.id); } } @@ -2335,54 +2339,54 @@ Database::reload( // Remove all the node descriptors. // const NodeDescriptorDict& oldNodes = oldApp.getInstance().nodes; - for (NodeDescriptorDict::const_iterator n = oldNodes.begin(); n != oldNodes.end(); ++n) + for (const auto& oldNode : oldNodes) { - _nodeCache.get(n->first)->removeDescriptor(application); + _nodeCache.get(oldNode.first)->removeDescriptor(application); } // // Add back node descriptors. // const NodeDescriptorDict& newNodes = newApp.getInstance().nodes; - for (NodeDescriptorDict::const_iterator n = newNodes.begin(); n != newNodes.end(); ++n) + for (const auto& newNode : newNodes) { - _nodeCache.get(n->first, true)->addDescriptor(application, n->second); + _nodeCache.get(newNode.first, true)->addDescriptor(application, newNode.second); } // // Add back replica groups. // - for (ReplicaGroupDescriptorSeq::const_iterator r = newAdpts.begin(); r != newAdpts.end(); ++r) + for (const auto& newAdpt : newAdpts) { try { - auto entry = dynamic_pointer_cast(_adapterCache.get(r->id)); + auto entry = dynamic_pointer_cast(_adapterCache.get(newAdpt.id)); assert(entry); - entry->update(application, r->loadBalancing, r->filter); + entry->update(application, newAdpt.loadBalancing, newAdpt.filter); } catch (const AdapterNotExistException&) { - _adapterCache.addReplicaGroup(*r, application); + _adapterCache.addReplicaGroup(newAdpt, application); } - for (ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o) + for (auto o = newAdpt.objects.begin(); o != newAdpt.objects.end(); ++o) { - _objectCache.add(toObjectInfo(_communicator, *o, r->id), application, ""); + _objectCache.add(toObjectInfo(_communicator, *o, newAdpt.id), application, ""); } } // // Add back servers. // - for (vector>::const_iterator q = load.begin(); q != load.end(); ++q) + for (const auto& q : load) { - if (q->first) // Update + if (q.first) // Update { - entries.push_back(_serverCache.postUpdate(q->second, noRestart)); + entries.push_back(_serverCache.postUpdate(q.second, noRestart)); } else { - entries.push_back(_serverCache.add(q->second)); + entries.push_back(_serverCache.add(q.second)); } } } @@ -2534,9 +2538,9 @@ Database::checkUpdate( } if (!reasons.empty()) { - for (vector::const_iterator r = reasons.begin(); r != reasons.end(); ++r) + for (const auto& reason : reasons) { - out << "\n" << *r; + out << "\n" << reason; } } } @@ -2573,9 +2577,9 @@ Database::checkUpdate( { ostringstream os; os << "check for application '" << application << "' update failed:"; - for (vector::const_iterator r = reasons.begin(); r != reasons.end(); ++r) + for (const auto& reason : reasons) { - os << "\n" << *r; + os << "\n" << reason; } throw DeploymentException(os.str()); } @@ -2653,11 +2657,11 @@ Database::finishApplicationUpdate( { try { - for (ServerEntrySeq::const_iterator p = entries.begin(); p != entries.end(); ++p) + for (const auto& entrie : entries) { try { - (*p)->waitForSync(); + entrie->waitForSync(); } catch (const NodeUnreachableException&) { @@ -2696,7 +2700,7 @@ Database::finishApplicationUpdate( newUpdate.revision = info.revision; newUpdate.descriptor = helper.diff(previous); - vector::iterator p = find(_updating.begin(), _updating.end(), update.descriptor.name); + auto p = find(_updating.begin(), _updating.end(), update.descriptor.name); assert(p != _updating.end()); p->unmarkUpdated(); @@ -2738,7 +2742,7 @@ Database::startUpdating(const string& name, const string& uuid, int revision) { // Must be called within the synchronization. assert(find(_updating.begin(), _updating.end(), name) == _updating.end()); - _updating.push_back(UpdateInfo(name, uuid, revision)); + _updating.emplace_back(name, uuid, revision); } void @@ -2746,7 +2750,7 @@ Database::finishUpdating(const string& name) { lock_guard lock(_mutex); - vector::iterator p = find(_updating.begin(), _updating.end(), name); + auto p = find(_updating.begin(), _updating.end(), name); assert(p != _updating.end()); p->markUpdated(); _updating.erase(p); diff --git a/cpp/src/IceGrid/DescriptorBuilder.cpp b/cpp/src/IceGrid/DescriptorBuilder.cpp index 372033e8c35..91294459481 100644 --- a/cpp/src/IceGrid/DescriptorBuilder.cpp +++ b/cpp/src/IceGrid/DescriptorBuilder.cpp @@ -26,11 +26,11 @@ void XmlAttributesHelper::checkUnknownAttributes() { vector notUsed; - for (map::const_iterator p = _attributes.begin(); p != _attributes.end(); ++p) + for (const auto& attribute : _attributes) { - if (_used.find(p->first) == _used.end()) + if (_used.find(attribute.first) == _used.end()) { - notUsed.push_back(p->first); + notUsed.push_back(attribute.first); } } @@ -53,7 +53,7 @@ string XmlAttributesHelper::operator()(const string& name) const { _used.insert(name); - XMLAttributes::const_iterator p = _attributes.find(name); + auto p = _attributes.find(name); if (p == _attributes.end()) { throw invalid_argument("missing attribute '" + name + "'"); @@ -70,7 +70,7 @@ string XmlAttributesHelper::operator()(const string& name, const string& def) const { _used.insert(name); - XMLAttributes::const_iterator p = _attributes.find(name); + auto p = _attributes.find(name); if (p == _attributes.end()) { return def; @@ -84,9 +84,9 @@ XmlAttributesHelper::operator()(const string& name, const string& def) const map XmlAttributesHelper::asMap() const { - for (map::const_iterator p = _attributes.begin(); p != _attributes.end(); ++p) + for (const auto& attribute : _attributes) { - _used.insert(p->first); + _used.insert(attribute.first); } return _attributes; } @@ -95,7 +95,7 @@ bool XmlAttributesHelper::asBool(const string& name) const { _used.insert(name); - XMLAttributes::const_iterator p = _attributes.find(name); + auto p = _attributes.find(name); if (p == _attributes.end()) { throw invalid_argument("missing attribute '" + name + "'"); @@ -118,7 +118,7 @@ bool XmlAttributesHelper::asBool(const string& name, bool def) const { _used.insert(name); - XMLAttributes::const_iterator p = _attributes.find(name); + auto p = _attributes.find(name); if (p == _attributes.end()) { return def; @@ -354,7 +354,7 @@ ApplicationDescriptorBuilder::createPropertySet(const XmlAttributesHelper& attrs { string id = attrs("id"); - PropertySetDescriptorBuilder* builder = new PropertySetDescriptorBuilder(); + auto* builder = new PropertySetDescriptorBuilder(); builder->setId(id); return builder; } @@ -422,7 +422,7 @@ ServerInstanceDescriptorBuilder::createPropertySet(const XmlAttributesHelper& at service = attrs("service"); // Can't be empty. } - PropertySetDescriptorBuilder* builder = new PropertySetDescriptorBuilder(); + auto* builder = new PropertySetDescriptorBuilder(); builder->setService(service); return builder; } @@ -472,7 +472,7 @@ NodeDescriptorBuilder::createPropertySet(const XmlAttributesHelper& attrs) const { string id = attrs("id"); - PropertySetDescriptorBuilder* builder = new PropertySetDescriptorBuilder(); + auto* builder = new PropertySetDescriptorBuilder(); builder->setId(id); return builder; } diff --git a/cpp/src/IceGrid/DescriptorBuilder.h b/cpp/src/IceGrid/DescriptorBuilder.h index 082e8cee1ec..6f81572eed1 100644 --- a/cpp/src/IceGrid/DescriptorBuilder.h +++ b/cpp/src/IceGrid/DescriptorBuilder.h @@ -18,10 +18,10 @@ namespace IceGrid XmlAttributesHelper(const XMLAttributes&, Ice::LoggerPtr, std::string, int); void checkUnknownAttributes(); - bool contains(const std::string&) const; // NOLINT:modernize-use-nodiscard - std::map asMap() const; // NOLINT:modernize-use-nodiscard - bool asBool(const std::string&) const; // NOLINT:modernize-use-nodiscard - bool asBool(const std::string&, bool) const; // NOLINT:modernize-use-nodiscard + bool contains(const std::string&) const; // NOLINT(modernize-use-nodiscard) + std::map asMap() const; // NOLINT(modernize-use-nodiscard) + bool asBool(const std::string&) const; // NOLINT(modernize-use-nodiscard) + bool asBool(const std::string&, bool) const; // NOLINT(modernize-use-nodiscard) std::string operator()(const std::string&) const; std::string operator()(const std::string&, const std::string&) const; diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp index 5d54234c154..26e541698de 100644 --- a/cpp/src/IceGrid/DescriptorHelper.cpp +++ b/cpp/src/IceGrid/DescriptorHelper.cpp @@ -31,9 +31,9 @@ namespace return false; } - for (typename Seq::const_iterator p = rseq.begin(); p != rseq.end(); ++p) + for (auto p = rseq.begin(); p != rseq.end(); ++p) { - typename Seq::const_iterator q = lseq.begin(); + auto q = lseq.begin(); for (; q != lseq.end(); ++q) { if (func(*p) == func(*q)) @@ -200,9 +200,9 @@ namespace Seq getSeqUpdatedEltsWithEq(const Seq& lseq, const Seq& rseq, GetKeyFunc func, EqFunc eq) { Seq result; - for (typename Seq::const_iterator p = rseq.begin(); p != rseq.end(); ++p) + for (auto p = rseq.begin(); p != rseq.end(); ++p) { - typename Seq::const_iterator q = lseq.begin(); + auto q = lseq.begin(); for (; q != lseq.end(); ++q) { if (func(*p) == func(*q)) @@ -222,7 +222,7 @@ namespace Ice::StringSeq getSeqRemovedElts(const Seq& lseq, const Seq& rseq, GetKeyFunc func) { Ice::StringSeq removed; - for (typename Seq::const_iterator p = lseq.begin(); p != lseq.end(); ++p) + for (auto p = lseq.begin(); p != lseq.end(); ++p) { typename Seq::const_iterator q; for (q = rseq.begin(); q != rseq.end(); ++q) @@ -245,11 +245,11 @@ namespace { Seq result = update; set removed(remove.begin(), remove.end()); - for (typename Seq::const_iterator p = seq.begin(); p != seq.end(); ++p) + for (auto p = seq.begin(); p != seq.end(); ++p) { if (removed.find(func(*p)) == removed.end()) { - typename Seq::const_iterator q = update.begin(); + auto q = update.begin(); for (; q != update.end(); ++q) { if (func(*p) == func(*q)) @@ -270,9 +270,9 @@ namespace Dict getDictUpdatedEltsWithEq(const Dict& ldict, const Dict& rdict, EqFunc eq) { Dict result; - for (typename Dict::const_iterator p = rdict.begin(); p != rdict.end(); ++p) + for (auto p = rdict.begin(); p != rdict.end(); ++p) { - typename Dict::const_iterator q = ldict.find(p->first); + auto q = ldict.find(p->first); if (q == ldict.end() || !eq(p->second, q->second)) { result.insert(*p); @@ -289,7 +289,7 @@ namespace template Ice::StringSeq getDictRemovedElts(const Dict& ldict, const Dict& rdict) { Ice::StringSeq removed; - for (typename Dict::const_iterator p = ldict.begin(); p != ldict.end(); ++p) + for (auto p = ldict.begin(); p != ldict.end(); ++p) { if (rdict.find(p->first) == rdict.end()) { @@ -302,11 +302,11 @@ namespace template Dict updateDictElts(const Dict& dict, const Dict& update, const Ice::StringSeq& remove) { Dict result = dict; - for (Ice::StringSeq::const_iterator p = remove.begin(); p != remove.end(); ++p) + for (const auto& p : remove) { - result.erase(*p); + result.erase(p); } - for (typename Dict::const_iterator q = update.begin(); q != update.end(); ++q) + for (auto q = update.begin(); q != update.end(); ++q) { result[q->first] = q->second; } @@ -372,28 +372,26 @@ Resolver::Resolver( // _deprecated["node.datadir"] = "node.data"; - for (StringStringDict::const_iterator v = _variables.begin(); v != _variables.end(); ++v) + for (const auto& variable : _variables) { - if (v->first == "") + if (variable.first == "") { exception("empty variable name"); } } - for (TemplateDescriptorDict::const_iterator t = _application->serverTemplates.begin(); - t != _application->serverTemplates.end(); - ++t) + for (const auto& serverTemplate : _application->serverTemplates) { - if (t->first == "") + if (serverTemplate.first == "") { exception("empty server template id"); } - if (!t->second.descriptor) + if (!serverTemplate.second.descriptor) { - exception("invalid server template '" + t->first + "': server definition is empty"); + exception("invalid server template '" + serverTemplate.first + "': server definition is empty"); } - Ice::StringSeq params = t->second.parameters; + Ice::StringSeq params = serverTemplate.second.parameters; sort(params.begin(), params.end()); Ice::StringSeq wdups = params; Ice::StringSeq dups; @@ -406,22 +404,20 @@ Resolver::Resolver( if (!dups.empty()) { dups.erase(unique(dups.begin(), dups.end()), dups.end()); - exception("invalid server template '" + t->first + "': duplicate parameters " + toString(dups)); + exception("invalid server template '" + serverTemplate.first + "': duplicate parameters " + toString(dups)); } } - for (TemplateDescriptorDict::const_iterator t = _application->serviceTemplates.begin(); - t != _application->serviceTemplates.end(); - ++t) + for (const auto& serviceTemplate : _application->serviceTemplates) { - if (t->first == "") + if (serviceTemplate.first == "") { exception("empty service template id"); } - if (!t->second.descriptor) + if (!serviceTemplate.second.descriptor) { - exception("invalid service template '" + t->first + "': service definition is empty"); + exception("invalid service template '" + serviceTemplate.first + "': service definition is empty"); } - Ice::StringSeq params = t->second.parameters; + Ice::StringSeq params = serviceTemplate.second.parameters; sort(params.begin(), params.end()); Ice::StringSeq wdups = params; Ice::StringSeq dups; @@ -434,7 +430,8 @@ Resolver::Resolver( if (!dups.empty()) { dups.erase(unique(dups.begin(), dups.end()), dups.end()); - exception("invalid server template '" + t->first + "': duplicate parameters " + toString(dups)); + exception( + "invalid server template '" + serviceTemplate.first + "': duplicate parameters " + toString(dups)); } } } @@ -463,9 +460,9 @@ Resolver::Resolver(const Resolver& resolve, const map& values, b checkReserved("variable", values); } - for (StringStringDict::const_iterator v = _variables.begin(); v != _variables.end(); ++v) + for (const auto& variable : _variables) { - if (v->first == "") + if (variable.first == "") { exception("empty variable name"); } @@ -531,9 +528,9 @@ Ice::StringSeq Resolver::operator()(const Ice::StringSeq& values, const string& name) const { Ice::StringSeq result; - for (Ice::StringSeq::const_iterator p = values.begin(); p != values.end(); ++p) + for (const auto& value : values) { - result.push_back(operator()(*p, name)); + result.push_back(operator()(value, name)); } return result; } @@ -542,11 +539,11 @@ PropertyDescriptorSeq Resolver::operator()(const PropertyDescriptorSeq& properties, const string& name) const { PropertyDescriptorSeq result; - for (PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) + for (const auto& p : properties) { PropertyDescriptor prop; - prop.name = operator()(q->name, name + " name"); - prop.value = operator()(q->value, name + " value"); + prop.name = operator()(p.name, name + " name"); + prop.value = operator()(p.value, name + " value"); result.push_back(prop); } return result; @@ -556,12 +553,16 @@ PropertySetDescriptorDict Resolver::operator()(const PropertySetDescriptorDict& propertySets) const { PropertySetDescriptorDict result; - for (PropertySetDescriptorDict::const_iterator ps = propertySets.begin(); ps != propertySets.end(); ++ps) + for (const auto& propertySet : propertySets) { PropertySetDescriptor desc; - desc.references = operator()(ps->second.references, "property set '" + ps->first + "' reference"); - desc.properties = operator()(ps->second.properties, "property set '" + ps->first + "' property"); - result.insert(make_pair(ps->first, desc)); + desc.references = operator()( + propertySet.second.references, + "property set '" + propertySet.first + "' reference"); + desc.properties = operator()( + propertySet.second.properties, + "property set '" + propertySet.first + "' property"); + result.insert(make_pair(propertySet.first, desc)); } return result; } @@ -570,14 +571,14 @@ ObjectDescriptorSeq Resolver::operator()(const ObjectDescriptorSeq& objects, const string& proxyOptions, const string& type) const { ObjectDescriptorSeq result; - for (ObjectDescriptorSeq::const_iterator q = objects.begin(); q != objects.end(); ++q) + for (const auto& object : objects) { ObjectDescriptor obj; - obj.type = operator()(q->type, type + " object type"); - obj.id = operator()(q->id, type + " object identity"); - if (!q->proxyOptions.empty()) + obj.type = operator()(object.type, type + " object type"); + obj.id = operator()(object.id, type + " object identity"); + if (!object.proxyOptions.empty()) { - obj.proxyOptions = IceInternal::trim(operator()(q->proxyOptions, type + " object proxy options")); + obj.proxyOptions = IceInternal::trim(operator()(object.proxyOptions, type + " object proxy options")); } else if (!proxyOptions.empty()) { @@ -706,11 +707,11 @@ Resolver::addPropertySets(const PropertySetDescriptorDict& propertySets) { PropertySetDescriptorDict oldPropertySets; oldPropertySets.swap(_propertySets); - for (PropertySetDescriptorDict::const_iterator p = propertySets.begin(); p != propertySets.end(); ++p) + for (const auto& propertySet : propertySets) { - if (!_propertySets.insert(*p).second) + if (!_propertySets.insert(propertySet).second) { - exception("property set with id '" + p->first + "' is already defined at this scope"); + exception("property set with id '" + propertySet.first + "' is already defined at this scope"); } } _propertySets.insert(oldPropertySets.begin(), oldPropertySets.end()); @@ -718,16 +719,16 @@ Resolver::addPropertySets(const PropertySetDescriptorDict& propertySets) // // Validate the new property set references. // - for (PropertySetDescriptorDict::const_iterator p = propertySets.begin(); p != propertySets.end(); ++p) + for (const auto& propertySet : propertySets) { - [[maybe_unused]] auto _ = getProperties(p->second.references); + [[maybe_unused]] auto _ = getProperties(propertySet.second.references); } } const PropertySetDescriptor& Resolver::getPropertySet(const string& id) const { - PropertySetDescriptorDict::const_iterator p = _propertySets.find(id); + auto p = _propertySets.find(id); if (p == _propertySets.end()) { exception("invalid reference to property set, property set '" + id + "' doesn't exist"); @@ -784,7 +785,7 @@ TemplateDescriptor Resolver::getServerTemplate(const string& tmpl) const { assert(_application); - TemplateDescriptorDict::const_iterator p = _application->serverTemplates.find(tmpl); + auto p = _application->serverTemplates.find(tmpl); if (p == _application->serverTemplates.end()) { throw DeploymentException("unknown server template '" + tmpl + "'"); @@ -796,7 +797,7 @@ TemplateDescriptor Resolver::getServiceTemplate(const string& tmpl) const { assert(_application); - TemplateDescriptorDict::const_iterator p = _application->serviceTemplates.find(tmpl); + auto p = _application->serviceTemplates.find(tmpl); if (p == _application->serviceTemplates.end()) { throw DeploymentException("unknown service template '" + tmpl + "'"); @@ -819,11 +820,9 @@ Resolver::hasReplicaGroup(const string& id) const return true; } - for (ReplicaGroupDescriptorSeq::const_iterator p = _application->replicaGroups.begin(); - p != _application->replicaGroups.end(); - ++p) + for (const auto& replicaGroup : _application->replicaGroups) { - if (p->id == id) + if (replicaGroup.id == id) { return true; } @@ -913,7 +912,7 @@ Resolver::getVariable(const string& name, bool checkParams, bool& param) const // necessary and finally the variables. // param = false; - map::const_iterator p = _reserved.find(name); + auto p = _reserved.find(name); if (p != _reserved.end()) { checkDeprecated(name); @@ -944,17 +943,17 @@ PropertyDescriptorSeq Resolver::getProperties(const Ice::StringSeq& references, set& resolved) const { PropertyDescriptorSeq properties; - for (Ice::StringSeq::const_iterator p = references.begin(); p != references.end(); ++p) + for (const auto& reference : references) { - if (resolved.find(*p) != resolved.end()) + if (resolved.find(reference) != resolved.end()) { - exception("detected circular dependency with property reference '" + *p + "'"); + exception("detected circular dependency with property reference '" + reference + "'"); } - PropertySetDescriptor desc = getPropertySet(*p); + PropertySetDescriptor desc = getPropertySet(reference); if (!desc.references.empty()) { - resolved.insert(*p); + resolved.insert(reference); PropertyDescriptorSeq q = getProperties(desc.references, resolved); properties.insert(properties.end(), q.begin(), q.end()); } @@ -992,11 +991,11 @@ Resolver::getReserved() void Resolver::checkReserved(const string& type, const map& values) const { - for (map::const_iterator p = values.begin(); p != values.end(); ++p) + for (const auto& value : values) { - if (_reserved.find(p->first) != _reserved.end()) + if (_reserved.find(value.first) != _reserved.end()) { - exception("invalid " + type + " '" + p->first + "': reserved variable name"); + exception("invalid " + type + " '" + value.first + "': reserved variable name"); } } } @@ -1009,7 +1008,7 @@ Resolver::checkDeprecated(const string& name) const return; } - map::const_iterator q = _deprecated.find(name); + auto q = _deprecated.find(name); if (q != _deprecated.end()) { Ice::Warning out(_communicator->getLogger()); @@ -1070,28 +1069,28 @@ CommunicatorHelper::operator!=(const CommunicatorHelper& helper) const void CommunicatorHelper::getIds(multiset& adapterIds, multiset& objectIds) const { - for (AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p) + for (const auto& adapter : _desc->adapters) { - if (!p->id.empty()) + if (!adapter.id.empty()) { - adapterIds.insert(p->id); + adapterIds.insert(adapter.id); } set ids; - for (ObjectDescriptorSeq::const_iterator q = p->objects.begin(); q != p->objects.end(); ++q) + for (const auto& object : adapter.objects) { - ids.insert(q->id); - objectIds.insert(q->id); + ids.insert(object.id); + objectIds.insert(object.id); } - for (ObjectDescriptorSeq::const_iterator q = p->allocatables.begin(); q != p->allocatables.end(); ++q) + for (const auto& allocatable : adapter.allocatables) { - if (ids.find(q->id) == ids.end()) + if (ids.find(allocatable.id) == ids.end()) { - objectIds.insert(q->id); + objectIds.insert(allocatable.id); } else { - ids.erase(q->id); + ids.erase(allocatable.id); } } } @@ -1100,11 +1099,11 @@ CommunicatorHelper::getIds(multiset& adapterIds, multiset void CommunicatorHelper::getReplicaGroups(set& replicaGroups) const { - for (AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p) + for (const auto& adapter : _desc->adapters) { - if (!p->replicaGroupId.empty()) + if (!adapter.replicaGroupId.empty()) { - replicaGroups.insert(p->replicaGroupId); + replicaGroups.insert(adapter.replicaGroupId); } } } @@ -1115,7 +1114,7 @@ CommunicatorHelper::instantiateImpl(const shared_ptr& in instance->description = resolve(_desc->description, "description"); instance->propertySet = resolve(_desc->propertySet); - for (AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p) + for (auto p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p) { AdapterDescriptor adapter; adapter.name = resolve(p->name, "object adapter name", false); @@ -1167,7 +1166,7 @@ CommunicatorHelper::instantiateImpl(const shared_ptr& in } } - for (Ice::StringSeq::const_iterator l = _desc->logs.begin(); l != _desc->logs.end(); ++l) + for (auto l = _desc->logs.begin(); l != _desc->logs.end(); ++l) { instance->logs.push_back(resolve(*l, "log path", false)); } @@ -1185,17 +1184,17 @@ CommunicatorHelper::print(const shared_ptr& communicator, Out } set hiddenProperties; { - for (AdapterDescriptorSeq::const_iterator p = _desc->adapters.begin(); p != _desc->adapters.end(); ++p) + for (const auto& adapter : _desc->adapters) { - hiddenProperties.insert(p->name + ".Endpoints"); - hiddenProperties.insert(p->name + ".ProxyOptions"); - printObjectAdapter(communicator, out, *p); + hiddenProperties.insert(adapter.name + ".Endpoints"); + hiddenProperties.insert(adapter.name + ".ProxyOptions"); + printObjectAdapter(communicator, out, adapter); } } { - for (Ice::StringSeq::const_iterator p = _desc->logs.begin(); p != _desc->logs.end(); ++p) + for (const auto& log : _desc->logs) { - out << nl << "log '" << *p << "'"; + out << nl << "log '" << log << "'"; } } if (!_desc->propertySet.properties.empty() || !_desc->propertySet.references.empty()) @@ -1207,13 +1206,11 @@ CommunicatorHelper::print(const shared_ptr& communicator, Out out << nl << "references = " << toString(_desc->propertySet.references); } - for (PropertyDescriptorSeq::const_iterator q = _desc->propertySet.properties.begin(); - q != _desc->propertySet.properties.end(); - ++q) + for (const auto& prop : _desc->propertySet.properties) { - if (hiddenProperties.find(q->name) == hiddenProperties.end()) + if (hiddenProperties.find(prop.name) == hiddenProperties.end()) { - out << nl << q->name << " = '" << q->value << "'"; + out << nl << prop.name << " = '" << prop.value << "'"; } } out << eb; @@ -1253,33 +1250,33 @@ CommunicatorHelper::printObjectAdapter( } out << nl << "register process = '" << (adapter.registerProcess ? "true" : "false") << "'"; out << nl << "server lifetime = '" << (adapter.serverLifetime ? "true" : "false") << "'"; - for (ObjectDescriptorSeq::const_iterator p = adapter.objects.begin(); p != adapter.objects.end(); ++p) + for (const auto& object : adapter.objects) { out << nl << "well-known object"; out << sb; - out << nl << "identity = '" << communicator->identityToString(p->id) << "' "; - if (!p->type.empty()) + out << nl << "identity = '" << communicator->identityToString(object.id) << "' "; + if (!object.type.empty()) { - out << nl << "type = '" << p->type << "'"; + out << nl << "type = '" << object.type << "'"; } - if (!p->proxyOptions.empty()) + if (!object.proxyOptions.empty()) { - out << nl << "proxy options = '" << p->proxyOptions << "'"; + out << nl << "proxy options = '" << object.proxyOptions << "'"; } out << eb; } - for (ObjectDescriptorSeq::const_iterator p = adapter.allocatables.begin(); p != adapter.allocatables.end(); ++p) + for (const auto& allocatable : adapter.allocatables) { out << nl << "allocatable"; out << sb; - out << nl << "identity = '" << communicator->identityToString(p->id) << "' "; - if (!p->type.empty()) + out << nl << "identity = '" << communicator->identityToString(allocatable.id) << "' "; + if (!allocatable.type.empty()) { - out << nl << "type = '" << p->type << "'"; + out << nl << "type = '" << allocatable.type << "'"; } - if (!p->proxyOptions.empty()) + if (!allocatable.proxyOptions.empty()) { - out << nl << "proxy options = '" << p->proxyOptions << "'"; + out << nl << "proxy options = '" << allocatable.proxyOptions << "'"; } out << eb; } @@ -1305,7 +1302,7 @@ ServiceHelper::ServiceHelper(const shared_ptr& descriptor, bo bool ServiceHelper::operator==(const CommunicatorHelper& h) const { - const ServiceHelper* helper = dynamic_cast(&h); + const auto* helper = dynamic_cast(&h); if (!helper || !CommunicatorHelper::operator==(h)) { return false; @@ -1352,7 +1349,7 @@ ServiceHelper::instantiateImpl( instance->name = resolve(_desc->name, "name", false); instance->entry = resolve(_desc->entry, "entry", false); instance->propertySet.properties.insert(instance->propertySet.properties.end(), props.begin(), props.end()); - PropertySetDescriptorDict::const_iterator p = serviceProps.find(instance->name); + auto p = serviceProps.find(instance->name); if (p != serviceProps.end()) { instance->propertySet.properties.insert( @@ -1381,7 +1378,7 @@ ServerHelper::ServerHelper(const shared_ptr& descriptor, bool bool ServerHelper::operator==(const CommunicatorHelper& h) const { - const ServerHelper* helper = dynamic_cast(&h); + const auto* helper = dynamic_cast(&h); if (!helper || !CommunicatorHelper::operator==(h)) { return false; @@ -1567,16 +1564,16 @@ IceBoxHelper::IceBoxHelper(const shared_ptr& descriptor, bool : ServerHelper(descriptor, ignoreProps), _desc(descriptor) { - for (ServiceInstanceDescriptorSeq::const_iterator p = _desc->services.begin(); p != _desc->services.end(); ++p) + for (const auto& service : _desc->services) { - _services.push_back(ServiceInstanceHelper(*p, ignoreProps)); + _services.emplace_back(service, ignoreProps); } } bool IceBoxHelper::operator==(const CommunicatorHelper& h) const { - const IceBoxHelper* helper = dynamic_cast(&h); + const auto* helper = dynamic_cast(&h); if (!helper || !ServerHelper::operator==(h)) { return false; @@ -1605,9 +1602,9 @@ void IceBoxHelper::getIds(multiset& adapterIds, multiset& objectIds) const { CommunicatorHelper::getIds(adapterIds, objectIds); - for (vector::const_iterator p = _services.begin(); p != _services.end(); ++p) + for (const auto& service : _services) { - p->getIds(adapterIds, objectIds); + service.getIds(adapterIds, objectIds); } } @@ -1615,9 +1612,9 @@ void IceBoxHelper::getReplicaGroups(set& replicaGroups) const { CommunicatorHelper::getReplicaGroups(replicaGroups); - for (vector::const_iterator p = _services.begin(); p != _services.end(); ++p) + for (const auto& service : _services) { - p->getReplicaGroups(replicaGroups); + service.getReplicaGroups(replicaGroups); } } @@ -1636,7 +1633,7 @@ IceBoxHelper::print(const shared_ptr& communicator, Output& o printImpl(communicator, out, info); out << nl << "services"; out << sb; - for (ServiceInstanceDescriptorSeq::const_iterator p = _desc->services.begin(); p != _desc->services.end(); ++p) + for (auto p = _desc->services.begin(); p != _desc->services.end(); ++p) { assert(p->descriptor); out << nl << p->descriptor->name; @@ -1654,18 +1651,18 @@ IceBoxHelper::instantiateImpl( { ServerHelper::instantiateImpl(instance, resolver, props); set serviceNames; - for (vector::const_iterator p = _services.begin(); p != _services.end(); ++p) + for (const auto& service : _services) { - ServiceInstanceDescriptor desc = p->instantiate(resolver, serviceProps); + ServiceInstanceDescriptor desc = service.instantiate(resolver, serviceProps); assert(desc.descriptor); serviceNames.insert(desc.descriptor->name); instance->services.push_back(desc); } - for (PropertySetDescriptorDict::const_iterator q = serviceProps.begin(); q != serviceProps.end(); ++q) + for (const auto& serviceProp : serviceProps) { - if (serviceNames.find(q->first) == serviceNames.end()) + if (serviceNames.find(serviceProp.first) == serviceNames.end()) { - resolver.exception("invalid service property set: service '" + q->first + "' doesn't exist"); + resolver.exception("invalid service property set: service '" + serviceProp.first + "' doesn't exist"); } } } @@ -1682,13 +1679,13 @@ InstanceHelper::instantiateParams( set required(requiredParameters.begin(), requiredParameters.end()); set unknown; - for (map::const_iterator p = parameters.begin(); p != parameters.end(); ++p) + for (const auto& parameter : parameters) { - if (required.find(p->first) == required.end()) + if (required.find(parameter.first) == required.end()) { - unknown.insert(p->first); + unknown.insert(parameter.first); } - params.insert(make_pair(p->first, resolve(p->second, "parameter '" + p->first + "'"))); + params.insert(make_pair(parameter.first, resolve(parameter.second, "parameter '" + parameter.first + "'"))); } if (!unknown.empty()) { @@ -1699,14 +1696,14 @@ InstanceHelper::instantiateParams( } set missingParams; - for (set::const_iterator q = required.begin(); q != required.end(); ++q) + for (const auto& q : required) { - if (params.find(*q) == params.end()) + if (params.find(q) == params.end()) { - map::const_iterator r = defaults.find(*q); + auto r = defaults.find(q); if (r == defaults.end()) { - missingParams.insert(*q); + missingParams.insert(q); } else { @@ -1834,9 +1831,9 @@ ServiceInstanceHelper::print(const shared_ptr& communicator, out << nl << "template = '" << _def._cpp_template << "'"; out << nl << "parameters"; out << sb; - for (StringStringDict::const_iterator p = _def.parameterValues.begin(); p != _def.parameterValues.end(); ++p) + for (const auto& parameterValue : _def.parameterValues) { - out << nl << p->first << " = '" << p->second << "'"; + out << nl << parameterValue.first << " = '" << parameterValue.second << "'"; } out << eb; out << eb; @@ -1924,11 +1921,10 @@ ServerInstanceHelper::init(const shared_ptr& definition, const _instance._cpp_template = _def._cpp_template; _instance.parameterValues = parameterValues; _instance.propertySet = svrResolve(_def.propertySet); - for (PropertySetDescriptorDict::const_iterator p = _def.servicePropertySets.begin(); - p != _def.servicePropertySets.end(); - ++p) + for (const auto& servicePropertySet : _def.servicePropertySets) { - _instance.servicePropertySets.insert(make_pair(svrResolve(p->first), svrResolve(p->second))); + _instance.servicePropertySets.insert( + make_pair(svrResolve(servicePropertySet.first), svrResolve(servicePropertySet.second))); } } @@ -2041,10 +2037,9 @@ NodeHelper::NodeHelper(string name, NodeDescriptor descriptor, const Resolver& a resolve.addPropertySets(_instance.propertySets); } - for (ServerInstanceDescriptorSeq::const_iterator p = _def.serverInstances.begin(); p != _def.serverInstances.end(); - ++p) + for (const auto& serverInstance : _def.serverInstances) { - ServerInstanceHelper helper(*p, resolve, instantiate); + ServerInstanceHelper helper(serverInstance, resolve, instantiate); if (!_serverInstances.insert(make_pair(helper.getId(), helper)).second) { resolve.exception("duplicate server '" + helper.getId() + "' in node '" + _name + "'"); @@ -2055,9 +2050,9 @@ NodeHelper::NodeHelper(string name, NodeDescriptor descriptor, const Resolver& a } } - for (ServerDescriptorSeq::const_iterator q = _def.servers.begin(); q != _def.servers.end(); ++q) + for (const auto& server : _def.servers) { - ServerInstanceHelper helper(*q, resolve, instantiate); + ServerInstanceHelper helper(server, resolve, instantiate); if (!_servers.insert(make_pair(helper.getId(), helper)).second) { resolve.exception("duplicate server '" + helper.getId() + "' in node '" + _name + "'"); @@ -2136,16 +2131,16 @@ NodeHelper::diff(const NodeHelper& helper) const update.removePropertySets = getDictRemovedElts(helper._def.propertySets, _def.propertySets); ServerInstanceHelperDict updated = getDictUpdatedElts(helper._serverInstances, _serverInstances); - for (ServerInstanceHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - update.serverInstances.push_back(p->second.getDefinition()); + update.serverInstances.push_back(p.second.getDefinition()); } update.removeServers = getDictRemovedElts(helper._serverInstances, _serverInstances); updated = getDictUpdatedElts(helper._servers, _servers); - for (ServerInstanceHelperDict::const_iterator q = updated.begin(); q != updated.end(); ++q) + for (const auto& q : updated) { - update.servers.push_back(q->second.getServerDefinition()); + update.servers.push_back(q.second.getServerDefinition()); } Ice::StringSeq removed = getDictRemovedElts(helper._servers, _servers); update.removeServers.insert(update.removeServers.end(), removed.begin(), removed.end()); @@ -2184,20 +2179,18 @@ NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolv set added; set removed(update.removeServers.begin(), update.removeServers.end()); - for (ServerInstanceDescriptorSeq::const_iterator q = update.serverInstances.begin(); - q != update.serverInstances.end(); - ++q) + for (const auto& serverInstance : update.serverInstances) { - ServerInstanceHelper helper(*q, resolve, false); + ServerInstanceHelper helper(serverInstance, resolve, false); if (!added.insert(helper.getId()).second) { resolve.exception("duplicate server '" + helper.getId() + "' in node '" + _name + "'"); } def.serverInstances.push_back(helper.getDefinition()); } - for (ServerInstanceHelperDict::const_iterator r = _serverInstances.begin(); r != _serverInstances.end(); ++r) + for (const auto& serverInstance : _serverInstances) { - if (removed.find(r->first) != removed.end() || added.find(r->first) != added.end()) + if (removed.find(serverInstance.first) != removed.end() || added.find(serverInstance.first) != added.end()) { continue; } @@ -2207,29 +2200,29 @@ NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolv // change, if the ID of a server changes the update descriptor // has to remove the server and add an update entry for it. // - ServerInstanceHelper helper(r->second.getDefinition(), resolve, false); - if (helper.getId() != r->first) + ServerInstanceHelper helper(serverInstance.second.getDefinition(), resolve, false); + if (helper.getId() != serverInstance.first) { resolve.exception( - "invalid update in node '" + _name + "':\n" + "server instance id '" + r->first + "' changed to '" + - helper.getId() + "'"); + "invalid update in node '" + _name + "':\n" + "server instance id '" + serverInstance.first + + "' changed to '" + helper.getId() + "'"); } def.serverInstances.push_back(helper.getDefinition()); } added.clear(); - for (ServerDescriptorSeq::const_iterator s = update.servers.begin(); s != update.servers.end(); ++s) + for (const auto& server : update.servers) { - ServerInstanceHelper helper(*s, resolve, false); + ServerInstanceHelper helper(server, resolve, false); if (!added.insert(helper.getId()).second) { resolve.exception("duplicate server '" + helper.getId() + "' in node '" + _name + "'"); } def.servers.push_back(helper.getServerDefinition()); } - for (ServerInstanceHelperDict::const_iterator r = _servers.begin(); r != _servers.end(); ++r) + for (const auto& server : _servers) { - if (removed.find(r->first) != removed.end() || added.find(r->first) != added.end()) + if (removed.find(server.first) != removed.end() || added.find(server.first) != added.end()) { continue; } @@ -2239,11 +2232,11 @@ NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolv // change, if the ID of a server changes the update descriptor // has to remove the server and add an update entry for it. // - ServerInstanceHelper helper(r->second.getServerDefinition(), resolve, false); - if (helper.getId() != r->first) + ServerInstanceHelper helper(server.second.getServerDefinition(), resolve, false); + if (helper.getId() != server.first) { resolve.exception( - "invalid update in node '" + _name + "':\nserver instance id '" + r->first + "' changed to '" + + "invalid update in node '" + _name + "':\nserver instance id '" + server.first + "' changed to '" + helper.getId() + "'"); } def.servers.push_back(helper.getServerDefinition()); @@ -2255,15 +2248,15 @@ void NodeHelper::getIds(multiset& serverIds, multiset& adapterIds, multiset& objectIds) const { assert(_instantiated); - for (ServerInstanceHelperDict::const_iterator p = _serverInstances.begin(); p != _serverInstances.end(); ++p) + for (const auto& serverInstance : _serverInstances) { - serverIds.insert(p->first); - p->second.getIds(adapterIds, objectIds); + serverIds.insert(serverInstance.first); + serverInstance.second.getIds(adapterIds, objectIds); } - for (ServerInstanceHelperDict::const_iterator p = _servers.begin(); p != _servers.end(); ++p) + for (const auto& server : _servers) { - serverIds.insert(p->first); - p->second.getIds(adapterIds, objectIds); + serverIds.insert(server.first); + server.second.getIds(adapterIds, objectIds); } } @@ -2271,13 +2264,13 @@ void NodeHelper::getReplicaGroups(set& replicaGroups) const { assert(_instantiated); - for (ServerInstanceHelperDict::const_iterator p = _serverInstances.begin(); p != _serverInstances.end(); ++p) + for (const auto& serverInstance : _serverInstances) { - p->second.getReplicaGroups(replicaGroups); + serverInstance.second.getReplicaGroups(replicaGroups); } - for (ServerInstanceHelperDict::const_iterator p = _servers.begin(); p != _servers.end(); ++p) + for (const auto& server : _servers) { - p->second.getReplicaGroups(replicaGroups); + server.second.getReplicaGroups(replicaGroups); } } @@ -2298,25 +2291,25 @@ void NodeHelper::getServerInfos(const string& app, const string& uuid, int revision, map& servers) const { assert(_instantiated); - for (ServerInstanceHelperDict::const_iterator p = _serverInstances.begin(); p != _serverInstances.end(); ++p) + for (const auto& serverInstance : _serverInstances) { ServerInfo info; info.node = _name; info.application = app; info.uuid = uuid; info.revision = revision; - info.descriptor = p->second.getServerInstance(); - servers.insert(make_pair(p->second.getId(), info)); + info.descriptor = serverInstance.second.getServerInstance(); + servers.insert(make_pair(serverInstance.second.getId(), info)); } - for (ServerInstanceHelperDict::const_iterator p = _servers.begin(); p != _servers.end(); ++p) + for (const auto& server : _servers) { ServerInfo info; info.node = _name; info.application = app; info.uuid = uuid; info.revision = revision; - info.descriptor = p->second.getServerInstance(); - servers.insert(make_pair(p->second.getId(), info)); + info.descriptor = server.second.getServerInstance(); + servers.insert(make_pair(server.second.getId(), info)); } } @@ -2351,26 +2344,24 @@ NodeHelper::print(Output& out) const { out << nl << "variables"; out << sb; - for (StringStringDict::const_iterator q = _instance.variables.begin(); q != _instance.variables.end(); ++q) + for (const auto& variable : _instance.variables) { - out << nl << q->first << " = '" << q->second << "'"; + out << nl << variable.first << " = '" << variable.second << "'"; } out << eb; } if (!_instance.propertySets.empty()) { - for (PropertySetDescriptorDict::const_iterator q = _instance.propertySets.begin(); - q != _instance.propertySets.end(); - ++q) + for (const auto& propertySet : _instance.propertySets) { - out << nl << "properties '" << q->first << "'"; + out << nl << "properties '" << propertySet.first << "'"; out << sb; - if (!q->second.references.empty()) + if (!propertySet.second.references.empty()) { - out << nl << "references = " << toString(q->second.references); + out << nl << "references = " << toString(propertySet.second.references); } PropertyDescriptorSeq::const_iterator r; - for (r = q->second.properties.begin(); r != q->second.properties.end(); ++r) + for (r = propertySet.second.properties.begin(); r != propertySet.second.properties.end(); ++r) { out << nl << r->name << " = '" << r->value << "'"; } @@ -2386,13 +2377,13 @@ NodeHelper::print(Output& out) const out << nl << "servers"; out << sb; - for (ServerInstanceHelperDict::const_iterator p = _serverInstances.begin(); p != _serverInstances.end(); ++p) + for (const auto& serverInstance : _serverInstances) { - out << nl << p->first; + out << nl << serverInstance.first; } - for (ServerInstanceHelperDict::const_iterator p = _servers.begin(); p != _servers.end(); ++p) + for (const auto& server : _servers) { - out << nl << p->first; + out << nl << server.first; } out << eb; out << eb; @@ -2454,25 +2445,25 @@ NodeHelper::printDiff(Output& out, const NodeHelper& helper) const { out << nl << "servers"; out << sb; - for (ServerInstanceHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - if (helper._serverInstances.find(p->first) == helper._serverInstances.end() && - helper._servers.find(p->first) == helper._servers.end()) + if (helper._serverInstances.find(p.first) == helper._serverInstances.end() && + helper._servers.find(p.first) == helper._servers.end()) { - out << nl << "server '" << p->first << "' added"; + out << nl << "server '" << p.first << "' added"; } } - for (ServerInstanceHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - if (helper._serverInstances.find(p->first) != helper._serverInstances.end() || - helper._servers.find(p->first) != helper._servers.end()) + if (helper._serverInstances.find(p.first) != helper._serverInstances.end() || + helper._servers.find(p.first) != helper._servers.end()) { - out << nl << "server '" << p->first << "' updated"; + out << nl << "server '" << p.first << "' updated"; } } - for (Ice::StringSeq::const_iterator q = removed.begin(); q != removed.end(); ++q) + for (const auto& q : removed) { - out << nl << "server '" << *q << "' removed"; + out << nl << "server '" << q << "' removed"; } out << eb; } @@ -2506,22 +2497,22 @@ ApplicationHelper::ApplicationHelper( _instance.description = resolve(_def.description, "description"); _instance.propertySets = resolve(_def.propertySets); - for (ReplicaGroupDescriptorSeq::iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r) + for (const auto& replicaGroup : _def.replicaGroups) { ReplicaGroupDescriptor desc; - desc.id = resolve.asId(r->id, "replica group id", false); - desc.description = resolve(r->description, "replica group description"); - desc.proxyOptions = resolve(r->proxyOptions, "replica group proxy options"); + desc.id = resolve.asId(replicaGroup.id, "replica group id", false); + desc.description = resolve(replicaGroup.description, "replica group description"); + desc.proxyOptions = resolve(replicaGroup.proxyOptions, "replica group proxy options"); validateProxyOptions(resolve, desc.proxyOptions); - desc.filter = resolve(r->filter, "replica group filter"); - desc.objects = resolve(r->objects, r->proxyOptions, "replica group well-known"); - if (!r->loadBalancing) + desc.filter = resolve(replicaGroup.filter, "replica group filter"); + desc.objects = resolve(replicaGroup.objects, replicaGroup.proxyOptions, "replica group well-known"); + if (!replicaGroup.loadBalancing) { resolve.exception("replica group load balancing is not set"); } - desc.loadBalancing = dynamic_pointer_cast(r->loadBalancing->ice_clone()); + desc.loadBalancing = dynamic_pointer_cast(replicaGroup.loadBalancing->ice_clone()); desc.loadBalancing->nReplicas = - resolve.asInt(r->loadBalancing->nReplicas, "replica group number of replicas"); + resolve.asInt(replicaGroup.loadBalancing->nReplicas, "replica group number of replicas"); if (desc.loadBalancing->nReplicas.empty()) { resolve.exception("invalid replica group load balancing number of replicas value: empty value"); @@ -2554,9 +2545,9 @@ ApplicationHelper::ApplicationHelper( // Create the node helpers. // NodeHelperDict::const_iterator n; - for (NodeDescriptorDict::const_iterator p = _def.nodes.begin(); p != _def.nodes.end(); ++p) + for (const auto& node : _def.nodes) { - n = _nodes.insert(make_pair(p->first, NodeHelper(p->first, p->second, resolve, instantiate))).first; + n = _nodes.insert(make_pair(node.first, NodeHelper(node.first, node.second, resolve, instantiate))).first; if (instantiate) { _instance.nodes.insert(make_pair(n->first, n->second.getInstance())); @@ -2577,38 +2568,38 @@ ApplicationHelper::ApplicationHelper( n->second.getIds(serverIds, adapterIds, objectIds); } - for (ReplicaGroupDescriptorSeq::iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r) + for (const auto& replicaGroup : _def.replicaGroups) { - if (r->id.empty()) + if (replicaGroup.id.empty()) { throw DeploymentException("replica group id is empty"); } - if (adapterIds.find(r->id) != adapterIds.end()) + if (adapterIds.find(replicaGroup.id) != adapterIds.end()) { - throw DeploymentException("duplicate replica group '" + r->id + "'"); + throw DeploymentException("duplicate replica group '" + replicaGroup.id + "'"); } - adapterIds.insert(r->id); - for (ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o) + adapterIds.insert(replicaGroup.id); + for (const auto& object : replicaGroup.objects) { - objectIds.insert(o->id); + objectIds.insert(object.id); } } - for (multiset::const_iterator s = serverIds.begin(); s != serverIds.end(); ++s) + for (auto s = serverIds.begin(); s != serverIds.end(); ++s) { if (serverIds.count(*s) > 1) { resolve.exception("duplicate server '" + *s + "'"); } } - for (multiset::const_iterator a = adapterIds.begin(); a != adapterIds.end(); ++a) + for (auto a = adapterIds.begin(); a != adapterIds.end(); ++a) { if (adapterIds.count(*a) > 1) { resolve.exception("duplicate adapter '" + *a + "'"); } } - for (multiset::const_iterator o = objectIds.begin(); o != objectIds.end(); ++o) + for (auto o = objectIds.begin(); o != objectIds.end(); ++o) { if (objectIds.count(*o) > 1) { @@ -2648,14 +2639,14 @@ ApplicationHelper::diff(const ApplicationHelper& helper) const updt.removeServiceTemplates = getDictRemovedElts(helper._def.serviceTemplates, _def.serviceTemplates); NodeHelperDict updated = getDictUpdatedElts(helper._nodes, _nodes); - for (NodeHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - NodeHelperDict::const_iterator q = helper._nodes.find(p->first); + auto q = helper._nodes.find(p.first); if (q == helper._nodes.end()) { NodeUpdateDescriptor nodeUpdate; - const NodeDescriptor& node = p->second.getDefinition(); - nodeUpdate.name = p->first; + const NodeDescriptor& node = p.second.getDefinition(); + nodeUpdate.name = p.first; nodeUpdate.variables = node.variables; nodeUpdate.servers = node.servers; nodeUpdate.serverInstances = node.serverInstances; @@ -2665,7 +2656,7 @@ ApplicationHelper::diff(const ApplicationHelper& helper) const } else { - updt.nodes.push_back(p->second.diff(q->second)); + updt.nodes.push_back(p.second.diff(q->second)); } } updt.removeNodes = getDictRemovedElts(helper._nodes, _nodes); @@ -2688,46 +2679,46 @@ ApplicationHelper::update(const ApplicationUpdateDescriptor& updt) const def.serviceTemplates = updateDictElts(_def.serviceTemplates, updt.serviceTemplates, updt.removeServiceTemplates); Resolver resolve(def, _communicator, false); // A resolver based on the *updated* application descriptor. - for (NodeUpdateDescriptorSeq::const_iterator p = updt.nodes.begin(); p != updt.nodes.end(); ++p) + for (const auto& node : updt.nodes) { - NodeHelperDict::const_iterator q = _nodes.find(p->name); + auto q = _nodes.find(node.name); if (q != _nodes.end()) // Updated node { - NodeDescriptor desc = q->second.update(*p, resolve); - def.nodes.insert(make_pair(p->name, q->second.update(*p, resolve))); + NodeDescriptor desc = q->second.update(node, resolve); + def.nodes.insert(make_pair(node.name, q->second.update(node, resolve))); } else // New node { NodeDescriptor desc; - desc.variables = p->variables; - if (!p->removeVariables.empty()) + desc.variables = node.variables; + if (!node.removeVariables.empty()) { - resolve.exception("can't remove variables for node '" + p->name + "': node doesn't exist"); + resolve.exception("can't remove variables for node '" + node.name + "': node doesn't exist"); } - desc.propertySets = p->propertySets; - if (!p->removePropertySets.empty()) + desc.propertySets = node.propertySets; + if (!node.removePropertySets.empty()) { - resolve.exception("can't remove property sets for node '" + p->name + "': node doesn't exist"); + resolve.exception("can't remove property sets for node '" + node.name + "': node doesn't exist"); } - desc.servers = p->servers; - desc.serverInstances = p->serverInstances; - if (!p->removeServers.empty()) + desc.servers = node.servers; + desc.serverInstances = node.serverInstances; + if (!node.removeServers.empty()) { - resolve.exception("can't remove servers for node '" + p->name + "': node doesn't exist"); + resolve.exception("can't remove servers for node '" + node.name + "': node doesn't exist"); } - desc.loadFactor = p->loadFactor ? p->loadFactor->value : string(""); - desc.description = p->description ? p->description->value : string(""); - def.nodes.insert(make_pair(p->name, desc)); + desc.loadFactor = node.loadFactor ? node.loadFactor->value : string(""); + desc.description = node.description ? node.description->value : string(""); + def.nodes.insert(make_pair(node.name, desc)); } } set removedNodes(updt.removeNodes.begin(), updt.removeNodes.end()); - for (NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) + for (const auto& node : _nodes) { - if (removedNodes.find(n->first) != removedNodes.end() || def.nodes.find(n->first) != def.nodes.end()) + if (removedNodes.find(node.first) != removedNodes.end() || def.nodes.find(node.first) != def.nodes.end()) { continue; // Node was removed or updated. } - def.nodes.insert(make_pair(n->first, n->second.getDefinition())); + def.nodes.insert(make_pair(node.first, node.second.getDefinition())); } return def; @@ -2743,7 +2734,7 @@ ApplicationHelper::instantiateServer(const string& node, const ServerInstanceDes // ensure it's valid. // ApplicationDescriptor def = _def; - NodeDescriptorDict::iterator q = def.nodes.find(node); + auto q = def.nodes.find(node); if (q == def.nodes.end()) { NodeDescriptor desc; @@ -2764,16 +2755,16 @@ ApplicationHelper::getIds(set& serverIds, set& adapterIds, set aIds; multiset oIds; - for (NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p) + for (const auto& node : _nodes) { - p->second.getIds(sIds, aIds, oIds); + node.second.getIds(sIds, aIds, oIds); } - for (ReplicaGroupDescriptorSeq::const_iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r) + for (const auto& replicaGroup : _def.replicaGroups) { - aIds.insert(r->id); - for (ObjectDescriptorSeq::const_iterator o = r->objects.begin(); o != r->objects.end(); ++o) + aIds.insert(replicaGroup.id); + for (const auto& object : replicaGroup.objects) { - oIds.insert(o->id); + oIds.insert(object.id); } } @@ -2785,15 +2776,15 @@ ApplicationHelper::getIds(set& serverIds, set& adapterIds, set& replicaGroups, set& adapterReplicaGroups) const { - for (ReplicaGroupDescriptorSeq::const_iterator r = _def.replicaGroups.begin(); r != _def.replicaGroups.end(); ++r) + for (const auto& replicaGroup : _def.replicaGroups) { - replicaGroups.insert(r->id); + replicaGroups.insert(replicaGroup.id); } set allAdapterReplicaGroups; - for (NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p) + for (const auto& node : _nodes) { - p->second.getReplicaGroups(allAdapterReplicaGroups); + node.second.getReplicaGroups(allAdapterReplicaGroups); } // @@ -2827,9 +2818,9 @@ ApplicationHelper::getServerInfos(const string& uuid, int revision) const assert(!_instance.name.empty()); map servers; - for (NodeHelperDict::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) + for (const auto& node : _nodes) { - n->second.getServerInfos(_def.name, uuid, revision, servers); + node.second.getServerInfos(_def.name, uuid, revision, servers); } return servers; } @@ -2858,29 +2849,25 @@ ApplicationHelper::print(Output& out, const ApplicationInfo& info) const { out << nl << "variables"; out << sb; - for (StringStringDict::const_iterator p = _instance.variables.begin(); p != _instance.variables.end(); ++p) + for (const auto& variable : _instance.variables) { - out << nl << p->first << " = '" << p->second << "'"; + out << nl << variable.first << " = '" << variable.second << "'"; } out << eb; } if (!_instance.propertySets.empty()) { - for (PropertySetDescriptorDict::const_iterator q = _instance.propertySets.begin(); - q != _instance.propertySets.end(); - ++q) + for (const auto& propertySet : _instance.propertySets) { - out << nl << "properties '" << q->first << "'"; + out << nl << "properties '" << propertySet.first << "'"; out << sb; - if (!q->second.references.empty()) + if (!propertySet.second.references.empty()) { - out << nl << "references = " << toString(q->second.references); + out << nl << "references = " << toString(propertySet.second.references); } - for (PropertyDescriptorSeq::const_iterator r = q->second.properties.begin(); - r != q->second.properties.end(); - ++r) + for (const auto& prop : propertySet.second.properties) { - out << nl << r->name << " = '" << r->value << "'"; + out << nl << prop.name << " = '" << prop.value << "'"; } out << eb; } @@ -2889,24 +2876,22 @@ ApplicationHelper::print(Output& out, const ApplicationInfo& info) const { out << nl << "replica groups"; out << sb; - for (ReplicaGroupDescriptorSeq::const_iterator p = _instance.replicaGroups.begin(); - p != _instance.replicaGroups.end(); - ++p) + for (const auto& replicaGroup : _instance.replicaGroups) { - out << nl << "id = '" << p->id << "' load balancing = '"; - if (!p->loadBalancing) + out << nl << "id = '" << replicaGroup.id << "' load balancing = '"; + if (!replicaGroup.loadBalancing) { out << "default (return all endpoints)"; } - else if (dynamic_pointer_cast(p->loadBalancing)) + else if (dynamic_pointer_cast(replicaGroup.loadBalancing)) { out << "random"; } - else if (dynamic_pointer_cast(p->loadBalancing)) + else if (dynamic_pointer_cast(replicaGroup.loadBalancing)) { out << "round-robin"; } - else if (dynamic_pointer_cast(p->loadBalancing)) + else if (dynamic_pointer_cast(replicaGroup.loadBalancing)) { out << "adaptive"; } @@ -2914,13 +2899,13 @@ ApplicationHelper::print(Output& out, const ApplicationInfo& info) const { out << ""; } - if (!p->proxyOptions.empty()) + if (!replicaGroup.proxyOptions.empty()) { - out << nl << "proxy options = '" << p->proxyOptions << "'"; + out << nl << "proxy options = '" << replicaGroup.proxyOptions << "'"; } - if (!p->filter.empty()) + if (!replicaGroup.filter.empty()) { - out << nl << "filter = '" << p->filter << "'"; + out << nl << "filter = '" << replicaGroup.filter << "'"; } out << "'"; } @@ -2930,11 +2915,9 @@ ApplicationHelper::print(Output& out, const ApplicationInfo& info) const { out << nl << "server templates"; out << sb; - for (TemplateDescriptorDict::const_iterator p = _instance.serverTemplates.begin(); - p != _instance.serverTemplates.end(); - ++p) + for (const auto& serverTemplate : _instance.serverTemplates) { - out << nl << p->first; + out << nl << serverTemplate.first; } out << eb; } @@ -2942,19 +2925,17 @@ ApplicationHelper::print(Output& out, const ApplicationInfo& info) const { out << nl << "service templates"; out << sb; - for (TemplateDescriptorDict::const_iterator p = _instance.serviceTemplates.begin(); - p != _instance.serviceTemplates.end(); - ++p) + for (const auto& serviceTemplate : _instance.serviceTemplates) { - out << nl << p->first; + out << nl << serviceTemplate.first; } out << eb; } if (!_nodes.empty()) { - for (NodeHelperDict::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p) + for (const auto& node : _nodes) { - p->second.print(out); + node.second.print(out); } } out << eb; @@ -2996,7 +2977,7 @@ ApplicationHelper::printDiff(Output& out, const ApplicationHelper& helper) const out << nl << "replica groups"; out << sb; - for (ReplicaGroupDescriptorSeq::iterator p = updated.begin(); p != updated.end();) + for (auto p = updated.begin(); p != updated.end();) { ReplicaGroupDescriptorSeq::const_iterator r; for (r = helper._def.replicaGroups.begin(); r != helper._def.replicaGroups.end(); ++r) @@ -3013,13 +2994,13 @@ ApplicationHelper::printDiff(Output& out, const ApplicationHelper& helper) const ++p; } } - for (ReplicaGroupDescriptorSeq::iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - out << nl << "replica group '" << p->id << "' added"; + out << nl << "replica group '" << p.id << "' added"; } - for (Ice::StringSeq::const_iterator q = removed.begin(); q != removed.end(); ++q) + for (const auto& q : removed) { - out << nl << "replica group '" << *q << "' removed"; + out << nl << "replica group '" << q << "' removed"; } out << eb; } @@ -3033,23 +3014,23 @@ ApplicationHelper::printDiff(Output& out, const ApplicationHelper& helper) const { out << nl << "server templates"; out << sb; - for (TemplateDescriptorDict::const_iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - if (helper._def.serverTemplates.find(p->first) == helper._def.serverTemplates.end()) + if (helper._def.serverTemplates.find(p.first) == helper._def.serverTemplates.end()) { - out << nl << "server template '" << p->first << "' added"; + out << nl << "server template '" << p.first << "' added"; } } - for (TemplateDescriptorDict::const_iterator q = updated.begin(); q != updated.end(); ++q) + for (const auto& q : updated) { - if (helper._def.serverTemplates.find(q->first) != helper._def.serverTemplates.end()) + if (helper._def.serverTemplates.find(q.first) != helper._def.serverTemplates.end()) { - out << nl << "server template '" << q->first << "' updated"; + out << nl << "server template '" << q.first << "' updated"; } } - for (Ice::StringSeq::const_iterator r = removed.begin(); r != removed.end(); ++r) + for (const auto& r : removed) { - out << nl << "server template '" << *r << "' removed"; + out << nl << "server template '" << r << "' removed"; } out << eb; } @@ -3063,23 +3044,23 @@ ApplicationHelper::printDiff(Output& out, const ApplicationHelper& helper) const { out << nl << "service templates"; out << sb; - for (TemplateDescriptorDict::const_iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - if (helper._def.serviceTemplates.find(p->first) == helper._def.serviceTemplates.end()) + if (helper._def.serviceTemplates.find(p.first) == helper._def.serviceTemplates.end()) { - out << nl << "service template '" << p->first << "' added"; + out << nl << "service template '" << p.first << "' added"; } } - for (TemplateDescriptorDict::const_iterator q = updated.begin(); q != updated.end(); ++q) + for (const auto& q : updated) { - if (helper._def.serviceTemplates.find(q->first) != helper._def.serviceTemplates.end()) + if (helper._def.serviceTemplates.find(q.first) != helper._def.serviceTemplates.end()) { - out << nl << "service template '" << q->first << "' updated"; + out << nl << "service template '" << q.first << "' updated"; } } - for (Ice::StringSeq::const_iterator r = removed.begin(); r != removed.end(); ++r) + for (const auto& r : removed) { - out << nl << "service template '" << *r << "' removed"; + out << nl << "service template '" << r << "' removed"; } out << eb; } @@ -3091,25 +3072,25 @@ ApplicationHelper::printDiff(Output& out, const ApplicationHelper& helper) const { out << nl << "nodes"; out << sb; - for (NodeHelperDict::const_iterator p = updated.begin(); p != updated.end(); ++p) + for (const auto& p : updated) { - NodeHelperDict::const_iterator q = helper._nodes.find(p->first); + auto q = helper._nodes.find(p.first); if (q == helper._nodes.end()) { - p->second.print(out); + p.second.print(out); } } - for (NodeHelperDict::const_iterator r = updated.begin(); r != updated.end(); ++r) + for (const auto& r : updated) { - NodeHelperDict::const_iterator q = helper._nodes.find(r->first); + auto q = helper._nodes.find(r.first); if (q != helper._nodes.end()) { - r->second.printDiff(out, q->second); + r.second.printDiff(out, q->second); } } - for (Ice::StringSeq::const_iterator s = removed.begin(); s != removed.end(); ++s) + for (const auto& s : removed) { - out << nl << "node '" << *s << "' removed"; + out << nl << "node '" << s << "' removed"; } out << eb; } diff --git a/cpp/src/IceGrid/DescriptorParser.cpp b/cpp/src/IceGrid/DescriptorParser.cpp index 894810926a7..7f23d989f18 100644 --- a/cpp/src/IceGrid/DescriptorParser.cpp +++ b/cpp/src/IceGrid/DescriptorParser.cpp @@ -724,9 +724,9 @@ namespace // // Go through the list of supplied targets and see if we can match one with the current communicator + target. // - for (vector::const_iterator p = _targets.begin(); p != _targets.end(); ++p) + for (const auto& p : _targets) { - if ((*p) == target) + if (p == target) { // // A supplied target without any communicator prefix is matching the target. @@ -754,7 +754,7 @@ namespace ++end; } - if ((*p) == communicatorTarget) + if (p == communicatorTarget) { return true; } diff --git a/cpp/src/IceGrid/FileCache.cpp b/cpp/src/IceGrid/FileCache.cpp index 19a9897fc03..6cc5cc276e9 100644 --- a/cpp/src/IceGrid/FileCache.cpp +++ b/cpp/src/IceGrid/FileCache.cpp @@ -79,7 +79,7 @@ FileCache::getOffsetFromEnd(const string& file, int originalCount) continue; } - lines.push_back(make_pair(beg, line)); + lines.emplace_back(beg, line); ++totalCount; if (lines.size() == static_cast(count + 1)) { @@ -177,7 +177,7 @@ FileCache::read(const string& file, int64_t offset, int size, int64_t& newOffset } else { - lines.push_back(""); + lines.emplace_back(""); } return false; // We didn't reach the end of file, we've just reached the size limit! } diff --git a/cpp/src/IceGrid/FileUserAccountMapperI.cpp b/cpp/src/IceGrid/FileUserAccountMapperI.cpp index 23308e3e633..8778351aeea 100644 --- a/cpp/src/IceGrid/FileUserAccountMapperI.cpp +++ b/cpp/src/IceGrid/FileUserAccountMapperI.cpp @@ -70,7 +70,7 @@ FileUserAccountMapperI::FileUserAccountMapperI(const string& filename) string FileUserAccountMapperI::getUserAccount(string user, const Ice::Current&) { - map::const_iterator p = _accounts.find(user); + auto p = _accounts.find(user); if (p == _accounts.end()) { throw UserAccountNotFoundException(); diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index 13caa505566..b76730cac00 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -230,7 +230,7 @@ NodeService::startImpl(int argc, char* argv[], int& status) while (i + 1 < argc && argv[++i][0] != '-') { - targets.push_back(argv[i]); + targets.emplace_back(argv[i]); } } else @@ -727,8 +727,8 @@ NodeService::initializeCommunicator(int& argc, char* argv[], const Initializatio // Glacier2CryptPermissionsVerifier plug-in // vector vTypes; - vTypes.push_back(""); - vTypes.push_back("Admin"); + vTypes.emplace_back(""); + vTypes.emplace_back("Admin"); for (const auto& type : vTypes) { diff --git a/cpp/src/IceGrid/IceGridRegistry.cpp b/cpp/src/IceGrid/IceGridRegistry.cpp index cf3b1f3206c..57637cddb02 100644 --- a/cpp/src/IceGrid/IceGridRegistry.cpp +++ b/cpp/src/IceGrid/IceGridRegistry.cpp @@ -148,16 +148,16 @@ RegistryService::initializeCommunicator(int& argc, char* argv[], const Initializ // Glacier2CryptPermissionsVerifier plug-in // vector vTypes; - vTypes.push_back(""); - vTypes.push_back("Admin"); + vTypes.emplace_back(""); + vTypes.emplace_back("Admin"); - for (vector::const_iterator p = vTypes.begin(); p != vTypes.end(); ++p) + for (const auto& vType : vTypes) { - string verifier = "IceGrid.Registry." + *p + "PermissionsVerifier"; + string verifier = "IceGrid.Registry." + vType + "PermissionsVerifier"; if (initData.properties->getProperty(verifier).empty()) { - string cryptPasswords = initData.properties->getIceProperty("IceGrid.Registry." + *p + "CryptPasswords"); + string cryptPasswords = initData.properties->getIceProperty("IceGrid.Registry." + vType + "CryptPasswords"); if (!cryptPasswords.empty()) { @@ -166,7 +166,7 @@ RegistryService::initializeCommunicator(int& argc, char* argv[], const Initializ "Glacier2CryptPermissionsVerifier:createCryptPermissionsVerifier"); initData.properties->setProperty( - "Glacier2CryptPermissionsVerifier.IceGrid.Registry." + *p + "PermissionsVerifier", + "Glacier2CryptPermissionsVerifier.IceGrid.Registry." + vType + "PermissionsVerifier", cryptPasswords); } } diff --git a/cpp/src/IceGrid/InternalRegistryI.cpp b/cpp/src/IceGrid/InternalRegistryI.cpp index 1fd0a4e94d0..1e9025f5856 100644 --- a/cpp/src/IceGrid/InternalRegistryI.cpp +++ b/cpp/src/IceGrid/InternalRegistryI.cpp @@ -137,7 +137,7 @@ InternalRegistryI::getNodes(const Ice::Current&) const for (const auto& proxy : _database->getInternalObjectsByType(string{Node::ice_staticId()})) { assert(proxy); - nodes.push_back(Ice::uncheckedCast(*proxy)); + nodes.emplace_back(Ice::uncheckedCast(*proxy)); } return nodes; } @@ -149,7 +149,7 @@ InternalRegistryI::getReplicas(const Ice::Current&) const for (const auto& proxy : _database->getObjectsByType(string{InternalRegistry::ice_staticId()})) { assert(proxy); - replicas.push_back(Ice::uncheckedCast(*proxy)); + replicas.emplace_back(Ice::uncheckedCast(*proxy)); } return replicas; } diff --git a/cpp/src/IceGrid/LocatorI.cpp b/cpp/src/IceGrid/LocatorI.cpp index bbecf35132f..43bfd19c57e 100644 --- a/cpp/src/IceGrid/LocatorI.cpp +++ b/cpp/src/IceGrid/LocatorI.cpp @@ -118,7 +118,7 @@ namespace LocatorAdapterInfoSeq adapters; { lock_guard lock(_mutex); - for (unsigned int i = static_cast(_proxies.size()); i < _count; ++i) + for (auto i = static_cast(_proxies.size()); i < _count; ++i) { if (_lastAdapter == _adapters.end()) { diff --git a/cpp/src/IceGrid/NodeCache.cpp b/cpp/src/IceGrid/NodeCache.cpp index 6fe6348c29f..4a1eb12dabc 100644 --- a/cpp/src/IceGrid/NodeCache.cpp +++ b/cpp/src/IceGrid/NodeCache.cpp @@ -20,7 +20,7 @@ namespace PropertyDescriptor removeProperty(PropertyDescriptorSeq& properties, const string& name) { string value; - PropertyDescriptorSeq::iterator p = properties.begin(); + auto p = properties.begin(); while (p != properties.end()) { if (p->name == name) @@ -52,7 +52,7 @@ NodeCache::get(const string& name, bool create) const auto cacheEntry = getImpl(name); if (!cacheEntry && create) { - NodeCache& self = const_cast(*this); + auto& self = const_cast(*this); cacheEntry = make_shared(self, name); self.addImpl(name, cacheEntry); } @@ -225,9 +225,9 @@ NodeEntry::getServers() const { lock_guard lock(_mutex); ServerEntrySeq entries; - for (map>::const_iterator p = _servers.begin(); p != _servers.end(); ++p) + for (const auto& server : _servers) { - entries.push_back(p->second); + entries.push_back(server.second); } return entries; } @@ -238,7 +238,7 @@ NodeEntry::getLoadInfoAndLoadFactor(const string& application, float& loadFactor unique_lock lock(_mutex); checkSession(lock); - map::const_iterator p = _descriptors.find(application); + auto p = _descriptors.find(application); if (p == _descriptors.end()) { throw NodeNotExistException(); // The node doesn't exist in the given application. @@ -926,12 +926,12 @@ NodeEntry::getInternalServerDescriptor(const ServerInfo& info) const // if (iceVersion == 0 || iceVersion >= 30300) { - for (PropertyDescriptorSeq::iterator p = serverProps.begin(); p != serverProps.end(); ++p) + for (auto& serverProp : serverProps) { - if (p->name.find('#') != 0 || !p->value.empty()) + if (serverProp.name.find('#') != 0 || !serverProp.value.empty()) { - p->name = escapeProperty(p->name, true); - p->value = escapeProperty(p->value); + serverProp.name = escapeProperty(serverProp.name, true); + serverProp.value = escapeProperty(serverProp.value); } } } diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp index 0a5fd5dc1ed..5feaa42e04f 100644 --- a/cpp/src/IceGrid/NodeI.cpp +++ b/cpp/src/IceGrid/NodeI.cpp @@ -88,11 +88,11 @@ NodeI::NodeI( vector overrides = props->getIcePropertyAsList("IceGrid.Node.PropertiesOverride"); if (!overrides.empty()) { - for (vector::iterator p = overrides.begin(); p != overrides.end(); ++p) + for (auto& override : overrides) { - if (p->find("--") != 0) + if (override.find("--") != 0) { - *p = "--" + *p; + override = "--" + override; } } @@ -714,13 +714,13 @@ NodeI::canRemoveServerDirectory(const string& name) contents.erase("revision"); contents.erase("data"); Ice::StringSeq serviceDataDirs; - for (set::const_iterator p = contents.begin(); p != contents.end(); ++p) + for (const auto& content : contents) { - if (p->find("data_") != 0) + if (content.find("data_") != 0) { return false; } - serviceDataDirs.push_back(*p); + serviceDataDirs.push_back(content); } if (!contents.empty()) { @@ -728,9 +728,9 @@ NodeI::canRemoveServerDirectory(const string& name) } c = readDirectory(_serversDir + "/" + name + "/config"); - for (Ice::StringSeq::const_iterator p = c.begin(); p != c.end(); ++p) + for (const auto& p : c) { - if (p->find("config") != 0) + if (p.find("config") != 0) { return false; } @@ -744,11 +744,11 @@ NodeI::canRemoveServerDirectory(const string& name) } } - for (Ice::StringSeq::const_iterator p = serviceDataDirs.begin(); p != serviceDataDirs.end(); ++p) + for (const auto& serviceDataDir : serviceDataDirs) { try { - if (!readDirectory(_serversDir + "/" + name + "/" + *p).empty()) + if (!readDirectory(_serversDir + "/" + name + "/" + serviceDataDir).empty()) { return false; } diff --git a/cpp/src/IceGrid/NodeSessionManager.cpp b/cpp/src/IceGrid/NodeSessionManager.cpp index 597c867a965..573bc494d21 100644 --- a/cpp/src/IceGrid/NodeSessionManager.cpp +++ b/cpp/src/IceGrid/NodeSessionManager.cpp @@ -641,7 +641,7 @@ NodeSessionManager::createdSession(const optional& session) for (const auto& prx : proxies) { - replicas.push_back(Ice::uncheckedCast(prx.second)); + replicas.emplace_back(Ice::uncheckedCast(prx.second)); } } diff --git a/cpp/src/IceGrid/ObjectCache.cpp b/cpp/src/IceGrid/ObjectCache.cpp index 3228d73c3f3..2e06e1652ac 100644 --- a/cpp/src/IceGrid/ObjectCache.cpp +++ b/cpp/src/IceGrid/ObjectCache.cpp @@ -65,7 +65,7 @@ ObjectCache::add(const ObjectInfo& info, const string& application, const string auto entry = make_shared(info, application, server); addImpl(id, entry); - map::iterator p = _types.find(entry->getType()); + auto p = _types.find(entry->getType()); if (p == _types.end()) { p = _types.insert(p, {entry->getType(), TypeEntry()}); @@ -104,7 +104,7 @@ ObjectCache::remove(const Ice::Identity& id) } removeImpl(id); - map::iterator p = _types.find(entry->getType()); + auto p = _types.find(entry->getType()); assert(p != _types.end()); if (p->second.remove(entry)) { @@ -131,11 +131,11 @@ ObjectCache::getAll(const string& expression) { lock_guard lock(_mutex); ObjectInfoSeq infos; - for (auto p = _entries.cbegin(); p != _entries.cend(); ++p) + for (const auto& entry : _entries) { - if (expression.empty() || IceInternal::match(_communicator->identityToString(p->first), expression, true)) + if (expression.empty() || IceInternal::match(_communicator->identityToString(entry.first), expression, true)) { - infos.push_back(p->second->getObjectInfo()); + infos.push_back(entry.second->getObjectInfo()); } } return infos; @@ -146,16 +146,16 @@ ObjectCache::getAllByType(const string& type) { lock_guard lock(_mutex); ObjectInfoSeq infos; - map::const_iterator p = _types.find(type); + auto p = _types.find(type); if (p == _types.end()) { return infos; } const vector>& objects = p->second.getObjects(); - for (vector>::const_iterator q = objects.begin(); q != objects.end(); ++q) + for (const auto& object : objects) { - infos.push_back((*q)->getObjectInfo()); + infos.push_back(object->getObjectInfo()); } return infos; } diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index fd10829c44e..9a0e545245d 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -423,7 +423,7 @@ void Parser::addApplication(const list& origArgs) { list copyArgs = origArgs; - copyArgs.push_front("icegridadmin"); + copyArgs.emplace_front("icegridadmin"); IceInternal::Options opts; vector args; @@ -452,7 +452,7 @@ Parser::addApplication(const list& origArgs) StringSeq targets; map vars; - vector::const_iterator p = args.begin(); + auto p = args.begin(); string desc = *p++; for (; p != args.end(); ++p) @@ -490,7 +490,7 @@ Parser::removeApplication(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); string name = *p++; @@ -513,7 +513,7 @@ Parser::describeApplication(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); string name = *p++; ostringstream os; @@ -534,7 +534,7 @@ void Parser::diffApplication(const list& origArgs) { list copyArgs = origArgs; - copyArgs.push_front("icegridadmin"); + copyArgs.emplace_front("icegridadmin"); IceInternal::Options opts; opts.addOpt("s", "servers"); @@ -564,7 +564,7 @@ Parser::diffApplication(const list& origArgs) StringSeq targets; map vars; - vector::const_iterator arg = args.begin(); + auto arg = args.begin(); string desc = *arg++; for (; arg != args.end(); ++arg) @@ -598,7 +598,7 @@ Parser::diffApplication(const list& origArgs) map::const_iterator p; for (p = oldServers.begin(); p != oldServers.end(); ++p) { - map::const_iterator q = newServers.find(p->first); + auto q = newServers.find(p->first); if (q == newServers.end()) { messages.push_back("server '" + p->first + "': removed"); @@ -607,7 +607,7 @@ Parser::diffApplication(const list& origArgs) for (p = newServers.begin(); p != newServers.end(); ++p) { - map::const_iterator q = oldServers.find(p->first); + auto q = oldServers.find(p->first); if (q == oldServers.end()) { messages.push_back("server '" + p->first + "': added"); @@ -628,9 +628,9 @@ Parser::diffApplication(const list& origArgs) out << "application '" << origApp.descriptor.name << "'"; out << sb; sort(messages.begin(), messages.end()); - for (vector::const_iterator r = messages.begin(); r != messages.end(); ++r) + for (const auto& message : messages) { - out << nl << *r; + out << nl << message; } out << eb; } @@ -651,16 +651,16 @@ void Parser::updateApplication(const list& origArgs) { list copyArgs = origArgs; - copyArgs.push_front("icegridadmin"); + copyArgs.emplace_front("icegridadmin"); IceInternal::Options opts; opts.addOpt("n", "no-restart"); vector args; try { - for (list::const_iterator p = copyArgs.begin(); p != copyArgs.end(); ++p) + for (const auto& copyArg : copyArgs) { - args.push_back(*p); + args.push_back(copyArg); } args = opts.parse(args); } @@ -681,7 +681,7 @@ Parser::updateApplication(const list& origArgs) StringSeq targets; map vars; - vector::const_iterator p = args.begin(); + auto p = args.begin(); string xml = *p++; for (; p != args.end(); ++p) @@ -751,7 +751,7 @@ Parser::describeServerTemplate(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); string name = *p++; string templ = *p++; @@ -760,7 +760,7 @@ Parser::describeServerTemplate(const list& args) ostringstream os; Output out(os); - TemplateDescriptorDict::const_iterator q = application.descriptor.serverTemplates.find(templ); + auto q = application.descriptor.serverTemplates.find(templ); if (q != application.descriptor.serverTemplates.end()) { out << "server template '" << templ << "'"; @@ -807,7 +807,7 @@ Parser::instantiateServerTemplate(const list& args) { map vars; - list::const_iterator p = args.begin(); + auto p = args.begin(); string application = *p++; string node = *p++; string templ = *p++; @@ -842,7 +842,7 @@ Parser::describeServiceTemplate(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); string name = *p++; string templ = *p++; @@ -851,7 +851,7 @@ Parser::describeServiceTemplate(const list& args) ostringstream os; Output out(os); - TemplateDescriptorDict::const_iterator q = application.descriptor.serviceTemplates.find(templ); + auto q = application.descriptor.serviceTemplates.find(templ); if (q != application.descriptor.serviceTemplates.end()) { out << "service template '" << templ << "'"; @@ -981,15 +981,15 @@ Parser::printNodeProcessorSockets(const list& args) { Ice::StringSeq names = _admin->getAllNodeNames(); map, int>> processorSocketCounts; - for (Ice::StringSeq::const_iterator p = names.begin(); p != names.end(); p++) + for (const auto& name : names) { try { - NodeInfo info = _admin->getNodeInfo(*p); - processorSocketCounts[info.hostname].first.push_back(*p); + NodeInfo info = _admin->getNodeInfo(name); + processorSocketCounts[info.hostname].first.push_back(name); try { - processorSocketCounts[info.hostname].second = _admin->getNodeProcessorSocketCount(*p); + processorSocketCounts[info.hostname].second = _admin->getNodeProcessorSocketCount(name); } catch (const Ice::OperationNotExistException&) { @@ -1009,13 +1009,11 @@ Parser::printNodeProcessorSockets(const list& args) os.flags(ios::left); os << setw(20) << "Hostname" << setw(20) << "| # of sockets" << setw(39) << "| Nodes" << endl; os << setw(79) << "=====================================================================" << endl; - for (map, int>>::const_iterator q = processorSocketCounts.begin(); - q != processorSocketCounts.end(); - ++q) + for (const auto& processorSocketCount : processorSocketCounts) { - os << setw(20) << setiosflags(ios::left) << q->first; - os << "| " << setw(18) << setiosflags(ios::left) << q->second.second; - os << "| " << setw(37) << setiosflags(ios::left) << toString(q->second.first); + os << setw(20) << setiosflags(ios::left) << processorSocketCount.first; + os << "| " << setw(18) << setiosflags(ios::left) << processorSocketCount.second.second; + os << "| " << setw(37) << setiosflags(ios::left) << toString(processorSocketCount.second.first); os << endl; } consoleOut << os.str() << flush; @@ -1252,7 +1250,7 @@ Parser::signalServer(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); string server = *p++; _admin->sendSignal(server, *p); } @@ -1273,7 +1271,7 @@ Parser::writeMessage(const list& args, int fd) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); string server = *p++; auto serverAdmin = _admin->getServerAdmin(server); @@ -1650,7 +1648,7 @@ Parser::propertiesService(const list& args, bool single) return; } - list::const_iterator a = args.begin(); + auto a = args.begin(); string server = *a++; string service = *a++; string property = single ? *a++ : string(); @@ -1779,10 +1777,10 @@ Parser::endpointsAdapter(const list& args) } else { - for (AdapterInfoSeq::const_iterator p = adpts.begin(); p != adpts.end(); ++p) + for (const auto& adpt : adpts) { - consoleOut << (p->id.empty() ? string("") : p->id) << ": "; - auto proxy = p->proxy; + consoleOut << (adpt.id.empty() ? string("") : adpt.id) << ": "; + auto proxy = adpt.proxy; if (proxy) { consoleOut << proxy << endl; @@ -1852,7 +1850,7 @@ Parser::addObject(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); string proxy = *p++; @@ -1903,9 +1901,9 @@ Parser::findObject(const list& args) try { ObjectInfoSeq objects = _admin->getObjectInfosByType(*(args.begin())); - for (ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) + for (const auto& object : objects) { - consoleOut << p->proxy << endl; + consoleOut << object.proxy << endl; } } catch (const Ice::Exception&) @@ -1946,9 +1944,9 @@ Parser::describeObject(const list& args) objects = _admin->getAllObjectInfos(""); } - for (ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) + for (const auto& object : objects) { - consoleOut << "proxy = '" << p->proxy << "' type = '" << p->type << "'" << endl; + consoleOut << "proxy = '" << object.proxy << "' type = '" << object.type << "'" << endl; } } catch (const Ice::Exception&) @@ -1978,9 +1976,9 @@ Parser::listObject(const list& args) objects = _admin->getAllObjectInfos(""); } - for (ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) + for (const auto& object : objects) { - consoleOut << _communicator->identityToString(p->proxy->ice_getIdentity()) << endl; + consoleOut << _communicator->identityToString(object.proxy->ice_getIdentity()) << endl; } } catch (const Ice::Exception&) @@ -1993,7 +1991,7 @@ void Parser::show(const string& reader, const list& origArgs) { list copyArgs = origArgs; - copyArgs.push_front("icegridadmin"); + copyArgs.emplace_front("icegridadmin"); IceInternal::Options opts; opts.addOpt("f", "follow"); @@ -2003,9 +2001,9 @@ Parser::show(const string& reader, const list& origArgs) vector args; try { - for (list::const_iterator p = copyArgs.begin(); p != copyArgs.end(); ++p) + for (const auto& copyArg : copyArgs) { - args.push_back(*p); + args.push_back(copyArg); } args = opts.parse(args); } @@ -2023,7 +2021,7 @@ Parser::show(const string& reader, const list& origArgs) try { - vector::const_iterator p = args.begin(); + auto p = args.begin(); string id = *p++; string filename = *p++; @@ -2188,7 +2186,7 @@ Parser::showFile( while (!interrupted()) { bool eof = it->read(maxBytes, lines); - for (Ice::StringSeq::const_iterator p = lines.begin(); p != lines.end(); ++p) + for (auto p = lines.begin(); p != lines.end(); ++p) { outputString(*p); if ((p + 1) != lines.end()) @@ -2329,9 +2327,9 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow, const Ice::LogMessageSeq logMessages = loggerAdmin->getLog(Ice::LogMessageTypeSeq(), Ice::StringSeq(), tail ? lineCount : -1, prefix); - for (Ice::LogMessageSeq::const_iterator p = logMessages.begin(); p != logMessages.end(); ++p) + for (const auto& logMessage : logMessages) { - printLogMessage(prefix, *p); + printLogMessage(prefix, logMessage); } } } @@ -2362,7 +2360,7 @@ Parser::showWarranty() void Parser::getInput(char* buf, int& result, size_t maxSize) { - size_t r = static_cast(result); + auto r = static_cast(result); getInput(buf, r, maxSize); result = static_cast(r); } diff --git a/cpp/src/IceGrid/PlatformInfo.cpp b/cpp/src/IceGrid/PlatformInfo.cpp index a936169b144..627dfb020c7 100644 --- a/cpp/src/IceGrid/PlatformInfo.cpp +++ b/cpp/src/IceGrid/PlatformInfo.cpp @@ -317,7 +317,7 @@ PlatformInfo::PlatformInfo( } Ice::PropertyDict props = properties->getPropertiesForPrefix(endpointsPrefix); - Ice::PropertyDict::const_iterator p = props.find(endpointsPrefix + ".PublishedEndpoints"); + auto p = props.find(endpointsPrefix + ".PublishedEndpoints"); if (p != props.end()) { _endpoints = p->second; diff --git a/cpp/src/IceGrid/PluginFacadeI.cpp b/cpp/src/IceGrid/PluginFacadeI.cpp index d19806bc8aa..84be066b847 100644 --- a/cpp/src/IceGrid/PluginFacadeI.cpp +++ b/cpp/src/IceGrid/PluginFacadeI.cpp @@ -156,12 +156,11 @@ RegistryPluginFacadeI::getPropertyForAdapter(const std::string& adapterId, const return ""; } - for (ServiceInstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); - ++p) + for (const auto& service : iceBox->services) { - if (hasAdapter(p->descriptor, adapterId)) + if (hasAdapter(service.descriptor, adapterId)) { - return IceGrid::getProperty(p->descriptor->propertySet.properties, name); + return IceGrid::getProperty(service.descriptor->propertySet.properties, name); } } } @@ -178,7 +177,7 @@ void RegistryPluginFacadeI::addReplicaGroupFilter(const string& id, const shared_ptr& filter) noexcept { lock_guard lock(_mutex); - map>>::iterator p = _replicaGroupFilters.find(id); + auto p = _replicaGroupFilters.find(id); if (p == _replicaGroupFilters.end()) { p = _replicaGroupFilters.insert(make_pair(id, vector>())).first; @@ -191,13 +190,13 @@ RegistryPluginFacadeI::removeReplicaGroupFilter(const string& id, const shared_p { lock_guard lock(_mutex); - map>>::iterator p = _replicaGroupFilters.find(id); + auto p = _replicaGroupFilters.find(id); if (p == _replicaGroupFilters.end()) { return false; } - vector>::iterator q = find(p->second.begin(), p->second.end(), filter); + auto q = find(p->second.begin(), p->second.end(), filter); if (q == p->second.end()) { return false; @@ -215,7 +214,7 @@ void RegistryPluginFacadeI::addTypeFilter(const string& id, const shared_ptr& filter) noexcept { lock_guard lock(_mutex); - map>>::iterator p = _typeFilters.find(id); + auto p = _typeFilters.find(id); if (p == _typeFilters.end()) { p = _typeFilters.insert(make_pair(id, vector>())).first; @@ -228,13 +227,13 @@ RegistryPluginFacadeI::removeTypeFilter(const string& id, const shared_ptr>>::iterator p = _typeFilters.find(id); + auto p = _typeFilters.find(id); if (p == _typeFilters.end()) { return false; } - vector>::iterator q = find(p->second.begin(), p->second.end(), filter); + auto q = find(p->second.begin(), p->second.end(), filter); if (q == p->second.end()) { return false; @@ -252,7 +251,7 @@ vector> RegistryPluginFacadeI::getReplicaGroupFilters(const string& id) const { lock_guard lock(_mutex); - map>>::const_iterator p = _replicaGroupFilters.find(id); + auto p = _replicaGroupFilters.find(id); if (p != _replicaGroupFilters.end()) { return p->second; @@ -270,7 +269,7 @@ vector> RegistryPluginFacadeI::getTypeFilters(const string& id) const { lock_guard lock(_mutex); - map>>::const_iterator p = _typeFilters.find(id); + auto p = _typeFilters.find(id); if (p != _typeFilters.end()) { return p->second; diff --git a/cpp/src/IceGrid/QueryI.cpp b/cpp/src/IceGrid/QueryI.cpp index e5912b56882..9d5824fc895 100644 --- a/cpp/src/IceGrid/QueryI.cpp +++ b/cpp/src/IceGrid/QueryI.cpp @@ -86,7 +86,7 @@ QueryI::findAllReplicas(optional proxy, const Ice::Current& curr for (const auto& info : infos) { assert(!info.id.empty()); - proxies.push_back(proxy->ice_adapterId(info.id)); + proxies.emplace_back(proxy->ice_adapterId(info.id)); } return proxies; } diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index d61a8663caa..b7a4d262324 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -542,10 +542,10 @@ RegistryI::startImpl() _serverAdapter->addDefaultServant(adminCallbackRouter, ""); vector verifierProperties; - verifierProperties.push_back("IceGrid.Registry.PermissionsVerifier"); - verifierProperties.push_back("IceGrid.Registry.SSLPermissionsVerifier"); - verifierProperties.push_back("IceGrid.Registry.AdminPermissionsVerifier"); - verifierProperties.push_back("IceGrid.Registry.AdminSSLPermissionsVerifier"); + verifierProperties.emplace_back("IceGrid.Registry.PermissionsVerifier"); + verifierProperties.emplace_back("IceGrid.Registry.SSLPermissionsVerifier"); + verifierProperties.emplace_back("IceGrid.Registry.AdminPermissionsVerifier"); + verifierProperties.emplace_back("IceGrid.Registry.AdminSSLPermissionsVerifier"); try { diff --git a/cpp/src/IceGrid/ReplicaCache.cpp b/cpp/src/IceGrid/ReplicaCache.cpp index 4d932a2781c..976d77ade92 100644 --- a/cpp/src/IceGrid/ReplicaCache.cpp +++ b/cpp/src/IceGrid/ReplicaCache.cpp @@ -176,7 +176,7 @@ ReplicaCache::subscribe(const ReplicaObserverPrx& observer) InternalRegistryPrxSeq replicas; for (const auto& entry : _entries) { - replicas.push_back(entry.second->getProxy()); + replicas.emplace_back(entry.second->getProxy()); } IceStorm::QoS qos; diff --git a/cpp/src/IceGrid/ReplicaSessionI.cpp b/cpp/src/IceGrid/ReplicaSessionI.cpp index f44556509f2..05f5159456c 100644 --- a/cpp/src/IceGrid/ReplicaSessionI.cpp +++ b/cpp/src/IceGrid/ReplicaSessionI.cpp @@ -125,10 +125,10 @@ ReplicaSessionI::setDatabaseObserver( { StringLongDict masterSerials = _database->getSerials(); bool error = false; - for (StringLongDict::const_iterator p = slaveSerials->begin(); p != slaveSerials->end(); ++p) + for (const auto& p : *slaveSerials) { - int64_t serial = masterSerials[p->first]; - if (serial < p->second) + int64_t serial = masterSerials[p.first]; + if (serial < p.second) { error = true; break; @@ -138,11 +138,11 @@ ReplicaSessionI::setDatabaseObserver( { ostringstream os; os << "database from replica '" << _info->name << "' contains earlier updates:\n"; - for (StringLongDict::const_iterator p = slaveSerials->begin(); p != slaveSerials->end(); ++p) + for (const auto& p : *slaveSerials) { - int64_t serial = masterSerials[p->first]; - os << "database '" << p->first << "': "; - os << "master serial = " << serial << ", replica serial = " << p->second << '\n'; + int64_t serial = masterSerials[p.first]; + os << "database '" << p.first << "': "; + os << "master serial = " << serial << ", replica serial = " << p.second << '\n'; } os << "(database replication is disabled for this replica, please check the\n"; os << " master and slave database with an administrative client and either:\n"; diff --git a/cpp/src/IceGrid/ServerCache.cpp b/cpp/src/IceGrid/ServerCache.cpp index 4197cad7fa3..f4f38eee10a 100644 --- a/cpp/src/IceGrid/ServerCache.cpp +++ b/cpp/src/IceGrid/ServerCache.cpp @@ -239,16 +239,16 @@ ServerCache::addCommunicator( { return; // Nothing to add } - for (AdapterDescriptorSeq::const_iterator q = newDesc->adapters.begin(); q != newDesc->adapters.end(); ++q) + for (auto q = newDesc->adapters.begin(); q != newDesc->adapters.end(); ++q) { AdapterDescriptor oldAdpt; if (oldDesc) { - for (AdapterDescriptorSeq::const_iterator p = oldDesc->adapters.begin(); p != oldDesc->adapters.end(); ++p) + for (const auto& adapter : oldDesc->adapters) { - if (p->id == q->id) + if (adapter.id == q->id) { - oldAdpt = *p; + oldAdpt = adapter; break; } } @@ -256,11 +256,11 @@ ServerCache::addCommunicator( assert(!q->id.empty()); _adapterCache.addServerAdapter(*q, server, application); - for (ObjectDescriptorSeq::const_iterator r = q->objects.begin(); r != q->objects.end(); ++r) + for (auto r = q->objects.begin(); r != q->objects.end(); ++r) { _objectCache.add(toObjectInfo(_communicator, *r, q->id), application, server->getId()); } - for (ObjectDescriptorSeq::const_iterator r = q->allocatables.begin(); r != q->allocatables.end(); ++r) + for (auto r = q->allocatables.begin(); r != q->allocatables.end(); ++r) { ObjectDescriptorSeq::const_iterator s; for (s = oldAdpt.allocatables.begin(); s != oldAdpt.allocatables.end() && s->id != r->id; ++s) @@ -283,34 +283,34 @@ ServerCache::removeCommunicator( { return; // Nothing to remove } - for (AdapterDescriptorSeq::const_iterator q = oldDesc->adapters.begin(); q != oldDesc->adapters.end(); ++q) + for (auto q = oldDesc->adapters.begin(); q != oldDesc->adapters.end(); ++q) { AdapterDescriptor newAdpt; if (newDesc) { - for (AdapterDescriptorSeq::const_iterator p = newDesc->adapters.begin(); p != newDesc->adapters.end(); ++p) + for (const auto& adapter : newDesc->adapters) { - if (p->id == q->id) + if (adapter.id == q->id) { - newAdpt = *p; + newAdpt = adapter; break; } } } - for (ObjectDescriptorSeq::const_iterator r = q->objects.begin(); r != q->objects.end(); ++r) + for (const auto& object : q->objects) { - _objectCache.remove((*r).id); + _objectCache.remove(object.id); } - for (ObjectDescriptorSeq::const_iterator r = q->allocatables.begin(); r != q->allocatables.end(); ++r) + for (const auto& allocatable : q->allocatables) { // Don't remove the allocatable if it's still in the new descriptor. ObjectDescriptorSeq::const_iterator s; - for (s = newAdpt.allocatables.begin(); s != newAdpt.allocatables.end() && s->id != r->id; ++s) + for (s = newAdpt.allocatables.begin(); s != newAdpt.allocatables.end() && s->id != allocatable.id; ++s) ; - if (s == newAdpt.allocatables.end() || *s != *r) // Only removed updated or removed allocatables + if (s == newAdpt.allocatables.end() || *s != allocatable) // Only removed updated or removed allocatables { - _allocatableObjectCache.remove(r->id); + _allocatableObjectCache.remove(allocatable.id); } } _adapterCache.removeServerAdapter(q->id); @@ -573,7 +573,7 @@ ServerEntry::getAdapter( lock_guard lock(_mutex); if (_loaded || (_proxy && _synchronizing && !upToDate)) // Synced or if not up to date is fine { - AdapterPrxDict::const_iterator p = _adapters.find(id); + auto p = _adapters.find(id); if (p != _adapters.end()) { assert(p->second); diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index b8cbff7b189..385d5b62f05 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -61,9 +61,9 @@ namespace IceGrid throw runtime_error("cannot read directory '" + path + "':\n" + IceInternal::lastErrorToString()); } - for (size_t i = 0; i < namelist.size(); ++i) + for (auto& i : namelist) { - string name = reinterpret_cast(&namelist[i][0])->d_name; + string name = reinterpret_cast(&i[0])->d_name; assert(!name.empty()); if (name == ".") @@ -127,9 +127,8 @@ namespace IceGrid } else { - InternalAdapterDescriptorSeq::const_iterator q = rhs->adapters.begin(); - for (InternalAdapterDescriptorSeq::const_iterator p = lhs->adapters.begin(); p != lhs->adapters.end(); - ++p, ++q) + auto q = rhs->adapters.begin(); + for (auto p = lhs->adapters.begin(); p != lhs->adapters.end(); ++p, ++q) { if ((*p)->id != (*q)->id || (*p)->serverLifetime != (*q)->serverLifetime) { @@ -149,20 +148,20 @@ namespace IceGrid Ice::PropertyDict toPropertyDict(const PropertyDescriptorSeq& seq) { Ice::PropertyDict props; - for (PropertyDescriptorSeq::const_iterator q = seq.begin(); q != seq.end(); ++q) + for (const auto& q : seq) { - if (q->value.empty() && q->name.find('#') == 0) + if (q.value.empty() && q.name.find('#') == 0) { continue; // Ignore comments. } - if (q->value.empty()) + if (q.value.empty()) { - props.erase(q->name); + props.erase(q.name); } else { - props[q->name] = q->value; + props[q.name] = q.value; } } return props; @@ -467,7 +466,7 @@ LoadCommand::addCallback( function response, function exception) { - _loadCB.push_back({std::move(response), std::move(exception)}); + _loadCB.emplace_back(std::move(response), std::move(exception)); } void @@ -607,7 +606,7 @@ StartCommand::timeout() void StartCommand::addCallback(function response, function exception) { - _startCB.push_back({std::move(response), std::move(exception)}); + _startCB.emplace_back(std::move(response), std::move(exception)); } void @@ -680,7 +679,7 @@ StopCommand::timeout() void StopCommand::addCallback(function response, function exception) { - _stopCB.push_back({std::move(response), std::move(exception)}); + _stopCB.emplace_back(std::move(response), std::move(exception)); } void @@ -2171,10 +2170,10 @@ ServerI::updateImpl(const shared_ptr& descriptor) if (_desc->services) { Ice::StringSeq knownDirs; - for (Ice::StringSeq::const_iterator q = _desc->services->begin(); q != _desc->services->end(); ++q) + for (const auto& q : *_desc->services) { - knownDirs.push_back("data_" + *q); - createDirectory(_serverDir + "/data_" + *q); + knownDirs.push_back("data_" + q); + createDirectory(_serverDir + "/data_" + q); } sort(knownDirs.begin(), knownDirs.end()); @@ -2955,30 +2954,30 @@ ServerI::getProperties(const shared_ptr& desc) // { const PropertyDescriptorSeq& overrides = _node->getPropertiesOverride(); - for (PropertyDescriptorSeqDict::iterator p = propDict.begin(); p != propDict.end(); ++p) + for (auto& p : propDict) { - if (getProperty(p->second, "Ice.Default.Locator").empty()) + if (getProperty(p.second, "Ice.Default.Locator").empty()) { auto properties = _node->getCommunicator()->getProperties(); string locator = properties->getIceProperty("Ice.Default.Locator"); if (!locator.empty()) { - p->second.push_back(createProperty("Ice.Default.Locator", locator)); + p.second.push_back(createProperty("Ice.Default.Locator", locator)); } string discoveryPlugin = properties->getIceProperty("Ice.Plugin.IceLocatorDiscovery"); if (!discoveryPlugin.empty()) { - p->second.push_back(createProperty("Ice.Plugin.IceLocatorDiscovery", discoveryPlugin)); - p->second.push_back(createProperty("IceLocatorDiscovery.InstanceName", _node->getInstanceName())); + p.second.push_back(createProperty("Ice.Plugin.IceLocatorDiscovery", discoveryPlugin)); + p.second.push_back(createProperty("IceLocatorDiscovery.InstanceName", _node->getInstanceName())); } } if (!overrides.empty()) { - p->second.push_back(createProperty("# Node properties override")); - p->second.insert(p->second.end(), overrides.begin(), overrides.end()); + p.second.push_back(createProperty("# Node properties override")); + p.second.insert(p.second.end(), overrides.begin(), overrides.end()); } } } diff --git a/cpp/src/IceGrid/SessionServantManager.cpp b/cpp/src/IceGrid/SessionServantManager.cpp index 7551df02dc4..13894b9ab4f 100644 --- a/cpp/src/IceGrid/SessionServantManager.cpp +++ b/cpp/src/IceGrid/SessionServantManager.cpp @@ -194,9 +194,9 @@ SessionServantManager::removeSession(const Ice::ObjectPtr& session) // // Remove all the servants associated with the session. // - for (auto q = p->second.identities.cbegin(); q != p->second.identities.cend(); ++q) + for (const auto& identity : p->second.identities) { - _servants.erase(*q); + _servants.erase(identity); } // @@ -228,14 +228,14 @@ void SessionServantManager::remove(const Ice::Identity& id) { lock_guard lock(_mutex); - map::iterator p = _servants.find(id); + auto p = _servants.find(id); assert(p != _servants.end()); // // Find the session associated to the servant and remove the servant identity from the // session identities. // - map::iterator q = _sessions.find(p->second.session); + auto q = _sessions.find(p->second.session); assert(q != _sessions.end()); q->second.identities.erase(id); diff --git a/cpp/src/IceGrid/Topics.cpp b/cpp/src/IceGrid/Topics.cpp index 1876a0fe20a..2a56444e61e 100644 --- a/cpp/src/IceGrid/Topics.cpp +++ b/cpp/src/IceGrid/Topics.cpp @@ -24,10 +24,10 @@ ObserverTopic::ObserverTopic(const IceStorm::TopicManagerPrx& topicManager, cons _serial(0), _dbSerial(dbSerial) { - for (int i = 0; i < static_cast(sizeof(encodings) / sizeof(Ice::EncodingVersion)); ++i) + for (const auto& encoding : encodings) { ostringstream os; - os << name << "-" << Ice::encodingVersionToString(encodings[i]); + os << name << "-" << Ice::encodingVersionToString(encoding); optional topic; try @@ -49,7 +49,7 @@ ObserverTopic::ObserverTopic(const IceStorm::TopicManagerPrx& topicManager, cons // topic because the subscribe() method is given a fixed proxy // which can't be marshaled. // - _topics.insert({encodings[i], *topic}); + _topics.insert({encoding, *topic}); optional publisher = topic->getPublisher(); @@ -61,7 +61,7 @@ ObserverTopic::ObserverTopic(const IceStorm::TopicManagerPrx& topicManager, cons "failed to get publisher for topic '" + topic->ice_toString() + "'"); } - _basePublishers.push_back((*publisher)->ice_encodingVersion(encodings[i])); + _basePublishers.push_back((*publisher)->ice_encodingVersion(encoding)); } } @@ -168,14 +168,14 @@ void ObserverTopic::receivedUpdate(const string& name, int serial, const string& failure) { lock_guard lock(_mutex); - map>::iterator p = _waitForUpdates.find(serial); + auto p = _waitForUpdates.find(serial); if (p != _waitForUpdates.end()) { p->second.erase(name); if (!failure.empty()) { - map>::iterator q = _updateFailures.find(serial); + auto q = _updateFailures.find(serial); if (q == _updateFailures.end()) { q = _updateFailures.insert(make_pair(serial, map())).first; @@ -216,9 +216,9 @@ ObserverTopic::waitForSyncedSubscribers(int serial, const string& name) map failures = q->second; _updateFailures.erase(q); ostringstream os; - for (map::const_iterator r = failures.begin(); r != failures.end(); ++r) + for (const auto& failure : failures) { - os << "replication failed on replica '" << r->first << "':\n" << r->second << "\n"; + os << "replication failed on replica '" << failure.first << "':\n" << failure.second << "\n"; } Ice::Error err(_logger); @@ -441,7 +441,7 @@ NodeObserverTopic::updateServer(string node, ServerDynamicInfo server, const Ice updateSerial(); ServerDynamicInfoSeq& servers = _nodes[node].servers; - ServerDynamicInfoSeq::iterator p = servers.begin(); + auto p = servers.begin(); while (p != servers.end()) { if (p->id == server.id) @@ -507,7 +507,7 @@ NodeObserverTopic::updateAdapter(string node, AdapterDynamicInfo adapter, const updateSerial(); AdapterDynamicInfoSeq& adapters = _nodes[node].adapters; - AdapterDynamicInfoSeq::iterator p = adapters.begin(); + auto p = adapters.begin(); while (p != adapters.end()) { if (p->id == adapter.id) @@ -601,7 +601,7 @@ NodeObserverTopic::isServerEnabled(const string& server) const { return false; } - map::const_iterator p = _serverStatus.find(server); + auto p = _serverStatus.find(server); if (p != _serverStatus.end()) { return p->second; @@ -632,9 +632,9 @@ ApplicationObserverTopic::applicationInit(int64_t dbSerial, const ApplicationInf } updateSerial(dbSerial); _applications.clear(); - for (ApplicationInfoSeq::const_iterator p = apps.begin(); p != apps.end(); ++p) + for (const auto& app : apps) { - _applications.insert(make_pair(p->descriptor.name, *p)); + _applications.insert(make_pair(app.descriptor.name, app)); } try { @@ -717,7 +717,7 @@ ApplicationObserverTopic::applicationUpdated(int64_t dbSerial, const Application updateSerial(dbSerial); try { - map::iterator p = _applications.find(info.descriptor.name); + auto p = _applications.find(info.descriptor.name); if (p != _applications.end()) { ApplicationHelper helper(_publishers[0]->ice_getCommunicator(), p->second.descriptor); diff --git a/cpp/src/IceGrid/TraceLevels.h b/cpp/src/IceGrid/TraceLevels.h index 61841dee8e6..caa0f42ae65 100644 --- a/cpp/src/IceGrid/TraceLevels.h +++ b/cpp/src/IceGrid/TraceLevels.h @@ -10,7 +10,7 @@ namespace IceGrid { - class TraceLevels // NOLINT:clang-analyzer-optin.performance.Padding + class TraceLevels // NOLINT(clang-analyzer-optin.performance.Padding) { public: TraceLevels(const Ice::CommunicatorPtr&, const std::string&); diff --git a/cpp/src/IceGrid/Util.cpp b/cpp/src/IceGrid/Util.cpp index a6628a53686..a9ab8d6e46b 100644 --- a/cpp/src/IceGrid/Util.cpp +++ b/cpp/src/IceGrid/Util.cpp @@ -41,7 +41,7 @@ string IceGrid::toString(const vector& v, const string& sep) { ostringstream os; - Ice::StringSeq::const_iterator p = v.begin(); + auto p = v.begin(); while (p != v.end()) { os << *p; @@ -84,11 +84,11 @@ string IceGrid::getProperty(const PropertyDescriptorSeq& properties, const string& name, const string& def) { string result; - for (PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) + for (const auto& prop : properties) { - if (q->name == name) + if (prop.name == name) { - result = q->value; + result = prop.value; } } if (result.empty()) @@ -102,11 +102,11 @@ int IceGrid::getPropertyAsInt(const PropertyDescriptorSeq& properties, const string& name, int def) { string strVal; - for (PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) + for (const auto& prop : properties) { - if (q->name == name) + if (prop.name == name) { - strVal = q->value; + strVal = prop.value; } } @@ -126,9 +126,9 @@ IceGrid::getPropertyAsInt(const PropertyDescriptorSeq& properties, const string& bool IceGrid::hasProperty(const PropertyDescriptorSeq& properties, const string& name) { - for (PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) + for (const auto& prop : properties) { - if (q->name == name) + if (prop.name == name) { return true; } @@ -506,9 +506,9 @@ IceGrid::removeRecursive(const string& pa) if (S_ISDIR(buf.st_mode)) { StringSeq paths = readDirectory(path); - for (StringSeq::const_iterator p = paths.begin(); p != paths.end(); ++p) + for (const auto& p : paths) { - removeRecursive(path + '/' + *p); + removeRecursive(path + '/' + p); } if (!isRoot(path)) diff --git a/cpp/src/IceGrid/Util.h b/cpp/src/IceGrid/Util.h index acc425dc05b..00aaecf3dac 100644 --- a/cpp/src/IceGrid/Util.h +++ b/cpp/src/IceGrid/Util.h @@ -126,11 +126,11 @@ namespace IceGrid template std::vector inline getMatchingKeys(const T& m, const std::string& expression) { std::vector keys; - for (typename T::const_iterator p = m.begin(); p != m.end(); ++p) + for (const auto& entry : m) { - if (expression.empty() || IceInternal::match(p->first, expression, true)) + if (expression.empty() || IceInternal::match(entry.first, expression, true)) { - keys.push_back(p->first); + keys.push_back(entry.first); } } return keys; diff --git a/cpp/src/IceGrid/WellKnownObjectsManager.cpp b/cpp/src/IceGrid/WellKnownObjectsManager.cpp index c016dd71220..92ac94f6e89 100644 --- a/cpp/src/IceGrid/WellKnownObjectsManager.cpp +++ b/cpp/src/IceGrid/WellKnownObjectsManager.cpp @@ -135,11 +135,11 @@ WellKnownObjectsManager::getWellKnownObjectReplicatedProxy(const Ice::Identity& // Re-order the endpoints to return first the endpoint for this registry replica. Ice::EndpointSeq endpoints = proxy->ice_getEndpoints(); Ice::EndpointSeq newEndpoints = registryEndpoints; - for (Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) + for (const auto& endpoint : endpoints) { - if (find(registryEndpoints.begin(), registryEndpoints.end(), *p) == registryEndpoints.end()) + if (find(registryEndpoints.begin(), registryEndpoints.end(), endpoint) == registryEndpoints.end()) { - newEndpoints.push_back(*p); + newEndpoints.push_back(endpoint); } } return proxy->ice_endpoints(newEndpoints); diff --git a/cpp/src/IceGrid/XMLParser.cpp b/cpp/src/IceGrid/XMLParser.cpp index da514addbdd..1c8fc9e4c1b 100644 --- a/cpp/src/IceGrid/XMLParser.cpp +++ b/cpp/src/IceGrid/XMLParser.cpp @@ -38,7 +38,7 @@ extern "C" { static void startElementHandler(void* data, const XML_Char* name, const XML_Char** attr) { - CallbackData* cb = static_cast(data); + auto* cb = static_cast(data); XMLAttributes attributes; for (int i = 0; attr[i]; i += 2) @@ -53,7 +53,7 @@ extern "C" static void endElementHandler(void* data, const XML_Char* name) { - CallbackData* cb = static_cast(data); + auto* cb = static_cast(data); int line = static_cast(XML_GetCurrentLineNumber(cb->parser)); int column = static_cast(XML_GetCurrentColumnNumber(cb->parser)); cb->handler->endElement(name, line, column); @@ -61,7 +61,7 @@ extern "C" static void characterDataHandler(void* data, const XML_Char* s, int len) { - CallbackData* cb = static_cast(data); + auto* cb = static_cast(data); string str(s, static_cast(len)); int line = static_cast(XML_GetCurrentLineNumber(cb->parser)); diff --git a/cpp/src/IceLocatorDiscovery/PluginI.cpp b/cpp/src/IceLocatorDiscovery/PluginI.cpp index c1454b9b69d..7301d013f95 100644 --- a/cpp/src/IceLocatorDiscovery/PluginI.cpp +++ b/cpp/src/IceLocatorDiscovery/PluginI.cpp @@ -209,7 +209,7 @@ PluginI::initialize() IceInternal::ProtocolSupport protocol = ipv4 && !preferIPv6 ? IceInternal::EnableIPv4 : IceInternal::EnableIPv6; vector interfaces = IceInternal::getInterfacesForMulticast(intf, protocol); ostringstream lookup; - for (vector::const_iterator p = interfaces.begin(); p != interfaces.end(); ++p) + for (auto p = interfaces.begin(); p != interfaces.end(); ++p) { if (p != interfaces.begin()) { @@ -428,7 +428,7 @@ LocatorI::setLookupReply(const LookupReplyPrx& lookupReply) } } - _lookups.push_back(make_pair(_lookup->ice_endpoints(Ice::EndpointSeq{lookupEndpoint}), reply)); + _lookups.emplace_back(_lookup->ice_endpoints(Ice::EndpointSeq{lookupEndpoint}), reply); } assert(!_lookups.empty()); } diff --git a/cpp/src/IceStorm/Admin.cpp b/cpp/src/IceStorm/Admin.cpp index 18f45b2c5cc..aab531c4dd9 100644 --- a/cpp/src/IceStorm/Admin.cpp +++ b/cpp/src/IceStorm/Admin.cpp @@ -107,9 +107,9 @@ run(const shared_ptr& communicator, const Ice::StringSeq& arg if (opts.isSet("e")) { vector optargs = opts.argVec("e"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& arg : optargs) { - commands += *i + ";"; + commands += arg + ";"; } } debug = opts.isSet("debug"); diff --git a/cpp/src/IceStorm/IceStormDB.cpp b/cpp/src/IceStorm/IceStormDB.cpp index db95eff95c9..3254719ab21 100644 --- a/cpp/src/IceStorm/IceStormDB.cpp +++ b/cpp/src/IceStorm/IceStormDB.cpp @@ -204,14 +204,13 @@ run(const shared_ptr& communicator, const Ice::StringSeq& arg dbContext, MDB_CREATE); - for (IceStormElection::StringLogUpdateDict::const_iterator p = data.llus.begin(); p != data.llus.end(); - ++p) + for (const auto& llu : data.llus) { if (debug) { - consoleOut << " KEY = " << p->first << endl; + consoleOut << " KEY = " << llu.first << endl; } - lluMap.put(txn, p->first, p->second); + lluMap.put(txn, llu.first, llu.second); } if (debug) diff --git a/cpp/src/IceStorm/InstrumentationI.cpp b/cpp/src/IceStorm/InstrumentationI.cpp index ad22f2ceea7..196634ba974 100644 --- a/cpp/src/IceStorm/InstrumentationI.cpp +++ b/cpp/src/IceStorm/InstrumentationI.cpp @@ -96,7 +96,7 @@ namespace { if (attribute.compare(0, 4, "qos.") == 0) { - IceStorm::QoS::const_iterator p = _qos.find(attribute.substr(4)); + auto p = _qos.find(attribute.substr(4)); if (p != _qos.end()) { return p->second; diff --git a/cpp/src/IceStorm/NodeI.cpp b/cpp/src/IceStorm/NodeI.cpp index 2a351d706cf..38b4bb0f313 100644 --- a/cpp/src/IceStorm/NodeI.cpp +++ b/cpp/src/IceStorm/NodeI.cpp @@ -94,7 +94,7 @@ namespace { ostringstream os; os << "("; - for (set::const_iterator p = s.begin(); p != s.end(); ++p) + for (auto p = s.begin(); p != s.end(); ++p) { if (p != s.begin()) { @@ -408,7 +408,7 @@ NodeI::merge(const set& coordinatorSet) } } - set::iterator p = invited.begin(); + auto p = invited.begin(); while (p != invited.end()) { try @@ -496,7 +496,7 @@ NodeI::mergeContinue() // in the election. If we're running a subsequent election then we // need a majority of the nodes to be active in order to start // running. - unsigned int ingroup = static_cast(tmpSet.size()); + auto ingroup = static_cast(tmpSet.size()); if ((_max != _nodes.size() && ingroup != _nodes.size() - 1) || ingroup < _nodes.size() / 2) { if (_traceLevels->election > 0) @@ -872,7 +872,7 @@ NodeI::accept( { Ice::Trace out(_traceLevels->logger, _traceLevels->electionCat); out << "node " << _id << ": accept " << j << " forward invites ("; - for (Ice::IntSeq::const_iterator p = forwardedInvites.begin(); p != forwardedInvites.end(); ++p) + for (auto p = forwardedInvites.begin(); p != forwardedInvites.end(); ++p) { if (p != forwardedInvites.begin()) { diff --git a/cpp/src/IceStorm/Observers.cpp b/cpp/src/IceStorm/Observers.cpp index dca78e6d7f2..9641bbf27a5 100644 --- a/cpp/src/IceStorm/Observers.cpp +++ b/cpp/src/IceStorm/Observers.cpp @@ -168,7 +168,7 @@ Observers::removeSubscriber(const LogUpdate& llu, const string& name, const Ice: void Observers::wait(const string& op) { - vector::iterator p = _observers.begin(); + auto p = _observers.begin(); while (p != _observers.end()) { try diff --git a/cpp/src/IceStorm/Parser.cpp b/cpp/src/IceStorm/Parser.cpp index ed1cf616399..89c59148757 100644 --- a/cpp/src/IceStorm/Parser.cpp +++ b/cpp/src/IceStorm/Parser.cpp @@ -144,7 +144,7 @@ Parser::link(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); auto fromTopic = findTopic(*p++); auto toTopic = findTopic(*p++); @@ -169,7 +169,7 @@ Parser::unlink(const list& args) try { - list::const_iterator p = args.begin(); + auto p = args.begin(); auto fromTopic = findTopic(*p++); auto toTopic = findTopic(*p++); @@ -369,7 +369,7 @@ Parser::showBanner() void Parser::getInput(char* buf, int& result, size_t maxSize) { - size_t r = static_cast(result); + auto r = static_cast(result); getInput(buf, r, maxSize); result = static_cast(r); } diff --git a/cpp/src/IceStorm/Subscriber.cpp b/cpp/src/IceStorm/Subscriber.cpp index aca36cb95d1..2aa5d1b065b 100644 --- a/cpp/src/IceStorm/Subscriber.cpp +++ b/cpp/src/IceStorm/Subscriber.cpp @@ -393,7 +393,7 @@ Subscriber::create(const shared_ptr& instance, const SubscriberRecord& try { int retryCount = 0; - QoS::const_iterator p = rec.theQoS.find("retryCount"); + auto p = rec.theQoS.find("retryCount"); if (p != rec.theQoS.end()) { retryCount = atoi(p->second.c_str()); @@ -537,7 +537,7 @@ Subscriber::queue(bool forwarded, const EventDataSeq& events) case SubscriberStateOnline: { - for (EventDataSeq::const_iterator p = events.begin(); p != events.end(); ++p) + for (const auto& event : events) { if (static_cast(_events.size()) == _instance->sendQueueSizeMax()) { @@ -551,7 +551,7 @@ Subscriber::queue(bool forwarded, const EventDataSeq& events) _events.pop_front(); } } - _events.push_back(*p); + _events.push_back(event); } if (_observer) diff --git a/cpp/src/IceStorm/TopicI.cpp b/cpp/src/IceStorm/TopicI.cpp index 1100a2783e1..9deb36ce60f 100644 --- a/cpp/src/IceStorm/TopicI.cpp +++ b/cpp/src/IceStorm/TopicI.cpp @@ -507,7 +507,7 @@ TopicImpl::subscribeAndGetPublisher(QoS qos, Ice::ObjectPrx obj) if (traceLevels->topic > 1) { out << " endpoints: " << IceStormInternal::describeEndpoints(obj) << " QoS: "; - for (QoS::const_iterator p = qos.begin(); p != qos.end(); ++p) + for (auto p = qos.begin(); p != qos.end(); ++p) { if (p != qos.begin()) { @@ -708,7 +708,7 @@ TopicImpl::reap(const Ice::IdentitySeq& ids) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << ": reap "; - for (Ice::IdentitySeq::const_iterator p = ids.begin(); p != ids.end(); ++p) + for (auto p = ids.begin(); p != ids.end(); ++p) { if (p != ids.begin()) { @@ -1004,7 +1004,7 @@ TopicImpl::observerAddSubscriber(const LogUpdate& llu, const SubscriberRecord& r if (traceLevels->topic > 1) { out << " endpoints: " << IceStormInternal::describeEndpoints(record.obj) << " QoS: "; - for (QoS::const_iterator p = record.theQoS.begin(); p != record.theQoS.end(); ++p) + for (auto p = record.theQoS.begin(); p != record.theQoS.end(); ++p) { if (p != record.theQoS.begin()) { @@ -1061,7 +1061,7 @@ TopicImpl::observerRemoveSubscriber(const LogUpdate& llu, const Ice::IdentitySeq { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << ": remove replica observer: "; - for (Ice::IdentitySeq::const_iterator id = ids.begin(); id != ids.end(); ++id) + for (auto id = ids.begin(); id != ids.end(); ++id) { if (id != ids.begin()) { diff --git a/cpp/src/IceStorm/TopicManagerI.cpp b/cpp/src/IceStorm/TopicManagerI.cpp index 27a0c04f6a1..bee49f092ee 100644 --- a/cpp/src/IceStorm/TopicManagerI.cpp +++ b/cpp/src/IceStorm/TopicManagerI.cpp @@ -339,9 +339,9 @@ TopicManagerImpl::retrieveAll() reap(); TopicDict all; - for (auto p = _topics.begin(); p != _topics.end(); ++p) + for (const auto& topic : _topics) { - all.insert({p->first, p->second->proxy()}); + all.insert({topic.first, topic.second->proxy()}); } return all; @@ -385,7 +385,7 @@ TopicManagerImpl::observerInit(const LogUpdate& llu, const TopicContentSeq& cont _subscriberMap.clear(txn); - for (TopicContentSeq::const_iterator p = content.begin(); p != content.end(); ++p) + for (auto p = content.begin(); p != content.end(); ++p) for (const auto& c : content) { SubscriberRecordKey srkey; @@ -449,17 +449,17 @@ TopicManagerImpl::observerInit(const LogUpdate& llu, const TopicContentSeq& cont // Now run through the contents updating the topics that do exist, // and creating those that do not. - for (auto q = content.cbegin(); q != content.cend(); ++q) + for (const auto& q : content) { - string name = identityToTopicName(q->id); + string name = identityToTopicName(q.id); auto r = _topics.find(name); if (r == _topics.end()) { - installTopic(name, q->id, true, q->records); + installTopic(name, q.id, true, q.records); } else { - r->second->update(q->records); + r->second->update(q.records); } } // Clear the set of observers. diff --git a/cpp/src/IceStorm/TraceLevels.h b/cpp/src/IceStorm/TraceLevels.h index 46d318b8e4b..4798b538a21 100644 --- a/cpp/src/IceStorm/TraceLevels.h +++ b/cpp/src/IceStorm/TraceLevels.h @@ -12,7 +12,7 @@ namespace IceStorm { - class TraceLevels // NOLINT:clang-analyzer-optin.performance.Padding + class TraceLevels // NOLINT(clang-analyzer-optin.performance.Padding) { public: TraceLevels(const Ice::PropertiesPtr&, Ice::LoggerPtr); diff --git a/cpp/src/IceStorm/TransientTopicI.cpp b/cpp/src/IceStorm/TransientTopicI.cpp index d7548ee5c16..22cf4a89f08 100644 --- a/cpp/src/IceStorm/TransientTopicI.cpp +++ b/cpp/src/IceStorm/TransientTopicI.cpp @@ -147,7 +147,7 @@ TransientTopicImpl::subscribeAndGetPublisher(QoS qos, optional o if (traceLevels->topic > 1) { out << " endpoints: " << IceStormInternal::describeEndpoints(obj) << " QoS: "; - for (QoS::const_iterator p = qos.begin(); p != qos.end(); ++p) + for (auto p = qos.begin(); p != qos.end(); ++p) { if (p != qos.begin()) { @@ -220,7 +220,7 @@ void TransientTopicImpl::link(optional topic, int cost, const Ice::Current& current) { checkNotNull(topic, __FILE__, __LINE__, current); - TopicInternalPrx internal = Ice::uncheckedCast(*topic); + auto internal = Ice::uncheckedCast(*topic); auto link = internal->getLinkProxy(); auto traceLevels = _instance->traceLevels(); diff --git a/cpp/src/Slice/FileTracker.cpp b/cpp/src/Slice/FileTracker.cpp index da03c03f9d6..386fe62b3dc 100644 --- a/cpp/src/Slice/FileTracker.cpp +++ b/cpp/src/Slice/FileTracker.cpp @@ -52,7 +52,7 @@ Slice::FileTracker::error() void Slice::FileTracker::addFile(const string& file) { - _files.push_front(make_pair(file, false)); + _files.emplace_front(file, false); if (_curr != _generated.end()) { _curr->second.push_back(file); @@ -62,21 +62,21 @@ Slice::FileTracker::addFile(const string& file) void Slice::FileTracker::addDirectory(const string& dir) { - _files.push_front(make_pair(dir, true)); + _files.emplace_front(dir, true); } void Slice::FileTracker::cleanup() { - for (list>::const_iterator p = _files.begin(); p != _files.end(); ++p) + for (const auto& file : _files) { - if (!p->second) + if (!file.second) { - IceInternal::unlink(p->first); + IceInternal::unlink(file.first); } else { - IceInternal::rmdir(p->first); + IceInternal::rmdir(file.first); } } } @@ -86,14 +86,14 @@ Slice::FileTracker::dumpxml() { consoleOut << "" << endl; consoleOut << ""; - for (map>::const_iterator p = _generated.begin(); p != _generated.end(); ++p) + for (const auto& p : _generated) { - if (!p->second.empty()) + if (!p.second.empty()) { - consoleOut << endl << " first << "\">"; - for (list::const_iterator q = p->second.begin(); q != p->second.end(); ++q) + consoleOut << endl << " "; + for (const auto& q : p.second) { - consoleOut << endl << " "; + consoleOut << endl << " "; } consoleOut << endl << " "; } diff --git a/cpp/src/Slice/MetadataValidation.cpp b/cpp/src/Slice/MetadataValidation.cpp index 3cbe76e80fa..01eeed40a59 100644 --- a/cpp/src/Slice/MetadataValidation.cpp +++ b/cpp/src/Slice/MetadataValidation.cpp @@ -250,7 +250,7 @@ MetadataVisitor::validate(MetadataList metadata, const SyntaxTreeBasePtr& p, boo // Iterate through the provided metadata and check each one for validity. // If we come across any invalid metadata, we remove it from the list (i.e. we filter out invalid metadata). - for (MetadataList::const_iterator i = metadata.begin(); i != metadata.end();) + for (auto i = metadata.begin(); i != metadata.end();) { const string& directive = (*i)->directive(); diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 8e042d22e3a..1105e8a4ee7 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -1780,9 +1780,9 @@ Slice::Container::lookupTypeNoBuiltin(const string& identifier, bool emitErrors, // Do not emit errors if there was a type error but a match was found in a higher scope. if (emitErrors && !(typeError && !results.empty())) { - for (vector::const_iterator p = errors.begin(); p != errors.end(); ++p) + for (const auto& error : errors) { - _unit->error(*p); + _unit->error(error); } } return results; @@ -2083,7 +2083,7 @@ Slice::Container::checkIntroduced(const string& scopedName, ContainedPtr namedTh } // Check if the first component is in the introduced map of this scope. - map::const_iterator it = _introducedMap.find(firstComponent); + auto it = _introducedMap.find(firstComponent); if (it == _introducedMap.end()) { // We've just introduced the first component to the current scope. @@ -2789,11 +2789,11 @@ Slice::InterfaceDecl::checkBasesAreLegal(const string& name, const InterfaceList // the union of the names defined in classes on each path are disjoint. // GraphPartitionList gpl; - for (InterfaceList::const_iterator p = bases.begin(); p != bases.end(); ++p) + for (const auto& base : bases) { InterfaceList cl; gpl.push_back(cl); - addPartition(gpl, gpl.rbegin(), *p); + addPartition(gpl, gpl.rbegin(), base); } // @@ -2866,7 +2866,7 @@ Slice::InterfaceDecl::addPartition( if (base->bases().size() > 1) { InterfaceList grandBases = base->bases(); - InterfaceList::const_iterator i = grandBases.begin(); + auto i = grandBases.begin(); while (++i != grandBases.end()) { InterfaceList cl; @@ -2911,35 +2911,35 @@ Slice::InterfaceDecl::checkPairIntersections( const UnitPtr& unit) { set reported; - for (StringPartitionList::const_iterator i = stringPartitions.begin(); i != stringPartitions.end(); ++i) + for (auto i = stringPartitions.begin(); i != stringPartitions.end(); ++i) { - StringPartitionList::const_iterator cursor = i; + auto cursor = i; ++cursor; - for (StringPartitionList::const_iterator j = cursor; j != stringPartitions.end(); ++j) + for (auto j = cursor; j != stringPartitions.end(); ++j) { - for (StringList::const_iterator s1 = i->begin(); s1 != i->end(); ++s1) + for (const auto& s1 : *i) { - for (StringList::const_iterator s2 = j->begin(); s2 != j->end(); ++s2) + for (const auto& s2 : *j) { - if ((*s1) == (*s2) && reported.find(*s1) == reported.end()) + if (s1 == s2 && reported.find(s1) == reported.end()) { ostringstream os; - os << "ambiguous multiple inheritance: '" << name << "' inherits operation '" << (*s1) + os << "ambiguous multiple inheritance: '" << name << "' inherits operation '" << s1 << "' from two or more unrelated base interfaces"; unit->error(os.str()); - reported.insert(*s1); + reported.insert(s1); } else if ( - !CICompare()(*s1, *s2) && !CICompare()(*s2, *s1) && reported.find(*s1) == reported.end() && - reported.find(*s2) == reported.end()) + !CICompare()(s1, s2) && !CICompare()(s2, s1) && reported.find(s1) == reported.end() && + reported.find(s2) == reported.end()) { ostringstream os; - os << "ambiguous multiple inheritance: '" << name << "' inherits operations '" << (*s1) - << "' and '" << (*s2) + os << "ambiguous multiple inheritance: '" << name << "' inherits operations '" << s1 + << "' and '" << s2 << "', which differ only in capitalization, from unrelated base interfaces"; unit->error(os.str()); - reported.insert(*s1); - reported.insert(*s2); + reported.insert(s1); + reported.insert(s2); } } } @@ -3154,7 +3154,7 @@ Slice::InterfaceDef::ids() const InterfaceList bases = allBases(); std::transform(bases.begin(), bases.end(), back_inserter(ids), [](const auto& c) { return c->scoped(); }); ids.push_back(scoped()); - ids.push_back("::Ice::Object"); + ids.emplace_back("::Ice::Object"); ids.sort(); ids.unique(); return ids; @@ -3430,7 +3430,7 @@ Slice::Operation::setExceptionList(const ExceptionList& exceptions) { os << "s"; } - ExceptionList::const_iterator i = duplicates.begin(); + auto i = duplicates.begin(); os << ": '" << (*i)->name() << "'"; for (i = ++i; i != duplicates.end(); ++i) { @@ -4861,7 +4861,7 @@ Slice::Unit::popDefinitionContext() DefinitionContextPtr Slice::Unit::findDefinitionContext(string_view file) const { - map::const_iterator p = _definitionContextMap.find(file); + auto p = _definitionContextMap.find(file); if (p != _definitionContextMap.end()) { return p->second; @@ -4883,7 +4883,7 @@ Slice::Unit::findContents(const string& scopedName) const assert(scopedName[0] == ':'); string name = IceInternal::toLower(scopedName); - map::const_iterator p = _contentMap.find(name); + auto p = _contentMap.find(name); if (p != _contentMap.end()) { return p->second; @@ -4903,7 +4903,7 @@ Slice::Unit::addTypeId(int compactId, const std::string& typeId) std::string Slice::Unit::getTypeId(int compactId) const { - map::const_iterator p = _typeIds.find(compactId); + auto p = _typeIds.find(compactId); if (p != _typeIds.end()) { return p->second; @@ -4996,7 +4996,7 @@ Slice::Unit::visit(ParserVisitor* visitor) BuiltinPtr Slice::Unit::createBuiltin(Builtin::Kind kind) { - map::const_iterator p = _builtins.find(kind); + auto p = _builtins.find(kind); if (p != _builtins.end()) { return p->second; @@ -5009,7 +5009,7 @@ Slice::Unit::createBuiltin(Builtin::Kind kind) void Slice::Unit::addTopLevelModule(const string& file, const string& module) { - map>::iterator i = _fileTopLevelModules.find(file); + auto i = _fileTopLevelModules.find(file); if (i == _fileTopLevelModules.end()) { set modules; @@ -5025,7 +5025,7 @@ Slice::Unit::addTopLevelModule(const string& file, const string& module) set Slice::Unit::getTopLevelModules(const string& file) const { - map>::const_iterator i = _fileTopLevelModules.find(file); + auto i = _fileTopLevelModules.find(file); if (i == _fileTopLevelModules.end()) { return set(); diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 94bb8dbcfb5..27e5b48c24d 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -347,7 +347,7 @@ namespace Slice [[nodiscard]] std::string kindAsString() const; static std::optional kindFromString(std::string_view str); - // NOLINTNEXTLINE:cert-err58-cpp + // NOLINTNEXTLINE(cert-err58-cpp) inline static const std::array builtinTable = {"byte", "bool", "short", "int", "long", "float", "double", "string", "Object", "Object*", "Value"}; diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 5d1bdcc8719..837c117bb74 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -131,20 +131,20 @@ namespace { if (keepComments) { - args.push_back("-C"); + args.emplace_back("-C"); } - args.push_back("-e"); - args.push_back("en_us.utf8"); + args.emplace_back("-e"); + args.emplace_back("en_us.utf8"); // // Define version macros __ICE_VERSION__ is preferred. We keep // ICE_VERSION for backward compatibility with 3.5.0. // const string version[2] = {"ICE_VERSION", "__ICE_VERSION__"}; - for (int i = 0; i < 2; ++i) + for (const auto& i : version) { ostringstream os; - os << "-D" << version[i] << "=" << ICE_INT_VERSION; + os << "-D" << i << "=" << ICE_INT_VERSION; args.push_back(os.str()); } @@ -187,14 +187,14 @@ Slice::Preprocessor::preprocess(bool keepComments, const string& languageArg) if (err) { vector messages = filterMcppWarnings(err); - for (vector::const_iterator i = messages.begin(); i != messages.end(); ++i) + for (const auto& message : messages) { - emitRaw(i->c_str()); + emitRaw(message.c_str()); // // MCPP FIX: mcpp does not always return non-zero exit status when there is an error. // - if (i->find("error:") != string::npos) + if (message.find("error:") != string::npos) { status = 1; } @@ -297,7 +297,7 @@ Slice::Preprocessor::printMakefileDependencies( // Build arguments list. // vector args = _args; - args.push_back("-M"); + args.emplace_back("-M"); args = baseArgs(args, false, languageArg, _fileName); const char** argv = new const char*[args.size() + 1]; @@ -320,9 +320,9 @@ Slice::Preprocessor::printMakefileDependencies( if (err) { vector messages = filterMcppWarnings(err); - for (vector::const_iterator i = messages.begin(); i != messages.end(); ++i) + for (const auto& message : messages) { - emitRaw(i->c_str()); + emitRaw(message.c_str()); } } @@ -404,9 +404,9 @@ Slice::Preprocessor::printMakefileDependencies( } vector fullIncludePaths; - for (vector::const_iterator p = includePaths.begin(); p != includePaths.end(); ++p) + for (const auto& includePath : includePaths) { - fullIncludePaths.push_back(fullPath(*p)); + fullIncludePaths.push_back(fullPath(includePath)); } // @@ -435,7 +435,7 @@ Slice::Preprocessor::printMakefileDependencies( // include paths. // string newFile = file; - for (vector::const_iterator p = fullIncludePaths.begin(); p != fullIncludePaths.end(); ++p) + for (auto p = fullIncludePaths.begin(); p != fullIncludePaths.end(); ++p) { if (file.compare(0, p->length(), *p) == 0) { @@ -500,7 +500,7 @@ Slice::Preprocessor::printMakefileDependencies( else if (lang == JavaScriptJSON) { result = "\"" + sourceFile + "\":" + (dependencies.empty() ? "[]" : "["); - for (vector::const_iterator i = dependencies.begin(); i != dependencies.end();) + for (auto i = dependencies.begin(); i != dependencies.end();) { string file = *i; result += "\n \"" + file + "\""; diff --git a/cpp/src/Slice/SliceUtil.cpp b/cpp/src/Slice/SliceUtil.cpp index 380fbe5a160..7968c4cce79 100644 --- a/cpp/src/Slice/SliceUtil.cpp +++ b/cpp/src/Slice/SliceUtil.cpp @@ -169,13 +169,13 @@ Slice::changeInclude(const string& p, const vector& includePaths) paths.push_back(canonicalPath); } - for (vector::const_iterator i = paths.begin(); i != paths.end(); ++i) + for (const auto& i : paths) { - for (vector::const_iterator j = includePaths.begin(); j != includePaths.end(); ++j) + for (const auto& includePath : includePaths) { - if (i->compare(0, j->length(), *j) == 0) + if (i.compare(0, includePath.length(), includePath) == 0) { - string s = i->substr(j->length() + 1); // + 1 for the '/' + string s = i.substr(includePath.length() + 1); // + 1 for the '/' if (s.size() < result.size()) { result = s; @@ -263,7 +263,7 @@ Slice::filterMcppWarnings(const string& message) } vector out; bool skipped; - for (vector::const_iterator i = in.begin(); i != in.end(); i++) + for (auto i = in.begin(); i != in.end(); i++) { skipped = false; @@ -383,7 +383,7 @@ Slice::argvToArgs(int argc, char* argv[]) vector args; for (int i = 0; i < argc; i++) { - args.push_back(argv[i]); + args.emplace_back(argv[i]); } return args; } @@ -418,7 +418,7 @@ Slice::splitScopedName(const string& scoped, bool allowEmpty) } else if (allowEmpty) { - ids.push_back(""); + ids.emplace_back(""); } return ids; @@ -475,11 +475,11 @@ Slice::checkIdentifier(const string& identifier) // check the identifier for reserved suffixes static const string suffixBlacklist[] = {"Helper", "Holder", "Prx", "Ptr"}; - for (size_t i = 0; i < sizeof(suffixBlacklist) / sizeof(*suffixBlacklist); ++i) + for (const auto& i : suffixBlacklist) { - if (name.find(suffixBlacklist[i], name.size() - suffixBlacklist[i].size()) != string::npos) + if (name.find(i, name.size() - i.size()) != string::npos) { - currentUnit->error("illegal identifier '" + name + "': '" + suffixBlacklist[i] + "' suffix is reserved"); + currentUnit->error("illegal identifier '" + name + "': '" + i + "' suffix is reserved"); isValid = false; break; } diff --git a/cpp/src/Slice/StringLiteralUtil.cpp b/cpp/src/Slice/StringLiteralUtil.cpp index c9b1fac90b3..68891baf5f1 100644 --- a/cpp/src/Slice/StringLiteralUtil.cpp +++ b/cpp/src/Slice/StringLiteralUtil.cpp @@ -223,9 +223,9 @@ namespace vector u8buffer = fromUTF32(u32buffer); ostringstream os; - for (vector::const_iterator q = u8buffer.begin(); q != u8buffer.end(); ++q) + for (unsigned char& q : u8buffer) { - os << "\\" << setfill('0') << setw(3) << oct << static_cast(*q); + os << "\\" << setfill('0') << setw(3) << oct << static_cast(q); } _format = OctalFormat; return os.str(); @@ -280,9 +280,9 @@ namespace ostringstream os; vector u32buffer = toUTF32(u8buffer); - for (vector::const_iterator p = u32buffer.begin(); p != u32buffer.end(); ++p) + for (unsigned int& p : u32buffer) { - os << escapeCodePoint(*p); + os << escapeCodePoint(p); } u8buffer.clear(); return os.str(); diff --git a/cpp/src/ice2slice/Gen.cpp b/cpp/src/ice2slice/Gen.cpp index b85e7fd4198..8a621fab269 100644 --- a/cpp/src/ice2slice/Gen.cpp +++ b/cpp/src/ice2slice/Gen.cpp @@ -250,7 +250,7 @@ namespace { ostringstream os; os << "("; - for (ParamInfoList::const_iterator q = params.begin(); q != params.end();) + for (auto q = params.begin(); q != params.end();) { os << paramToString(*q, scope); q++; @@ -314,7 +314,7 @@ namespace // Input parameters for (const auto& param : operation->inParameters()) { - std::map::const_iterator q = parameterDocs.find(param->name()); + auto q = parameterDocs.find(param->name()); if (q != parameterDocs.end()) { out << nl << "/// @param " << param->name() << ": "; @@ -325,7 +325,7 @@ namespace // Output parameters for (const auto& param : operation->outParameters()) { - std::map::const_iterator q = parameterDocs.find(param->name()); + auto q = parameterDocs.find(param->name()); if (q != parameterDocs.end()) { out << nl << "/// @returns"; @@ -520,7 +520,7 @@ Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (bases.size() > 0) { out << " :"; - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end();) + for (auto q = bases.begin(); q != bases.end();) { InterfaceDefPtr base = *q; out << " " << getUnqualified(base, scope); @@ -534,7 +534,7 @@ Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) out << " {"; out.inc(); OperationList operations = p->operations(); - for (OperationList::const_iterator q = operations.begin(); q != operations.end();) + for (auto q = operations.begin(); q != operations.end();) { OperationPtr op = *q; writeDocComment(op, out); @@ -568,7 +568,7 @@ Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) else if (throws.size() > 1) { out << " throws ("; - for (ExceptionList::const_iterator r = throws.begin(); r != throws.end();) + for (auto r = throws.begin(); r != throws.end();) { ExceptionPtr ex = *r; out << getUnqualified(ex, scope); diff --git a/cpp/src/ice2slice/Main.cpp b/cpp/src/ice2slice/Main.cpp index 0858411eae6..b57ebedcaf2 100644 --- a/cpp/src/ice2slice/Main.cpp +++ b/cpp/src/ice2slice/Main.cpp @@ -93,21 +93,21 @@ compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + optarg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + optarg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -140,16 +140,16 @@ compile(const vector& argv) // Create a copy of args without the duplicates. vector sources; - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (const auto& arg : args) { - vector::iterator p = find(sources.begin(), sources.end(), *i); + auto p = find(sources.begin(), sources.end(), arg); if (p == sources.end()) { - sources.push_back(*i); + sources.push_back(arg); } } - for (vector::const_iterator i = sources.begin(); i != sources.end();) + for (auto i = sources.begin(); i != sources.end();) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); FILE* cppHandle = icecpp->preprocess(true, "-D__ICE2SLICE__"); diff --git a/cpp/src/icegriddb/IceGridDB.cpp b/cpp/src/icegriddb/IceGridDB.cpp index 5febca632c0..59ee7853ee8 100644 --- a/cpp/src/icegriddb/IceGridDB.cpp +++ b/cpp/src/icegriddb/IceGridDB.cpp @@ -265,15 +265,13 @@ run(const Ice::StringSeq& args) dbContext, MDB_CREATE); - for (IceGrid::ApplicationInfoSeq::const_iterator p = data.applications.begin(); - p != data.applications.end(); - ++p) + for (const auto& application : data.applications) { if (debug) { - consoleOut << " NAME = " << p->descriptor.name << endl; + consoleOut << " NAME = " << application.descriptor.name << endl; } - apps.put(txn, p->descriptor.name, *p); + apps.put(txn, application.descriptor.name, application); } if (debug) @@ -287,13 +285,13 @@ run(const Ice::StringSeq& args) dbContext, MDB_CREATE); - for (IceGrid::AdapterInfoSeq::const_iterator p = data.adapters.begin(); p != data.adapters.end(); ++p) + for (const auto& adapter : data.adapters) { if (debug) { - consoleOut << " NAME = " << p->id << endl; + consoleOut << " NAME = " << adapter.id << endl; } - adpts.put(txn, p->id, *p); + adpts.put(txn, adapter.id, adapter); } if (debug) @@ -307,14 +305,14 @@ run(const Ice::StringSeq& args) dbContext, MDB_CREATE); - for (IceGrid::ObjectInfoSeq::const_iterator p = data.objects.begin(); p != data.objects.end(); ++p) + for (const auto& object : data.objects) { if (debug) { - consoleOut << " NAME = " << communicator->identityToString(p->proxy->ice_getIdentity()) + consoleOut << " NAME = " << communicator->identityToString(object.proxy->ice_getIdentity()) << endl; } - objs.put(txn, p->proxy->ice_getIdentity(), *p); + objs.put(txn, object.proxy->ice_getIdentity(), object); } if (debug) @@ -328,16 +326,14 @@ run(const Ice::StringSeq& args) dbContext, MDB_CREATE); - for (IceGrid::ObjectInfoSeq::const_iterator p = data.internalObjects.begin(); - p != data.internalObjects.end(); - ++p) + for (const auto& internalObject : data.internalObjects) { if (debug) { - consoleOut << " NAME = " << communicator->identityToString(p->proxy->ice_getIdentity()) - << endl; + consoleOut << " NAME = " + << communicator->identityToString(internalObject.proxy->ice_getIdentity()) << endl; } - internalObjs.put(txn, p->proxy->ice_getIdentity(), *p); + internalObjs.put(txn, internalObject.proxy->ice_getIdentity(), internalObject); } if (debug) @@ -351,13 +347,13 @@ run(const Ice::StringSeq& args) dbContext, MDB_CREATE); - for (IceGrid::StringLongDict::const_iterator p = data.serials.begin(); p != data.serials.end(); ++p) + for (const auto& serial : data.serials) { if (debug) { - consoleOut << " NAME = " << p->first << endl; + consoleOut << " NAME = " << serial.first << endl; } - srls.put(txn, p->first, p->second); + srls.put(txn, serial.first, serial.second); } txn.commit(); diff --git a/cpp/src/slice2cpp/CPlusPlusUtil.cpp b/cpp/src/slice2cpp/CPlusPlusUtil.cpp index 52d65b2176e..41a59ead5bf 100644 --- a/cpp/src/slice2cpp/CPlusPlusUtil.cpp +++ b/cpp/src/slice2cpp/CPlusPlusUtil.cpp @@ -202,15 +202,15 @@ namespace // ParameterList requiredParams; ParameterList optionals; - for (ParameterList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { - if ((*p)->optional()) + if (param->optional()) { - optionals.push_back(*p); + optionals.push_back(param); } else { - requiredParams.push_back(*p); + requiredParams.push_back(param); } } @@ -228,16 +228,17 @@ namespace out << stream << "->readAll"; } out << spar; - for (ParameterList::const_iterator p = requiredParams.begin(); p != requiredParams.end(); ++p) + for (const auto& requiredParam : requiredParams) { if (tuple) { - auto index = std::distance(params.begin(), std::find(params.begin(), params.end(), *p)) + retOffset; + auto index = std::distance(params.begin(), std::find(params.begin(), params.end(), requiredParam)) + + retOffset; out << "::std::get<" + std::to_string(index) + ">(v)"; } else { - out << fixKwd(paramPrefix + (*p)->name()); + out << fixKwd(paramPrefix + requiredParam->name()); } } if (op && op->returnType() && !op->returnIsOptional()) @@ -288,15 +289,15 @@ namespace os << '{'; bool checkReturnType = op && op->returnIsOptional(); bool insertComma = false; - for (ParameterList::const_iterator p = optionals.begin(); p != optionals.end(); ++p) + for (const auto& optional : optionals) { - if (checkReturnType && op->returnTag() < (*p)->tag()) + if (checkReturnType && op->returnTag() < optional->tag()) { os << (insertComma ? ", " : "") << op->returnTag(); checkReturnType = false; insertComma = true; } - os << (insertComma ? ", " : "") << (*p)->tag(); + os << (insertComma ? ", " : "") << optional->tag(); insertComma = true; } if (checkReturnType) @@ -312,9 +313,9 @@ namespace // Parameters // bool checkReturnType = op && op->returnIsOptional(); - for (ParameterList::const_iterator p = optionals.begin(); p != optionals.end(); ++p) + for (const auto& optional : optionals) { - if (checkReturnType && op->returnTag() < (*p)->tag()) + if (checkReturnType && op->returnTag() < optional->tag()) { if (tuple) { @@ -329,13 +330,13 @@ namespace if (tuple) { - auto index = - std::distance(params.begin(), std::find(params.begin(), params.end(), *p)) + retOffset; + auto index = std::distance(params.begin(), std::find(params.begin(), params.end(), optional)) + + retOffset; out << "::std::get<" + std::to_string(index) + ">(v)"; } else { - out << fixKwd(paramPrefix + (*p)->name()); + out << fixKwd(paramPrefix + optional->name()); } } if (checkReturnType) @@ -355,7 +356,7 @@ namespace } } -string Slice::paramPrefix = "iceP_"; // NOLINT:cert-err58-cpp +string Slice::paramPrefix = "iceP_"; // NOLINT(cert-err58-cpp) char Slice::ToIfdef::operator()(char c) @@ -790,9 +791,9 @@ Slice::fixKwd(const string& name) vector ids = splitScopedName(name); transform(ids.begin(), ids.end(), ids.begin(), [](const string& id) -> string { return lookupKwd(id); }); stringstream result; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (const auto& id : ids) { - result << "::" + *i; + result << "::" + id; } return result.str(); } @@ -937,7 +938,7 @@ Slice::writeIceTuple(::IceInternal::Output& out, const DataMemberList& dataMembe // Use an empty scope to get full qualified names from calls to typeToString. const string scope = ""; out << nl << "[[nodiscard]] std::tuple<"; - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (auto q = dataMembers.begin(); q != dataMembers.end(); ++q) { if (q != dataMembers.begin()) { @@ -950,7 +951,7 @@ Slice::writeIceTuple(::IceInternal::Output& out, const DataMemberList& dataMembe out << sb; out << nl << "return std::tie("; - for (DataMemberList::const_iterator pi = dataMembers.begin(); pi != dataMembers.end(); ++pi) + for (auto pi = dataMembers.begin(); pi != dataMembers.end(); ++pi) { if (pi != dataMembers.begin()) { diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index f4af67cd65c..d22fc93c786 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -59,9 +59,9 @@ namespace if (s) { DataMemberList members = s->dataMembers(); - for (DataMemberList::const_iterator i = members.begin(); i != members.end(); ++i) + for (const auto& member : members) { - if (!isConstexprType((*i)->type())) + if (!isConstexprType(member->type())) { return false; } @@ -308,7 +308,7 @@ namespace { // Extract the first sentence. ostringstream ostr; - for (StringList::const_iterator i = lines.begin(); i != lines.end(); ++i) + for (auto i = lines.begin(); i != lines.end(); ++i) { const string ws = " \t"; @@ -451,7 +451,7 @@ namespace map paramDoc = doc->parameters(); for (const auto& param : params) { - map::iterator q = paramDoc.find(param->name()); + auto q = paramDoc.find(param->name()); if (q != paramDoc.end()) { out << nl << "/// @param " << fixKwd(q->first) << " "; @@ -604,9 +604,9 @@ Slice::Gen::Gen( _dllExport(std::move(dllExport)), _dir(std::move(dir)) { - for (vector::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) + for (auto& includePath : _includePaths) { - *p = fullPath(*p); + includePath = fullPath(includePath); } string::size_type pos = _base.find_last_of("/\\"); @@ -1087,14 +1087,14 @@ Slice::Gen::ForwardDeclVisitor::visitEnum(const EnumPtr& p) if (p->maxValue() > numeric_limits::max() && p->maxValue() <= numeric_limits::max()) { - H << " // NOLINT:performance-enum-size"; + H << " // NOLINT(performance-enum-size)"; } H << sb; // Check if any of the enumerators were assigned an explicit value. EnumeratorList enumerators = p->enumerators(); const bool hasExplicitValues = p->hasExplicitValues(); - for (EnumeratorList::const_iterator en = enumerators.begin(); en != enumerators.end();) + for (auto en = enumerators.begin(); en != enumerators.end();) { writeDocSummary(H, *en); H << nl << fixKwd((*en)->name()); @@ -1199,7 +1199,7 @@ Slice::Gen::ForwardDeclVisitor::visitConst(const ConstPtr& p) if (!isConstexprType(p->type())) // i.e. string or wstring { // The string/wstring constructor can throw, which produces a clang-tidy lint for const or static objects. - H << " // NOLINT:cert-err58-cpp"; + H << " // NOLINT(cert-err58-cpp)"; } H << sp; } @@ -1312,7 +1312,7 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } else { - InterfaceList::const_iterator q = bases.begin(); + auto q = bases.begin(); while (q != bases.end()) { H << getUnqualified(fixKwd((*q)->scoped() + "Prx"), scope); @@ -1360,13 +1360,13 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) // We can't use "= default" for the copy/move ctor/assignment operator as it's not correct with virtual inheritance. H << sp; H << nl << prx << "(const " << prx << "& other) noexcept : ::Ice::ObjectPrx(other)"; - H << " {} // NOLINT:modernize-use-equals-default"; + H << " {} // NOLINT(modernize-use-equals-default)"; H << sp; H << nl << prx << "(" << prx << "&& other) noexcept : ::Ice::ObjectPrx(std::move(other))"; - H << " {} // NOLINT:modernize-use-equals-default"; + H << " {} // NOLINT(modernize-use-equals-default)"; H << sp; H << nl << prx << "(const ::Ice::CommunicatorPtr& communicator, std::string_view proxyString)"; - H << " : ::Ice::ObjectPrx(communicator, proxyString) {} // NOLINT:modernize-use-equals-default"; + H << " : ::Ice::ObjectPrx(communicator, proxyString) {} // NOLINT(modernize-use-equals-default)"; H << sp; H << nl << prx << "& operator=(const " << prx << "& rhs) noexcept"; H << sb; @@ -1524,7 +1524,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) // We don't want to add [[nodiscard]] to proxy member functions. if (ret && p->outParameters().empty()) { - H << " // NOLINT:modernize-use-nodiscard"; + H << " // NOLINT(modernize-use-nodiscard)"; } C << sp; @@ -1623,7 +1623,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) postParams.push_back("@param " + exParam + " The exception callback."); postParams.push_back("@param " + sentParam + " The sent callback."); postParams.push_back(contextDoc); - returns.push_back("A function that can be called to cancel the invocation locally."); + returns.emplace_back("A function that can be called to cancel the invocation locally."); writeOpDocSummary( H, p, @@ -1637,7 +1637,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) } H << nl; H << deprecatedAttribute; - H << "::std::function // NOLINT:modernize-use-nodiscard"; + H << "::std::function // NOLINT(modernize-use-nodiscard)"; // TODO: need "nl" version of spar/epar H << nl << name << "Async" << spar; @@ -1961,7 +1961,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) H << nl << "/// One-shot constructor to initialize all data members."; for (const auto& dataMember : allDataMembers) { - map::iterator r = allDocComments.find(dataMember->name()); + auto r = allDocComments.find(dataMember->name()); if (r != allDocComments.end()) { H << nl << "/// @param " << fixKwd(r->first) << " " << getDocSentence(r->second->overview()); @@ -1969,7 +1969,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) } H << nl << name << "("; - for (vector::const_iterator q = allParameters.begin(); q != allParameters.end(); ++q) + for (auto q = allParameters.begin(); q != allParameters.end(); ++q) { if (q != allParameters.begin()) { @@ -1983,7 +1983,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) { H << nl << baseClass << "("; - for (DataMemberList::const_iterator q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) + for (auto q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) { if (q != baseDataMembers.begin()) { @@ -2001,7 +2001,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p) } } - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (auto q = dataMembers.begin(); q != dataMembers.end(); ++q) { string memberName = fixKwd((*q)->name()); TypePtr memberType = (*q)->type(); @@ -2348,7 +2348,7 @@ Slice::Gen::DataDefVisitor::emitBaseInitializers(const ClassDefPtr& p) const string scope = fixKwd(p->scope()); string upcall = "("; - for (DataMemberList::const_iterator q = allBaseDataMembers.begin(); q != allBaseDataMembers.end(); ++q) + for (auto q = allBaseDataMembers.begin(); q != allBaseDataMembers.end(); ++q) { string memberName = fixKwd((*q)->name()); TypePtr memberType = (*q)->type(); @@ -2392,7 +2392,7 @@ Slice::Gen::DataDefVisitor::emitOneShotConstructor(const ClassDefPtr& p) H << nl << "/// One-shot constructor to initialize all data members."; for (const auto& dataMember : allDataMembers) { - map::iterator r = allDocComments.find(dataMember->name()); + auto r = allDocComments.find(dataMember->name()); if (r != allDocComments.end()) { H << nl << "/// @param " << fixKwd(r->first) << " " << getDocSentence(r->second->overview()); @@ -2419,7 +2419,7 @@ Slice::Gen::DataDefVisitor::emitOneShotConstructor(const ClassDefPtr& p) H << nl; } - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (auto q = dataMembers.begin(); q != dataMembers.end(); ++q) { if (q != dataMembers.begin()) { @@ -2520,7 +2520,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } else { - InterfaceList::const_iterator q = bases.begin(); + auto q = bases.begin(); while (q != bases.end()) { string baseScoped = fixKwd((*q)->scope() + (*q)->name()); @@ -2615,10 +2615,10 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) allOps.end(), back_inserter(allOpNames), [](const ContainedPtr& it) { return it->name(); }); - allOpNames.push_back("ice_id"); - allOpNames.push_back("ice_ids"); - allOpNames.push_back("ice_isA"); - allOpNames.push_back("ice_ping"); + allOpNames.emplace_back("ice_id"); + allOpNames.emplace_back("ice_ids"); + allOpNames.emplace_back("ice_isA"); + allOpNames.emplace_back("ice_ping"); allOpNames.sort(); H << sp; @@ -2804,20 +2804,20 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) else { params.push_back("::std::function " + responsecbParam); - args.push_back( + args.emplace_back( ret || !outParams.empty() ? "::std::move(responseCb)" : "[responseHandler] { responseHandler->sendEmptyResponse(); }"); } params.push_back("::std::function " + excbParam); - args.push_back("[responseHandler](std::exception_ptr ex) { " - "responseHandler->sendException(ex); }"); + args.emplace_back("[responseHandler](std::exception_ptr ex) { " + "responseHandler->sendException(ex); }"); params.push_back(currentDecl); - args.push_back("responseHandler->current()"); + args.emplace_back("responseHandler->current()"); } else { params.push_back(currentDecl); - args.push_back("request.current()"); + args.emplace_back("request.current()"); } if (p->hasMarshaledResult()) @@ -2843,7 +2843,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) const string mrcurrent = escapeParam(outParams, "current"); for (const auto& param : outParams) { - map::iterator r = paramComments.find(param->name()); + auto r = paramComments.find(param->name()); if (r != paramComments.end()) { H << nl << "/// @param " << fixKwd(r->first) << " " << getDocSentence(r->second); @@ -2885,7 +2885,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) } else if (p->hasMarshaledResult()) { - returns.push_back("The marshaled result structure."); + returns.emplace_back("The marshaled result structure."); } else { @@ -2913,7 +2913,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) { // We want to use the same signature for sync and async dispatch functions. There is no performance penalty for // sync functions since we always move this parameter. - C << " // NOLINT:performance-unnecessary-value-param"; + C << " // NOLINT(performance-unnecessary-value-param)"; } C.dec(); C << sb; diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index c523d577886..8788d175d2b 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -114,22 +114,22 @@ compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + optarg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + optarg); } vector includePaths; includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -184,12 +184,12 @@ compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // // Ignore duplicates. // - vector::iterator p = find(args.begin(), args.end(), *i); + auto p = find(args.begin(), args.end(), *i); if (p != i) { continue; diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index c69dd715877..3c847847345 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -165,12 +165,12 @@ Slice::CsGenerator::fixId(const string& name, unsigned int baseTypes, bool mangl } vector ids = splitScopedName(name); vector newIds; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (const auto& id : ids) { - newIds.push_back(lookupKwd(*i, baseTypes)); + newIds.push_back(lookupKwd(id, baseTypes)); } stringstream result; - for (vector::const_iterator j = newIds.begin(); j != newIds.end(); ++j) + for (auto j = newIds.begin(); j != newIds.end(); ++j) { if (j != newIds.begin()) { @@ -379,9 +379,9 @@ Slice::CsGenerator::isValueType(const TypePtr& type) return false; } DataMemberList dm = s->dataMembers(); - for (DataMemberList::const_iterator i = dm.begin(); i != dm.end(); ++i) + for (const auto& i : dm) { - if (!isValueType((*i)->type()) || (*i)->defaultValueType()) + if (!isValueType(i->type()) || i->defaultValueType()) { return false; } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index e66c85e80de..77e20e844f5 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -94,9 +94,9 @@ namespace { ParameterList params = p->parameters(); - for (ParameterList::const_iterator i = params.begin(); i != params.end(); ++i) + for (const auto& param : params) { - if ((*i)->name() == name) + if (param->name() == name) { return name + "_"; } @@ -106,9 +106,9 @@ namespace string resultStructReturnValueName(const ParameterList& outParams) { - for (ParameterList::const_iterator i = outParams.begin(); i != outParams.end(); ++i) + for (const auto& outParam : outParams) { - if ((*i)->name() == "returnValue") + if (outParam->name() == "returnValue") { return "returnValue_"; } @@ -145,10 +145,10 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( } } - for (ParameterList::const_iterator pli = params.begin(); pli != params.end(); ++pli) + for (const auto& pli : params) { - string param = paramPrefix.empty() && !publicNames ? "iceP_" + (*pli)->name() : fixId((*pli)->name()); - TypePtr type = (*pli)->type(); + string param = paramPrefix.empty() && !publicNames ? "iceP_" + pli->name() : fixId(pli->name()); + TypePtr type = pli->type(); if (!marshal && type->isClassType()) { ostringstream os; @@ -160,9 +160,9 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( param = paramPrefix + param; } - if ((*pli)->optional()) + if (pli->optional()) { - optionals.push_back(*pli); + optionals.push_back(pli); } else { @@ -207,9 +207,9 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( // Handle optional parameters. // bool checkReturnType = op && op->returnIsOptional(); - for (ParameterList::const_iterator pli = optionals.begin(); pli != optionals.end(); ++pli) + for (const auto& optional : optionals) { - if (checkReturnType && op->returnTag() < (*pli)->tag()) + if (checkReturnType && op->returnTag() < optional->tag()) { string param; if (!marshal && ret->isClassType()) @@ -226,8 +226,8 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( checkReturnType = false; } - string param = paramPrefix.empty() && !publicNames ? "iceP_" + (*pli)->name() : fixId((*pli)->name()); - TypePtr type = (*pli)->type(); + string param = paramPrefix.empty() && !publicNames ? "iceP_" + optional->name() : fixId(optional->name()); + TypePtr type = optional->type(); if (!marshal && type->isClassType()) { ostringstream os; @@ -239,7 +239,7 @@ Slice::CsVisitor::writeMarshalUnmarshalParams( param = paramPrefix + param; } - writeOptionalMarshalUnmarshalCode(_out, type, ns, param, (*pli)->tag(), marshal, customStream); + writeOptionalMarshalUnmarshalCode(_out, type, ns, param, optional->tag(), marshal, customStream); } if (checkReturnType) @@ -334,16 +334,16 @@ Slice::CsVisitor::writeMarshaling(const ClassDefPtr& p) _out << nl << "protected override void iceWriteImpl(Ice.OutputStream ostr_)"; _out << sb; _out << nl << "ostr_.startSlice(ice_staticId(), " << p->compactId() << (!base ? ", true" : ", false") << ");"; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - writeMarshalDataMember(*d, fixId((*d)->name(), DotNet::ICloneable, true), ns); + writeMarshalDataMember(member, fixId(member->name(), DotNet::ICloneable, true), ns); } } - for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + for (const auto& optionalMember : optionalMembers) { - writeMarshalDataMember(*d, fixId((*d)->name(), DotNet::ICloneable, true), ns); + writeMarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::ICloneable, true), ns); } _out << nl << "ostr_.endSlice();"; if (base) @@ -356,16 +356,16 @@ Slice::CsVisitor::writeMarshaling(const ClassDefPtr& p) _out << nl << "protected override void iceReadImpl(Ice.InputStream istr_)"; _out << sb; _out << nl << "istr_.startSlice();"; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - writeUnmarshalDataMember(*d, fixId((*d)->name(), DotNet::ICloneable, true), ns); + writeUnmarshalDataMember(member, fixId(member->name(), DotNet::ICloneable, true), ns); } } - for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + for (const auto& optionalMember : optionalMembers) { - writeUnmarshalDataMember(*d, fixId((*d)->name(), DotNet::ICloneable, true), ns); + writeUnmarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::ICloneable, true), ns); } _out << nl << "istr_.endSlice();"; if (base) @@ -395,14 +395,14 @@ Slice::CsVisitor::getParams(const OperationPtr& op, const string& ns) vector params; ParameterList paramList = op->parameters(); InterfaceDefPtr interface = op->interface(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - string param = getParamAttributes(*q); - if ((*q)->isOutParam()) + string param = getParamAttributes(q); + if (q->isOutParam()) { param += "out "; } - param += typeToString((*q)->type(), ns, (*q)->optional()) + " " + fixId((*q)->name()); + param += typeToString(q->type(), ns, q->optional()) + " " + fixId(q->name()); params.push_back(param); } return params; @@ -416,11 +416,11 @@ Slice::CsVisitor::getInParams(const OperationPtr& op, const string& ns, bool int string name = fixId(op->name()); InterfaceDefPtr interface = op->interface(); ParameterList paramList = op->inParameters(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { params.push_back( - getParamAttributes(*q) + typeToString((*q)->type(), ns, (*q)->optional()) + " " + - (internal ? "iceP_" + (*q)->name() : fixId((*q)->name()))); + getParamAttributes(q) + typeToString(q->type(), ns, q->optional()) + " " + + (internal ? "iceP_" + q->name() : fixId(q->name()))); } return params; } @@ -439,14 +439,14 @@ Slice::CsVisitor::getOutParams(const OperationPtr& op, const string& ns, bool re } ParameterList paramList = op->outParameters(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - string s = getParamAttributes(*q); + string s = getParamAttributes(q); if (outKeyword) { s += "out "; } - s += typeToString((*q)->type(), ns, (*q)->optional()) + ' ' + fixId((*q)->name()); + s += typeToString(q->type(), ns, q->optional()) + ' ' + fixId(q->name()); params.push_back(s); } @@ -458,10 +458,10 @@ Slice::CsVisitor::getArgs(const OperationPtr& op) { vector args; ParameterList paramList = op->parameters(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - string arg = fixId((*q)->name()); - if ((*q)->isOutParam()) + string arg = fixId(q->name()); + if (q->isOutParam()) { arg = "out " + arg; } @@ -475,11 +475,11 @@ Slice::CsVisitor::getInArgs(const OperationPtr& op, bool internal) { vector args; ParameterList paramList = op->parameters(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - if (!(*q)->isOutParam()) + if (!q->isOutParam()) { - args.push_back(internal ? "iceP_" + (*q)->name() : fixId((*q)->name())); + args.push_back(internal ? "iceP_" + q->name() : fixId(q->name())); } } return args; @@ -854,7 +854,7 @@ Slice::CsVisitor::splitIntoLines(const string& comment) string::size_type nextPos; while ((nextPos = s.find_first_of('\n', pos)) != string::npos) { - result.push_back(string(s, pos, nextPos - pos)); + result.emplace_back(s, pos, nextPos - pos); pos = nextPos + 1; } string lastLine = string(s, pos); @@ -914,12 +914,12 @@ Slice::CsVisitor::writeDocComment(const ContainedPtr& p, const string& extraPara _out << nl << "/// "; - for (StringList::const_iterator i = summaryLines.begin(); i != summaryLines.end(); ++i) + for (const auto& summaryLine : summaryLines) { _out << nl << "///"; - if (!(*i).empty()) + if (!summaryLine.empty()) { - _out << " " << *i; + _out << " " << summaryLine; } } @@ -927,7 +927,7 @@ Slice::CsVisitor::writeDocComment(const ContainedPtr& p, const string& extraPara if (!remarksLines.empty()) { - for (StringList::const_iterator i = remarksLines.begin(); i != remarksLines.end(); ++i) + for (const auto& remarksLine : remarksLines) { // // The first param, returns, or exception tag ends the description. @@ -936,19 +936,20 @@ Slice::CsVisitor::writeDocComment(const ContainedPtr& p, const string& extraPara static const string returnsTag = "find(paramTag) != string::npos || i->find(returnsTag) != string::npos || - i->find(exceptionTag) != string::npos)) + if (!summaryClosed && + (remarksLine.find(paramTag) != string::npos || remarksLine.find(returnsTag) != string::npos || + remarksLine.find(exceptionTag) != string::npos)) { _out << nl << "/// "; - _out << nl << "/// " << *i; + _out << nl << "/// " << remarksLine; summaryClosed = true; } else { _out << nl << "///"; - if (!(*i).empty()) + if (!remarksLine.empty()) { - _out << " " << *i; + _out << " " << remarksLine; } } } @@ -988,17 +989,17 @@ Slice::CsVisitor::writeDocCommentAMI( // Output the leading comment block up until the first tag. // _out << nl << "/// "; - for (StringList::const_iterator i = summaryLines.begin(); i != summaryLines.end(); ++i) + for (const auto& summaryLine : summaryLines) { _out << nl << "///"; - if (!(*i).empty()) + if (!summaryLine.empty()) { - _out << " " << *i; + _out << " " << summaryLine; } } bool done = false; - for (StringList::const_iterator i = remarksLines.begin(); i != remarksLines.end() && !done; ++i) + for (auto i = remarksLines.begin(); i != remarksLines.end() && !done; ++i) { string::size_type pos = i->find('<'); done = true; @@ -1053,7 +1054,7 @@ Slice::CsVisitor::writeDocCommentAMI( static const string returnsCloseTag = ""; bool doneReturn = false; bool foundReturn = false; - for (StringList::const_iterator i = remarksLines.begin(); i != remarksLines.end() && !doneReturn; ++i) + for (auto i = remarksLines.begin(); i != remarksLines.end() && !doneReturn; ++i) { if (!foundReturn) { @@ -1118,17 +1119,17 @@ Slice::CsVisitor::writeDocCommentTaskAsyncAMI( // Output the leading comment block up until the first tag. // _out << nl << "/// "; - for (StringList::const_iterator i = summaryLines.begin(); i != summaryLines.end(); ++i) + for (const auto& summaryLine : summaryLines) { _out << nl << "///"; - if (!(*i).empty()) + if (!summaryLine.empty()) { - _out << " " << *i; + _out << " " << summaryLine; } } bool done = false; - for (StringList::const_iterator i = remarksLines.begin(); i != remarksLines.end() && !done; ++i) + for (auto i = remarksLines.begin(); i != remarksLines.end() && !done; ++i) { string::size_type pos = i->find('<'); done = true; @@ -1189,17 +1190,17 @@ Slice::CsVisitor::writeDocCommentAMD(const OperationPtr& p, const string& extraP // Output the leading comment block up until the first tag. // _out << nl << "/// "; - for (StringList::const_iterator i = summaryLines.begin(); i != summaryLines.end(); ++i) + for (const auto& summaryLine : summaryLines) { _out << nl << "///"; - if (!(*i).empty()) + if (!summaryLine.empty()) { - _out << " " << *i; + _out << " " << summaryLine; } } bool done = false; - for (StringList::const_iterator i = remarksLines.begin(); i != remarksLines.end() && !done; ++i) + for (auto i = remarksLines.begin(); i != remarksLines.end() && !done; ++i) { string::size_type pos = i->find('<'); done = true; @@ -1242,15 +1243,15 @@ Slice::CsVisitor::writeDocCommentParam(const OperationPtr& p, ParamDir paramType // ParameterList tmp = p->parameters(); vector params; - for (ParameterList::const_iterator q = tmp.begin(); q != tmp.end(); ++q) + for (const auto& q : tmp) { - if ((*q)->isOutParam() && paramType == OutParam) + if (q->isOutParam() && paramType == OutParam) { - params.push_back((*q)->name()); + params.push_back(q->name()); } - else if (!(*q)->isOutParam() && paramType == InParam) + else if (!q->isOutParam() && paramType == InParam) { - params.push_back((*q)->name()); + params.push_back(q->name()); } } @@ -1262,7 +1263,7 @@ Slice::CsVisitor::writeDocCommentParam(const OperationPtr& p, ParamDir paramType splitDocComment(p, summaryLines, remarksLines); const string paramTag = "optional()) + if (!dataMember->optional()) { - writeMarshalDataMember(*q, fixId((*q)->name(), DotNet::Exception), ns); + writeMarshalDataMember(dataMember, fixId(dataMember->name(), DotNet::Exception), ns); } } - for (DataMemberList::const_iterator q = optionalMembers.begin(); q != optionalMembers.end(); ++q) + for (const auto& optionalMember : optionalMembers) { - writeMarshalDataMember(*q, fixId((*q)->name(), DotNet::Exception), ns); + writeMarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::Exception), ns); } _out << nl << "ostr_.endSlice();"; @@ -1868,17 +1869,17 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << sb; _out << nl << "istr_.startSlice();"; - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { - if (!(*q)->optional()) + if (!dataMember->optional()) { - writeUnmarshalDataMember(*q, fixId((*q)->name(), DotNet::Exception), ns); + writeUnmarshalDataMember(dataMember, fixId(dataMember->name(), DotNet::Exception), ns); } } - for (DataMemberList::const_iterator q = optionalMembers.begin(); q != optionalMembers.end(); ++q) + for (const auto& optionalMember : optionalMembers) { - writeUnmarshalDataMember(*q, fixId((*q)->name(), DotNet::Exception), ns); + writeUnmarshalDataMember(optionalMember, fixId(optionalMember->name(), DotNet::Exception), ns); } _out << nl << "istr_.endSlice();"; if (base) @@ -1999,9 +2000,9 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sp; _out << nl << "public void ice_writeMembers(Ice.OutputStream ostr)"; _out << sb; - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { - writeMarshalDataMember(*q, fixId((*q)->name(), classMapping ? DotNet::ICloneable : 0), ns, true); + writeMarshalDataMember(dataMember, fixId(dataMember->name(), classMapping ? DotNet::ICloneable : 0), ns, true); } _out << eb; @@ -2031,7 +2032,7 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) emitAttributes(p); _out << nl << "public enum " << name; _out << sb; - for (EnumeratorList::const_iterator en = enumerators.begin(); en != enumerators.end(); ++en) + for (auto en = enumerators.begin(); en != enumerators.end(); ++en) { if (en != enumerators.begin()) { @@ -2174,13 +2175,11 @@ namespace bool hasResultType(const ModulePtr& p) { InterfaceList interfaces = p->interfaces(); - for (InterfaceList::const_iterator i = interfaces.begin(); i != interfaces.end(); ++i) + for (const auto& interface : interfaces) { - InterfaceDefPtr interface = *i; OperationList operations = interface->operations(); - for (OperationList::const_iterator j = operations.begin(); j != operations.end(); ++j) + for (const auto& op : operations) { - OperationPtr op = *j; ParameterList outParams = op->outParameters(); TypePtr ret = op->returnType(); if (outParams.size() > 1 || (ret && outParams.size() > 0)) @@ -2323,17 +2322,17 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << nl << "public interface " << name << "Prx : "; vector baseInterfaces; - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end(); ++q) + for (const auto& base : bases) { - baseInterfaces.push_back(getUnqualified(*q, ns, "", "Prx")); + baseInterfaces.push_back(getUnqualified(base, ns, "", "Prx")); } if (baseInterfaces.empty()) { - baseInterfaces.push_back("Ice.ObjectPrx"); + baseInterfaces.emplace_back("Ice.ObjectPrx"); } - for (vector::const_iterator q = baseInterfaces.begin(); q != baseInterfaces.end();) + for (auto q = baseInterfaces.begin(); q != baseInterfaces.end();) { _out << *q; if (++q != baseInterfaces.end()) @@ -2679,9 +2678,8 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if ((ret && outParams.size() > 0) || outParams.size() > 1) { - for (ParameterList::const_iterator i = outParams.begin(); i != outParams.end(); ++i) + for (const auto& param : outParams) { - ParameterPtr param = *i; _out << nl << fixId(param->name()) << " = result_." << fixId(param->name()) << ";"; } @@ -2931,7 +2929,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << sb; { - StringList::const_iterator q = ids.begin(); + auto q = ids.begin(); while (q != ids.end()) { _out << nl << '"' << *q << '"'; diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 00bb72e8ead..167878a257b 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -97,21 +97,21 @@ compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + optarg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + optarg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -162,12 +162,12 @@ compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // // Ignore duplicates. // - vector::iterator j = find(args.begin(), args.end(), *i); + auto j = find(args.begin(), args.end(), *i); if (j != i) { continue; diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index e6b72a5a1ca..12685f15c5a 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -61,9 +61,9 @@ namespace { ParameterList params = p->parameters(); - for (ParameterList::const_iterator i = params.begin(); i != params.end(); ++i) + for (const auto& param : params) { - if ((*i)->name() == name) + if (param->name() == name) { return name + "_"; } @@ -192,9 +192,9 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s // string retval = "returnValue"; const ParameterList outParams = op->outParameters(); - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { - if ((*p)->name() == "returnValue") + if (outParam->name() == "returnValue") { retval = "_returnValue"; break; @@ -250,10 +250,10 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s writeDocCommentLines(out, dc->returns()); } map paramDocs = dc->parameters(); - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { - const string name = (*p)->name(); - map::const_iterator q = paramDocs.find(name); + const string name = outParam->name(); + auto q = paramDocs.find(name); if (q != paramDocs.end() && !q->second.empty()) { out << nl << " * @param " << fixKwd(q->first) << ' '; @@ -278,20 +278,20 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s " " + retval); needMandatoryOnly = !generateMandatoryOnly && op->returnIsOptional(); } - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { out << (typeToString( - (*p)->type(), + outParam->type(), TypeModeIn, package, - (*p)->getMetadata(), + outParam->getMetadata(), true, - !generateMandatoryOnly && (*p)->optional()) + - " " + fixKwd((*p)->name())); + !generateMandatoryOnly && outParam->optional()) + + " " + fixKwd(outParam->name())); if (!generateMandatoryOnly) { - needMandatoryOnly = needMandatoryOnly || (*p)->optional(); + needMandatoryOnly = needMandatoryOnly || outParam->optional(); } } out << epar; @@ -308,13 +308,13 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s out << retval << ';'; } } - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { - const string name = fixKwd((*p)->name()); + const string name = fixKwd(outParam->name()); out << nl << "this." << name << " = "; - if ((*p)->optional() && generateMandatoryOnly) + if (outParam->optional() && generateMandatoryOnly) { - out << ofFactory((*p)->type()) << "(" << name << ");"; + out << ofFactory(outParam->type()) << "(" << name << ");"; } else { @@ -342,13 +342,13 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s << ';'; } - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { if (dc) { - const string name = (*p)->name(); + const string name = outParam->name(); map paramDocs = dc->parameters(); - map::const_iterator q = paramDocs.find(name); + auto q = paramDocs.find(name); if (q != paramDocs.end() && !q->second.empty()) { out << nl << "/**"; @@ -358,8 +358,8 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s } } out << nl << "public " - << typeToString((*p)->type(), TypeModeIn, package, (*p)->getMetadata(), true, (*p)->optional()) << ' ' - << fixKwd((*p)->name()) << ';'; + << typeToString(outParam->type(), TypeModeIn, package, outParam->getMetadata(), true, outParam->optional()) + << ' ' << fixKwd(outParam->name()) << ';'; } ParameterList required, optional; @@ -369,13 +369,13 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s out << sb; int iter = 0; - for (ParameterList::const_iterator pli = required.begin(); pli != required.end(); ++pli) + for (const auto& pli : required) { - const string paramName = fixKwd((*pli)->name()); + const string paramName = fixKwd(pli->name()); writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalNone, false, 0, @@ -383,7 +383,7 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s true, iter, "", - (*pli)->getMetadata()); + pli->getMetadata()); } if (ret && !op->returnIsOptional()) @@ -396,9 +396,9 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s // bool checkReturnType = op->returnIsOptional(); - for (ParameterList::const_iterator pli = optional.begin(); pli != optional.end(); ++pli) + for (const auto& pli : optional) { - if (checkReturnType && op->returnTag() < (*pli)->tag()) + if (checkReturnType && op->returnTag() < pli->tag()) { writeMarshalUnmarshalCode( out, @@ -415,19 +415,19 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s checkReturnType = false; } - const string paramName = fixKwd((*pli)->name()); + const string paramName = fixKwd(pli->name()); writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalOutParam, true, - (*pli)->tag(), + pli->tag(), "this." + paramName, true, iter, "", - (*pli)->getMetadata()); + pli->getMetadata()); } if (checkReturnType) @@ -452,14 +452,14 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s out << sb; iter = 0; - for (ParameterList::const_iterator pli = required.begin(); pli != required.end(); ++pli) + for (const auto& pli : required) { - const string paramName = fixKwd((*pli)->name()); - const string patchParams = getPatcher((*pli)->type(), package, "this." + paramName); + const string paramName = fixKwd(pli->name()); + const string patchParams = getPatcher(pli->type(), package, "this." + paramName); writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalNone, false, 0, @@ -467,7 +467,7 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s false, iter, "", - (*pli)->getMetadata(), + pli->getMetadata(), patchParams); } @@ -494,9 +494,9 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s // checkReturnType = op->returnIsOptional(); - for (ParameterList::const_iterator pli = optional.begin(); pli != optional.end(); ++pli) + for (const auto& pli : optional) { - if (checkReturnType && op->returnTag() < (*pli)->tag()) + if (checkReturnType && op->returnTag() < pli->tag()) { const string patchParams = getPatcher(ret, package, retval); writeMarshalUnmarshalCode( @@ -515,20 +515,20 @@ Slice::JavaVisitor::writeResultType(Output& out, const OperationPtr& op, const s checkReturnType = false; } - const string paramName = fixKwd((*pli)->name()); - const string patchParams = getPatcher((*pli)->type(), package, paramName); + const string paramName = fixKwd(pli->name()); + const string patchParams = getPatcher(pli->type(), package, paramName); writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalOutParam, true, - (*pli)->tag(), + pli->tag(), "this." + paramName, false, iter, "", - (*pli)->getMetadata(), + pli->getMetadata(), patchParams); } @@ -591,10 +591,10 @@ Slice::JavaVisitor::writeMarshaledResultType( writeDocCommentLines(out, dc->returns()); } map paramDocs = dc->parameters(); - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { - const string name = (*p)->name(); - map::const_iterator q = paramDocs.find(name); + const string name = outParam->name(); + auto q = paramDocs.find(name); if (q != paramDocs.end() && !q->second.empty()) { out << nl << " * @param " << fixKwd(q->first) << ' '; @@ -612,13 +612,19 @@ Slice::JavaVisitor::writeMarshaledResultType( out << (typeToString(ret, TypeModeIn, package, op->getMetadata(), true, op->returnIsOptional()) + " " + retval); hasOpt = op->returnIsOptional(); } - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { out - << (typeToString((*p)->type(), TypeModeIn, package, (*p)->getMetadata(), true, (*p)->optional()) + " " + - fixKwd((*p)->name())); + << (typeToString( + outParam->type(), + TypeModeIn, + package, + outParam->getMetadata(), + true, + outParam->optional()) + + " " + fixKwd(outParam->name())); - hasOpt = hasOpt || (*p)->optional(); + hasOpt = hasOpt || outParam->optional(); } out << currentParam << epar; out << sb; @@ -628,13 +634,13 @@ Slice::JavaVisitor::writeMarshaledResultType( ParameterList required, optional; op->outParameters(required, optional); int iter = 0; - for (ParameterList::const_iterator pli = required.begin(); pli != required.end(); ++pli) + for (const auto& pli : required) { - const string paramName = fixKwd((*pli)->name()); + const string paramName = fixKwd(pli->name()); writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalNone, false, 0, @@ -642,7 +648,7 @@ Slice::JavaVisitor::writeMarshaledResultType( true, iter, "_ostr", - (*pli)->getMetadata()); + pli->getMetadata()); } if (ret && !op->returnIsOptional()) @@ -666,9 +672,9 @@ Slice::JavaVisitor::writeMarshaledResultType( // bool checkReturnType = op->returnIsOptional(); - for (ParameterList::const_iterator pli = optional.begin(); pli != optional.end(); ++pli) + for (const auto& pli : optional) { - if (checkReturnType && op->returnTag() < (*pli)->tag()) + if (checkReturnType && op->returnTag() < pli->tag()) { writeMarshalUnmarshalCode( out, @@ -685,19 +691,19 @@ Slice::JavaVisitor::writeMarshaledResultType( checkReturnType = false; } - const string paramName = fixKwd((*pli)->name()); + const string paramName = fixKwd(pli->name()); writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalOutParam, true, - (*pli)->tag(), + pli->tag(), paramName, true, iter, "_ostr", - (*pli)->getMetadata()); + pli->getMetadata()); } if (checkReturnType) @@ -744,10 +750,10 @@ Slice::JavaVisitor::writeMarshaledResultType( writeDocCommentLines(out, dc->returns()); } map paramDocs = dc->parameters(); - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { - const string name = (*p)->name(); - map::const_iterator q = paramDocs.find(name); + const string name = outParam->name(); + auto q = paramDocs.find(name); if (q != paramDocs.end() && !q->second.empty()) { out << nl << " * @param " << fixKwd(q->first) << ' '; @@ -763,11 +769,11 @@ Slice::JavaVisitor::writeMarshaledResultType( { out << (typeToString(ret, TypeModeIn, package, op->getMetadata(), true, false) + " " + retval); } - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { out - << (typeToString((*p)->type(), TypeModeIn, package, (*p)->getMetadata(), true, false) + " " + - fixKwd((*p)->name())); + << (typeToString(outParam->type(), TypeModeIn, package, outParam->getMetadata(), true, false) + " " + + fixKwd(outParam->name())); } out << currentParam << epar; @@ -784,15 +790,15 @@ Slice::JavaVisitor::writeMarshaledResultType( out << retval; } } - for (ParameterList::const_iterator p = outParams.begin(); p != outParams.end(); ++p) + for (const auto& outParam : outParams) { - if ((*p)->optional()) + if (outParam->optional()) { - out << ofFactory((*p)->type()) + "(" + fixKwd((*p)->name()) + ")"; + out << ofFactory(outParam->type()) + "(" + fixKwd(outParam->name()) + ")"; } else { - out << fixKwd((*p)->name()); + out << fixKwd(outParam->name()); } } @@ -882,11 +888,10 @@ Slice::JavaVisitor::getParams(const OperationPtr& op, const string& package) vector params; const ParameterList paramList = op->inParameters(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - const string type = - typeToString((*q)->type(), TypeModeIn, package, (*q)->getMetadata(), true, (*q)->optional()); - params.push_back(type + ' ' + fixKwd((*q)->name())); + const string type = typeToString(q->type(), TypeModeIn, package, q->getMetadata(), true, q->optional()); + params.push_back(type + ' ' + fixKwd(q->name())); } return params; @@ -898,16 +903,16 @@ Slice::JavaVisitor::getParamsProxy(const OperationPtr& op, const string& package vector params; ParameterList inParams = op->inParameters(); - for (ParameterList::const_iterator q = inParams.begin(); q != inParams.end(); ++q) + for (const auto& inParam : inParams) { const string typeString = typeToString( - (*q)->type(), + inParam->type(), TypeModeIn, package, - (*q)->getMetadata(), + inParam->getMetadata(), true, - optionalMapping && (*q)->optional()); - params.push_back(typeString + ' ' + (internal ? "iceP_" + (*q)->name() : fixKwd((*q)->name()))); + optionalMapping && inParam->optional()); + params.push_back(typeString + ' ' + (internal ? "iceP_" + inParam->name() : fixKwd(inParam->name()))); } return params; @@ -919,9 +924,9 @@ Slice::JavaVisitor::getArgs(const OperationPtr& op) vector args; ParameterList paramList = op->parameters(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - args.push_back(fixKwd((*q)->name())); + args.push_back(fixKwd(q->name())); } return args; @@ -933,9 +938,9 @@ Slice::JavaVisitor::getInArgs(const OperationPtr& op, bool internal) vector args; ParameterList paramList = op->inParameters(); - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - string s = internal ? "iceP_" + (*q)->name() : fixKwd((*q)->name()); + string s = internal ? "iceP_" + q->name() : fixKwd(q->name()); args.push_back(s); } @@ -952,13 +957,13 @@ Slice::JavaVisitor::writeMarshalProxyParams( int iter = 0; ParameterList required, optional; op->inParameters(required, optional); - for (ParameterList::const_iterator pli = required.begin(); pli != required.end(); ++pli) + for (const auto& pli : required) { - string paramName = "iceP_" + (*pli)->name(); + string paramName = "iceP_" + pli->name(); writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalNone, false, 0, @@ -966,26 +971,26 @@ Slice::JavaVisitor::writeMarshalProxyParams( true, iter, "", - (*pli)->getMetadata()); + pli->getMetadata()); } // // Handle optional parameters. // - for (ParameterList::const_iterator pli = optional.begin(); pli != optional.end(); ++pli) + for (const auto& pli : optional) { writeMarshalUnmarshalCode( out, package, - (*pli)->type(), + pli->type(), OptionalInParam, optionalMapping, - (*pli)->tag(), - "iceP_" + (*pli)->name(), + pli->tag(), + "iceP_" + pli->name(), true, iter, "", - (*pli)->getMetadata()); + pli->getMetadata()); } if (op->sendsClasses()) @@ -1163,13 +1168,13 @@ Slice::JavaVisitor::writeThrowsClause(const string& package, const ExceptionList out << nl << "throws "; out.useCurrentPosAsIndent(); int count = 0; - for (ExceptionList::const_iterator r = throws.begin(); r != throws.end(); ++r) + for (const auto& r : throws) { if (count > 0) { out << "," << nl; } - out << getUnqualified(*r, package); + out << getUnqualified(r, package); count++; } out.restoreIndent(); @@ -1329,7 +1334,7 @@ Slice::JavaVisitor::writeDispatch(Output& out, const InterfaceDefPtr& p) out << nl << "static final String[] _iceIds ="; out << sb; - for (StringList::const_iterator q = ids.begin(); q != ids.end();) + for (auto q = ids.begin(); q != ids.end();) { out << nl << '"' << *q << '"'; if (++q != ids.end()) @@ -1461,11 +1466,11 @@ Slice::JavaVisitor::writeDispatch(Output& out, const InterfaceDefPtr& p) } out << nl << "istr.endEncapsulation();"; - for (ParameterList::const_iterator pli = values.begin(); pli != values.end(); ++pli) + for (const auto& value : values) { const string typeS = - typeToString((*pli)->type(), TypeModeIn, package, (*pli)->getMetadata(), true, (*pli)->optional()); - out << nl << typeS << ' ' << "iceP_" << (*pli)->name() << " = icePP_" << (*pli)->name() << ".value;"; + typeToString(value->type(), TypeModeIn, package, value->getMetadata(), true, value->optional()); + out << nl << typeS << ' ' << "iceP_" << value->name() << " = icePP_" << value->name() << ".value;"; } } else @@ -1597,16 +1602,16 @@ Slice::JavaVisitor::writeMarshaling(Output& out, const ClassDefPtr& p) out << sb; out << nl << "ostr_.startSlice(ice_staticId(), " << p->compactId() << (!base ? ", true" : ", false") << ");"; iter = 0; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - writeMarshalDataMember(out, package, *d, iter); + writeMarshalDataMember(out, package, member, iter); } } - for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + for (const auto& optionalMember : optionalMembers) { - writeMarshalDataMember(out, package, *d, iter); + writeMarshalDataMember(out, package, optionalMember, iter); } out << nl << "ostr_.endSlice();"; if (base) @@ -1626,16 +1631,16 @@ Slice::JavaVisitor::writeMarshaling(Output& out, const ClassDefPtr& p) out << nl << "istr_.startSlice();"; iter = 0; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - writeUnmarshalDataMember(out, package, *d, iter); + writeUnmarshalDataMember(out, package, member, iter); } } - for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + for (const auto& optionalMember : optionalMembers) { - writeUnmarshalDataMember(out, package, *d, iter); + writeUnmarshalDataMember(out, package, optionalMember, iter); } out << nl << "istr_.endSlice();"; @@ -1720,23 +1725,23 @@ Slice::JavaVisitor::writeConstantValue( void Slice::JavaVisitor::writeDataMemberInitializers(Output& out, const DataMemberList& members, const string& package) { - for (DataMemberList::const_iterator p = members.begin(); p != members.end(); ++p) + for (const auto& member : members) { - TypePtr t = (*p)->type(); - if ((*p)->defaultValueType()) + TypePtr t = member->type(); + if (member->defaultValueType()) { - if ((*p)->optional()) + if (member->optional()) { - string capName = (*p)->name(); + string capName = member->name(); capName[0] = static_cast(toupper(static_cast(capName[0]))); out << nl << "set" << capName << '('; - writeConstantValue(out, t, (*p)->defaultValueType(), (*p)->defaultValue(), package); + writeConstantValue(out, t, member->defaultValueType(), member->defaultValue(), package); out << ");"; } else { - out << nl << "this." << fixKwd((*p)->name()) << " = "; - writeConstantValue(out, t, (*p)->defaultValueType(), (*p)->defaultValue(), package); + out << nl << "this." << fixKwd(member->name()) << " = "; + writeConstantValue(out, t, member->defaultValueType(), member->defaultValue(), package); out << ';'; } } @@ -1745,22 +1750,22 @@ Slice::JavaVisitor::writeDataMemberInitializers(Output& out, const DataMemberLis BuiltinPtr builtin = dynamic_pointer_cast(t); if (builtin && builtin->kind() == Builtin::KindString) { - out << nl << "this." << fixKwd((*p)->name()) << " = \"\";"; + out << nl << "this." << fixKwd(member->name()) << " = \"\";"; } EnumPtr en = dynamic_pointer_cast(t); if (en) { string firstEnum = fixKwd(en->enumerators().front()->name()); - out << nl << "this." << fixKwd((*p)->name()) << " = " << getUnqualified(en, package) << '.' << firstEnum - << ';'; + out << nl << "this." << fixKwd(member->name()) << " = " << getUnqualified(en, package) << '.' + << firstEnum << ';'; } StructPtr st = dynamic_pointer_cast(t); if (st) { - string memberType = typeToString(st, TypeModeMember, package, (*p)->getMetadata()); - out << nl << "this." << fixKwd((*p)->name()) << " = new " << memberType << "();"; + string memberType = typeToString(st, TypeModeMember, package, member->getMetadata()); + out << nl << "this." << fixKwd(member->name()) << " = new " << memberType << "();"; } } } @@ -1784,12 +1789,12 @@ Slice::JavaVisitor::writeDocCommentLines(Output& out, const StringList& lines) StringList l = lines; out << l.front(); l.pop_front(); - for (StringList::const_iterator p = l.begin(); p != l.end(); ++p) + for (const auto& p : l) { out << nl << " *"; - if (!p->empty()) + if (!p.empty()) { - out << " " << *p; + out << " " << p; } } } @@ -1862,10 +1867,10 @@ Slice::JavaVisitor::writeDocComment(Output& out, const UnitPtr& unt, const DocCo { out << nl << " *"; StringList sa = dc->seeAlso(); - for (StringList::iterator p = sa.begin(); p != sa.end(); ++p) + for (const auto& p : sa) { out << nl << " * @see "; - writeSeeAlso(out, unt, *p); + writeSeeAlso(out, unt, p); } } @@ -1921,10 +1926,10 @@ Slice::JavaVisitor::writeProxyDocComment( // Show in-params in order of declaration, but only those with docs. // const ParameterList paramList = p->inParameters(); - for (ParameterList::const_iterator i = paramList.begin(); i != paramList.end(); ++i) + for (const auto& i : paramList) { - const string name = (*i)->name(); - map::const_iterator j = paramDocs.find(name); + const string name = i->name(); + auto j = paramDocs.find(name); if (j != paramDocs.end() && !j->second.empty()) { out << nl << " * @param " << fixKwd(j->first) << ' '; @@ -1967,7 +1972,7 @@ Slice::JavaVisitor::writeProxyDocComment( { assert(p->outParameters().size() == 1); const ParameterPtr param = p->outParameters().front(); - map::const_iterator j = paramDocs.find(param->name()); + auto j = paramDocs.find(param->name()); if (j != paramDocs.end() && !j->second.empty()) { out << nl << " * @return "; @@ -1992,10 +1997,10 @@ Slice::JavaVisitor::writeProxyDocComment( if (!async) { map exDocs = dc->exceptions(); - for (map::const_iterator i = exDocs.begin(); i != exDocs.end(); ++i) + for (const auto& exDoc : exDocs) { - out << nl << " * @throws " << fixKwd(i->first) << ' '; - writeDocCommentLines(out, i->second); + out << nl << " * @throws " << fixKwd(exDoc.first) << ' '; + writeDocCommentLines(out, exDoc.second); } } @@ -2003,10 +2008,10 @@ Slice::JavaVisitor::writeProxyDocComment( { out << nl << " *"; StringList sa = dc->seeAlso(); - for (StringList::iterator q = sa.begin(); q != sa.end(); ++q) + for (const auto& q : sa) { out << nl << " * @see "; - writeSeeAlso(out, p->unit(), *q); + writeSeeAlso(out, p->unit(), q); } } @@ -2035,9 +2040,9 @@ Slice::JavaVisitor::writeHiddenProxyDocComment(Output& out, const OperationPtr& // Show in-params in order of declaration // const ParameterList paramList = p->inParameters(); - for (ParameterList::const_iterator i = paramList.begin(); i != paramList.end(); ++i) + for (const auto& i : paramList) { - const string name = (*i)->name(); + const string name = i->name(); out << nl << " * @param " << "iceP_" << name << " -"; } @@ -2081,10 +2086,10 @@ Slice::JavaVisitor::writeServantDocComment( // // Show in-params in order of declaration, but only those with docs. // - for (ParameterList::const_iterator i = paramList.begin(); i != paramList.end(); ++i) + for (const auto& i : paramList) { - const string name = (*i)->name(); - map::const_iterator j = paramDocs.find(name); + const string name = i->name(); + auto j = paramDocs.find(name); if (j != paramDocs.end() && !j->second.empty()) { out << nl << " * @param " << fixKwd(j->first) << ' '; @@ -2125,7 +2130,7 @@ Slice::JavaVisitor::writeServantDocComment( { assert(p->outParameters().size() == 1); const ParameterPtr param = p->outParameters().front(); - map::const_iterator j = paramDocs.find(param->name()); + auto j = paramDocs.find(param->name()); if (j != paramDocs.end() && !j->second.empty()) { out << nl << " * @return "; @@ -2151,10 +2156,10 @@ Slice::JavaVisitor::writeServantDocComment( else { map exDocs = dc->exceptions(); - for (map::const_iterator i = exDocs.begin(); i != exDocs.end(); ++i) + for (const auto& exDoc : exDocs) { - out << nl << " * @throws " << fixKwd(i->first) << ' '; - writeDocCommentLines(out, i->second); + out << nl << " * @throws " << fixKwd(exDoc.first) << ' '; + writeDocCommentLines(out, exDoc.second); } } @@ -2162,10 +2167,10 @@ Slice::JavaVisitor::writeServantDocComment( { out << nl << " *"; StringList sa = dc->seeAlso(); - for (StringList::iterator q = sa.begin(); q != sa.end(); ++q) + for (const auto& q : sa) { out << nl << " * @see "; - writeSeeAlso(out, p->unit(), *q); + writeSeeAlso(out, p->unit(), q); } } @@ -2318,9 +2323,9 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) bool hasOptionalMembers = false; bool hasRequiredMembers = false; - for (DataMemberList::const_iterator d = allDataMembers.begin(); d != allDataMembers.end(); ++d) + for (const auto& allDataMember : allDataMembers) { - if ((*d)->optional()) + if (allDataMember->optional()) { hasOptionalMembers = true; } @@ -2361,13 +2366,18 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) // out << sp << nl << "public " << fixKwd(name) << spar; vector parameters; - for (DataMemberList::const_iterator d = allDataMembers.begin(); d != allDataMembers.end(); ++d) + for (const auto& allDataMember : allDataMembers) { - if (!(*d)->optional()) + if (!allDataMember->optional()) { - string memberName = fixKwd((*d)->name()); - string memberType = - typeToString((*d)->type(), TypeModeMember, package, (*d)->getMetadata(), true, false); + string memberName = fixKwd(allDataMember->name()); + string memberType = typeToString( + allDataMember->type(), + TypeModeMember, + package, + allDataMember->getMetadata(), + true, + false); parameters.push_back(memberType + " " + memberName); } } @@ -2376,9 +2386,9 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) if (!baseDataMembers.empty()) { bool hasBaseRequired = false; - for (DataMemberList::const_iterator d = baseDataMembers.begin(); d != baseDataMembers.end(); ++d) + for (const auto& baseDataMember : baseDataMembers) { - if (!(*d)->optional()) + if (!baseDataMember->optional()) { hasBaseRequired = true; break; @@ -2388,23 +2398,22 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) { out << nl << "super" << spar; vector baseParamNames; - for (DataMemberList::const_iterator d = baseDataMembers.begin(); d != baseDataMembers.end(); - ++d) + for (const auto& baseDataMember : baseDataMembers) { - if (!(*d)->optional()) + if (!baseDataMember->optional()) { - baseParamNames.push_back(fixKwd((*d)->name())); + baseParamNames.push_back(fixKwd(baseDataMember->name())); } } out << baseParamNames << epar << ';'; } } - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - string paramName = fixKwd((*d)->name()); + string paramName = fixKwd(member->name()); out << nl << "this." << paramName << " = " << paramName << ';'; } } @@ -2417,11 +2426,16 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) // out << sp << nl << "public " << fixKwd(name) << spar; vector parameters; - for (DataMemberList::const_iterator d = allDataMembers.begin(); d != allDataMembers.end(); ++d) + for (const auto& allDataMember : allDataMembers) { - string memberName = fixKwd((*d)->name()); - string memberType = - typeToString((*d)->type(), TypeModeMember, package, (*d)->getMetadata(), true, false); + string memberName = fixKwd(allDataMember->name()); + string memberType = typeToString( + allDataMember->type(), + TypeModeMember, + package, + allDataMember->getMetadata(), + true, + false); parameters.push_back(memberType + " " + memberName); } out << parameters << epar; @@ -2430,16 +2444,16 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) { out << nl << "super" << spar; vector baseParamNames; - for (DataMemberList::const_iterator d = baseDataMembers.begin(); d != baseDataMembers.end(); ++d) + for (const auto& baseDataMember : baseDataMembers) { - baseParamNames.push_back(fixKwd((*d)->name())); + baseParamNames.push_back(fixKwd(baseDataMember->name())); } out << baseParamNames << epar << ';'; } - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - string paramName = fixKwd((*d)->name()); - if ((*d)->optional()) + string paramName = fixKwd(member->name()); + if (member->optional()) { string capName = paramName; capName[0] = static_cast(toupper(static_cast(capName[0]))); @@ -2532,7 +2546,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) writeDocComment(out, p->unit(), dc); out << nl << "public interface " << fixKwd(name) << " extends "; - InterfaceList::const_iterator q = bases.begin(); + auto q = bases.begin(); out.useCurrentPosAsIndent(); if (bases.empty()) { @@ -2795,16 +2809,16 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) out << sb; out << nl << "ostr_.startSlice(\"" << scoped << "\", -1, " << (!base ? "true" : "false") << ");"; iter = 0; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - writeMarshalDataMember(out, package, *d, iter); + writeMarshalDataMember(out, package, member, iter); } } - for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + for (const auto& optionalMember : optionalMembers) { - writeMarshalDataMember(out, package, *d, iter); + writeMarshalDataMember(out, package, optionalMember, iter); } out << nl << "ostr_.endSlice();"; if (base) @@ -2823,16 +2837,16 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) out << sb; out << nl << "istr_.startSlice();"; iter = 0; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - writeUnmarshalDataMember(out, package, *d, iter); + writeUnmarshalDataMember(out, package, member, iter); } } - for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + for (const auto& optionalMember : optionalMembers) { - writeUnmarshalDataMember(out, package, *d, iter); + writeUnmarshalDataMember(out, package, optionalMember, iter); } out << nl << "istr_.endSlice();"; if (base) @@ -2913,19 +2927,20 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) { vector parameters; vector paramNames; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - string memberName = fixKwd((*d)->name()); - string memberType = typeToString((*d)->type(), TypeModeMember, package, (*d)->getMetadata(), true, false); + string memberName = fixKwd(member->name()); + string memberType = + typeToString(member->type(), TypeModeMember, package, member->getMetadata(), true, false); parameters.push_back(memberType + " " + memberName); paramNames.push_back(memberName); } out << sp << nl << "public " << name << spar << parameters << epar; out << sb; - for (vector::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) + for (const auto& paramName : paramNames) { - out << nl << "this." << *i << " = " << *i << ';'; + out << nl << "this." << paramName << " = " << paramName << ';'; } out << eb; } @@ -2943,10 +2958,10 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) out << eb; out << sp << nl << "if(r != null)"; out << sb; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - string memberName = fixKwd((*d)->name()); - BuiltinPtr b = dynamic_pointer_cast((*d)->type()); + string memberName = fixKwd(member->name()); + BuiltinPtr b = dynamic_pointer_cast(member->type()); if (b) { switch (b->kind()) @@ -2993,10 +3008,10 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) // // For all other types, we can use the native equals() method. // - SequencePtr seq = dynamic_pointer_cast((*d)->type()); + SequencePtr seq = dynamic_pointer_cast(member->type()); if (seq) { - if (hasTypeMetadata(seq, (*d)->getMetadata())) + if (hasTypeMetadata(seq, member->getMetadata())) { out << nl << "if(this." << memberName << " != r." << memberName << ')'; out << sb; @@ -3066,9 +3081,9 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) out << sp << nl << "public void ice_writeMembers(com.zeroc.Ice.OutputStream ostr)"; out << sb; iter = 0; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - writeMarshalDataMember(out, package, *d, iter, true); + writeMarshalDataMember(out, package, member, iter, true); } out << eb; @@ -3077,9 +3092,9 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) out << sp << nl << "public void ice_readMembers(com.zeroc.Ice.InputStream istr)"; out << sb; iter = 0; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - writeUnmarshalDataMember(out, package, *d, iter, true); + writeUnmarshalDataMember(out, package, member, iter, true); } out << eb; @@ -3477,7 +3492,7 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) out << nl << "public enum " << name; out << sb; - for (EnumeratorList::const_iterator en = enumerators.begin(); en != enumerators.end(); ++en) + for (auto en = enumerators.begin(); en != enumerators.end(); ++en) { if (en != enumerators.begin()) { @@ -3503,11 +3518,11 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) out << nl << "switch(v)"; out << sb; out.dec(); - for (EnumeratorList::const_iterator en = enumerators.begin(); en != enumerators.end(); ++en) + for (const auto& enumerator : enumerators) { - out << nl << "case " << (*en)->value() << ':'; + out << nl << "case " << enumerator->value() << ':'; out.inc(); - out << nl << "return " << fixKwd((*en)->name()) << ';'; + out << nl << "return " << fixKwd(enumerator->name()) << ';'; out.dec(); } out.inc(); @@ -3936,7 +3951,7 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } else { - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end(); ++q) + for (auto q = bases.begin(); q != bases.end(); ++q) { if (q != bases.begin()) { @@ -4225,9 +4240,9 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) out << "_iceI_" << p->name() << "Async" << spar << args << contextParamName << "true" << epar << ".waitForResponseOrUserEx();"; out << eb; - for (ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t) + for (const auto& t : throws) { - string exS = getUnqualified(*t, package); + string exS = getUnqualified(t, package); out << nl << "catch(" << exS << " ex)"; out << sb; out << nl << "throw ex;"; @@ -4293,9 +4308,9 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) out << "_iceI_" << p->name() << "Async" << spar << args << contextParamName << "true" << epar << ".waitForResponseOrUserEx();"; out << eb; - for (ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t) + for (const auto& t : throws) { - string exS = getUnqualified(*t, package); + string exS = getUnqualified(t, package); out << nl << "catch(" << exS << " ex)"; out << sb; out << nl << "throw ex;"; @@ -4388,7 +4403,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) writeHiddenDocComment(out); out << nl << "static final Class[] _iceE_" << p->name() << " ="; out << sb; - for (ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t) + for (auto t = throws.begin(); t != throws.end(); ++t) { if (t != throws.begin()) { diff --git a/cpp/src/slice2java/JavaUtil.cpp b/cpp/src/slice2java/JavaUtil.cpp index 0eea4190d05..288662d353f 100644 --- a/cpp/src/slice2java/JavaUtil.cpp +++ b/cpp/src/slice2java/JavaUtil.cpp @@ -153,9 +153,9 @@ Slice::isValidMethodParameterList(const DataMemberList& members, int additionalU // Each parameter is 1 unit, except for long and double parameters, which are 2 units. // Start the length at 1 to account for the implicit 'this' parameter (plus any additional units). int length = 1 + additionalUnits; - for (DataMemberList::const_iterator p = members.begin(); p != members.end(); ++p) + for (const auto& member : members) { - BuiltinPtr builtin = dynamic_pointer_cast((*p)->type()); + BuiltinPtr builtin = dynamic_pointer_cast(member->type()); if (builtin && (builtin->kind() == Builtin::KindLong || builtin->kind() == Builtin::KindDouble)) { length += 2; @@ -369,9 +369,9 @@ Slice::JavaGenerator::fixKwd(const string& name) vector ids = splitScopedName(name); transform(ids.begin(), ids.end(), ids.begin(), [](const string& id) -> string { return lookupKwd(id); }); stringstream result; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (const auto& id : ids) { - result << "::" + *i; + result << "::" + id; } return result.str(); } diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 2d81ca12afb..c982ba2c271 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -102,21 +102,21 @@ compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + optarg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + optarg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -171,12 +171,12 @@ compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // // Ignore duplicates. // - vector::iterator j = find(args.begin(), args.end(), *i); + auto j = find(args.begin(), args.end(), *i); if (j != i) { continue; diff --git a/cpp/src/slice2js/Gen.cpp b/cpp/src/slice2js/Gen.cpp index 4302c657847..508ff2170a8 100644 --- a/cpp/src/slice2js/Gen.cpp +++ b/cpp/src/slice2js/Gen.cpp @@ -120,9 +120,9 @@ namespace string escapeParam(const ParameterList& params, const string& name) { string r = name; - for (ParameterList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { - if (Slice::JsGenerator::fixId((*p)->name()) == name) + if (Slice::JsGenerator::fixId(param->name()) == name) { r = name + "_"; break; @@ -141,12 +141,12 @@ namespace out << l.front(); l.pop_front(); } - for (StringList::const_iterator i = l.begin(); i != l.end(); ++i) + for (const auto& i : l) { out << nl << " *"; - if (!i->empty()) + if (!i.empty()) { - out << space << *i; + out << space << i; } } } @@ -154,12 +154,12 @@ namespace void writeSeeAlso(Output& out, const StringList& lines, const string& space = " ") { - for (StringList::const_iterator i = lines.begin(); i != lines.end(); ++i) + for (const auto& line : lines) { out << nl << " *"; - if (!i->empty()) + if (!line.empty()) { - out << space << "@see " << *i; + out << space << "@see " << line; } } } @@ -191,7 +191,7 @@ namespace // Extract the first sentence. // ostringstream ostr; - for (StringList::const_iterator i = lines.begin(); i != lines.end(); ++i) + for (auto i = lines.begin(); i != lines.end(); ++i) { const string ws = " \t"; @@ -251,12 +251,12 @@ namespace void writeOpDocExceptions(Output& out, const OperationPtr& op, const DocCommentPtr& doc) { map exDoc = doc->exceptions(); - for (map::iterator p = exDoc.begin(); p != exDoc.end(); ++p) + for (const auto& p : exDoc) { // // Try to locate the exception's definition using the name given in the comment. // - string name = p->first; + string name = p.first; ExceptionPtr ex = op->container()->lookupException(name, false); if (ex) { @@ -264,7 +264,7 @@ namespace } name = JsGenerator::fixId(name); out << nl << " * @throws {@link " << name << "} "; - writeDocLines(out, p->second, false); + writeDocLines(out, p.second, false); } } } @@ -288,25 +288,25 @@ Slice::JsVisitor::writeMarshalDataMembers( bool isStruct = dynamic_pointer_cast(contained) != nullptr; bool isLegalKeyType = Dictionary::isLegalKeyType(dynamic_pointer_cast(contained)); - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { - if (!(*q)->optional()) + if (!dataMember->optional()) { writeMarshalUnmarshalCode( _out, - (*q)->type(), - "this." + fixDataMemberName((*q)->name(), isStruct, isLegalKeyType), + dataMember->type(), + "this." + fixDataMemberName(dataMember->name(), isStruct, isLegalKeyType), true); } } - for (DataMemberList::const_iterator q = optionalMembers.begin(); q != optionalMembers.end(); ++q) + for (const auto& optionalMember : optionalMembers) { writeOptionalMarshalUnmarshalCode( _out, - (*q)->type(), - "this." + fixDataMemberName((*q)->name(), isStruct, isLegalKeyType), - (*q)->tag(), + optionalMember->type(), + "this." + fixDataMemberName(optionalMember->name(), isStruct, isLegalKeyType), + optionalMember->tag(), true); } } @@ -320,25 +320,25 @@ Slice::JsVisitor::writeUnmarshalDataMembers( bool isStruct = dynamic_pointer_cast(contained) != nullptr; bool isLegalKeyType = Dictionary::isLegalKeyType(dynamic_pointer_cast(contained)); - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { - if (!(*q)->optional()) + if (!dataMember->optional()) { writeMarshalUnmarshalCode( _out, - (*q)->type(), - "this." + fixDataMemberName((*q)->name(), isStruct, isLegalKeyType), + dataMember->type(), + "this." + fixDataMemberName(dataMember->name(), isStruct, isLegalKeyType), false); } } - for (DataMemberList::const_iterator q = optionalMembers.begin(); q != optionalMembers.end(); ++q) + for (const auto& optionalMember : optionalMembers) { writeOptionalMarshalUnmarshalCode( _out, - (*q)->type(), - "this." + fixDataMemberName((*q)->name(), isStruct, isLegalKeyType), - (*q)->tag(), + optionalMember->type(), + "this." + fixDataMemberName(optionalMember->name(), isStruct, isLegalKeyType), + optionalMember->tag(), false); } } @@ -349,10 +349,10 @@ Slice::JsVisitor::writeInitDataMembers(const DataMemberList& dataMembers, const bool isStruct = dynamic_pointer_cast(contained) != nullptr; bool isLegalKeyType = Dictionary::isLegalKeyType(dynamic_pointer_cast(contained)); - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { - const string m = fixDataMemberName((*q)->name(), isStruct, isLegalKeyType); - _out << nl << "this." << m << " = " << fixId((*q)->name()) << ';'; + const string m = fixDataMemberName(dataMember->name(), isStruct, isLegalKeyType); + _out << nl << "this." << m << " = " << fixId(dataMember->name()) << ';'; } } @@ -681,9 +681,9 @@ Slice::Gen::ImportVisitor::ImportVisitor(IceInternal::Output& out, vector::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) + for (auto& includePath : _includePaths) { - *p = fullPath(*p); + includePath = fullPath(includePath); } } @@ -951,7 +951,7 @@ Slice::Gen::ImportVisitor::writeImports(const UnitPtr& p) { // Import the required modules from "ice" JavaScript module. set iceModules = imports["ice"]; - for (set::const_iterator i = iceModules.begin(); i != iceModules.end();) + for (auto i = iceModules.begin(); i != iceModules.end();) { _out << nl << "import { "; _out << (*i); @@ -1100,9 +1100,9 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) const DataMemberList optionalMembers = p->orderedOptionalDataMembers(); vector allParamNames; - for (DataMemberList::const_iterator q = allDataMembers.begin(); q != allDataMembers.end(); ++q) + for (const auto& allDataMember : allDataMembers) { - allParamNames.push_back(fixId((*q)->name())); + allParamNames.push_back(fixId(allDataMember->name())); } vector baseParamNames; @@ -1111,9 +1111,9 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) if (base) { baseDataMembers = base->allDataMembers(); - for (DataMemberList::const_iterator q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) + for (const auto& baseDataMember : baseDataMembers) { - baseParamNames.push_back(fixId((*q)->name())); + baseParamNames.push_back(fixId(baseDataMember->name())); } } @@ -1126,19 +1126,23 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) if (!allParamNames.empty()) { _out << nl << "constructor" << spar; - for (DataMemberList::const_iterator q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) + for (const auto& baseDataMember : baseDataMembers) { - _out << fixId((*q)->name()); + _out << fixId(baseDataMember->name()); } - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { string value; - if ((*q)->optional()) + if (dataMember->optional()) { - if ((*q)->defaultValueType()) + if (dataMember->defaultValueType()) { - value = writeConstantValue(scope, (*q)->type(), (*q)->defaultValueType(), (*q)->defaultValue()); + value = writeConstantValue( + scope, + dataMember->type(), + dataMember->defaultValueType(), + dataMember->defaultValue()); } else { @@ -1147,16 +1151,20 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) } else { - if ((*q)->defaultValueType()) + if (dataMember->defaultValueType()) { - value = writeConstantValue(scope, (*q)->type(), (*q)->defaultValueType(), (*q)->defaultValue()); + value = writeConstantValue( + scope, + dataMember->type(), + dataMember->defaultValueType(), + dataMember->defaultValue()); } else { - value = getValue(scope, (*q)->type()); + value = getValue(scope, dataMember->type()); } } - _out << (fixId((*q)->name()) + (value.empty() ? value : (" = " + value))); + _out << (fixId(dataMember->name()) + (value.empty() ? value : (" = " + value))); } _out << epar << sb; @@ -1220,7 +1228,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << nl << "const iceC_" << getLocalScope(scoped, "_") << "_ids = ["; _out.inc(); - for (StringList::const_iterator q = ids.begin(); q != ids.end(); ++q) + for (auto q = ids.begin(); q != ids.end(); ++q) { if (q != ids.begin()) { @@ -1248,7 +1256,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << sb; _out << nl << "return ["; _out.inc(); - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end();) + for (auto q = bases.begin(); q != bases.end();) { InterfaceDefPtr base = *q; _out << nl << getLocalScope(base->scope()) << "." << base->name(); @@ -1279,7 +1287,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << nl << "return ["; _out.inc(); - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end();) + for (auto q = bases.begin(); q != bases.end();) { InterfaceDefPtr base = *q; @@ -1308,7 +1316,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _out << ','; _out << sb; - for (OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q) + for (auto q = ops.begin(); q != ops.end(); ++q) { if (q != ops.begin()) { @@ -1320,15 +1328,15 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) const ParameterList paramList = op->parameters(); const TypePtr ret = op->returnType(); ParameterList inParams, outParams; - for (ParameterList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) + for (const auto& pli : paramList) { - if ((*pli)->isOutParam()) + if (pli->isOutParam()) { - outParams.push_back(*pli); + outParams.push_back(pli); } else { - inParams.push_back(*pli); + inParams.push_back(pli); } } @@ -1396,7 +1404,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (!inParams.empty()) { _out << '['; - for (ParameterList::const_iterator pli = inParams.begin(); pli != inParams.end(); ++pli) + for (auto pli = inParams.begin(); pli != inParams.end(); ++pli) { if (pli != inParams.begin()) { @@ -1429,7 +1437,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (!outParams.empty()) { _out << '['; - for (ParameterList::const_iterator pli = outParams.begin(); pli != outParams.end(); ++pli) + for (auto pli = outParams.begin(); pli != outParams.end(); ++pli) { if (pli != outParams.begin()) { @@ -1472,7 +1480,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _out << nl << '['; _out.inc(); - for (ExceptionList::const_iterator eli = throws.begin(); eli != throws.end(); ++eli) + for (auto eli = throws.begin(); eli != throws.end(); ++eli) { if (eli != throws.begin()) { @@ -1553,9 +1561,9 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) const DataMemberList optionalMembers = p->orderedOptionalDataMembers(); vector allParamNames; - for (DataMemberList::const_iterator q = allDataMembers.begin(); q != allDataMembers.end(); ++q) + for (const auto& allDataMember : allDataMembers) { - allParamNames.push_back(fixId((*q)->name())); + allParamNames.push_back(fixId(allDataMember->name())); } vector baseParamNames; @@ -1564,9 +1572,9 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) if (p->base()) { baseDataMembers = p->base()->allDataMembers(); - for (DataMemberList::const_iterator q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) + for (const auto& baseDataMember : baseDataMembers) { - baseParamNames.push_back(fixId((*q)->name())); + baseParamNames.push_back(fixId(baseDataMember->name())); } } @@ -1577,19 +1585,23 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) _out << nl << "constructor" << spar; - for (DataMemberList::const_iterator q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) + for (const auto& baseDataMember : baseDataMembers) { - _out << fixId((*q)->name()); + _out << fixId(baseDataMember->name()); } - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { string value; - if ((*q)->optional()) + if (dataMember->optional()) { - if ((*q)->defaultValueType()) + if (dataMember->defaultValueType()) { - value = writeConstantValue(scope, (*q)->type(), (*q)->defaultValueType(), (*q)->defaultValue()); + value = writeConstantValue( + scope, + dataMember->type(), + dataMember->defaultValueType(), + dataMember->defaultValue()); } else { @@ -1598,16 +1610,20 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) } else { - if ((*q)->defaultValueType()) + if (dataMember->defaultValueType()) { - value = writeConstantValue(scope, (*q)->type(), (*q)->defaultValueType(), (*q)->defaultValue()); + value = writeConstantValue( + scope, + dataMember->type(), + dataMember->defaultValueType(), + dataMember->defaultValue()); } else { - value = getValue(scope, (*q)->type()); + value = getValue(scope, dataMember->type()); } } - _out << (fixId((*q)->name()) + (value.empty() ? value : (" = " + value))); + _out << (fixId(dataMember->name()) + (value.empty() ? value : (" = " + value))); } _out << "_cause = \"\"" << epar; @@ -1678,9 +1694,9 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) const DataMemberList dataMembers = p->dataMembers(); vector paramNames; - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { - paramNames.push_back(fixId((*q)->name())); + paramNames.push_back(fixId(dataMember->name())); } _out << sp; @@ -1690,14 +1706,18 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) _out << nl << "constructor" << spar; - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& dataMember : dataMembers) { string value; - if ((*q)->optional()) + if (dataMember->optional()) { - if ((*q)->defaultValueType()) + if (dataMember->defaultValueType()) { - value = writeConstantValue(scope, (*q)->type(), (*q)->defaultValueType(), (*q)->defaultValue()); + value = writeConstantValue( + scope, + dataMember->type(), + dataMember->defaultValueType(), + dataMember->defaultValue()); } else { @@ -1706,16 +1726,20 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) } else { - if ((*q)->defaultValueType()) + if (dataMember->defaultValueType()) { - value = writeConstantValue(scope, (*q)->type(), (*q)->defaultValueType(), (*q)->defaultValue()); + value = writeConstantValue( + scope, + dataMember->type(), + dataMember->defaultValueType(), + dataMember->defaultValue()); } else { - value = getValue(scope, (*q)->type()); + value = getValue(scope, dataMember->type()); } } - _out << (fixId((*q)->name()) + (value.empty() ? value : (" = " + value))); + _out << (fixId(dataMember->name()) + (value.empty() ? value : (" = " + value))); } _out << epar; @@ -1807,7 +1831,7 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) const EnumeratorList enumerators = p->enumerators(); int i = 0; - for (EnumeratorList::const_iterator en = enumerators.begin(); en != enumerators.end(); ++en) + for (auto en = enumerators.begin(); en != enumerators.end(); ++en) { if (en != enumerators.begin()) { @@ -2444,7 +2468,7 @@ Slice::Gen::TypeScriptVisitor::writeOpDocSummary( paramDoc = comment->parameters(); for (const auto& param : op->inParameters()) { - map::iterator q = paramDoc.find(param->name()); + auto q = paramDoc.find(param->name()); if (q != paramDoc.end()) { out << nl << " * @param " << Slice::JsGenerator::fixId(q->first) << " "; @@ -2490,7 +2514,7 @@ Slice::Gen::TypeScriptVisitor::writeOpDocSummary( for (const auto& param : outParams) { - map::iterator q = paramDoc.find(param->name()); + auto q = paramDoc.find(param->name()); if (q != paramDoc.end()) { out << nl << " * - " << typeToTsString(param->type(), true, false, param->optional()) << " : "; @@ -2598,7 +2622,7 @@ Slice::Gen::TypeScriptVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << typeToTsString(ret, true, false, op->returnIsOptional()) << ", "; } - for (ParameterList::const_iterator i = outParams.begin(); i != outParams.end();) + for (auto i = outParams.begin(); i != outParams.end();) { _out << typeToTsString((*i)->type(), true, false, (*i)->optional()); if (++i != outParams.end()) @@ -2688,7 +2712,7 @@ Slice::Gen::TypeScriptVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) os << typeToTsString(ret, true, false, op->returnIsOptional()) << ", "; } - for (ParameterList::const_iterator i = outParams.begin(); i != outParams.end();) + for (auto i = outParams.begin(); i != outParams.end();) { os << typeToTsString((*i)->type(), true, false, (*i)->optional()); if (++i != outParams.end()) diff --git a/cpp/src/slice2js/JsUtil.cpp b/cpp/src/slice2js/JsUtil.cpp index b1e43f2e3b6..b18248427c9 100644 --- a/cpp/src/slice2js/JsUtil.cpp +++ b/cpp/src/slice2js/JsUtil.cpp @@ -37,8 +37,8 @@ Slice::relativePath(const string& p1, const string& p2) tokens1.pop_back(); tokens2.pop_back(); - vector::const_iterator i1 = tokens1.begin(); - vector::const_iterator i2 = tokens2.begin(); + auto i1 = tokens1.begin(); + auto i2 = tokens2.begin(); while (i1 != tokens1.end() && i2 != tokens2.end() && *i1 == *i2) { @@ -106,9 +106,9 @@ static vector fixIds(const vector& ids) { vector newIds; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (const auto& id : ids) { - newIds.push_back(lookupKwd(*i)); + newIds.push_back(lookupKwd(id)); } return newIds; } @@ -169,7 +169,7 @@ Slice::JsGenerator::fixId(const string& name) const vector newIds = fixIds(ids); stringstream result; - for (vector::const_iterator j = newIds.begin(); j != newIds.end(); ++j) + for (auto j = newIds.begin(); j != newIds.end(); ++j) { if (j != newIds.begin()) { @@ -323,7 +323,7 @@ Slice::JsGenerator::getLocalScope(const string& scope, const string& separator) // Return local scope for "::A::B::C" as A.B.C // stringstream result; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (auto i = ids.begin(); i != ids.end(); ++i) { if (i != ids.begin()) { diff --git a/cpp/src/slice2matlab/Main.cpp b/cpp/src/slice2matlab/Main.cpp index 5ddee9943ba..431d0a30b4d 100644 --- a/cpp/src/slice2matlab/Main.cpp +++ b/cpp/src/slice2matlab/Main.cpp @@ -80,9 +80,9 @@ namespace vector ids = splitScopedName(ident); transform(ids.begin(), ids.end(), ids.begin(), [](const string& id) -> string { return lookupKwd(id); }); stringstream result; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (const auto& id : ids) { - result << "::" + *i; + result << "::" + id; } return result.str(); } @@ -745,12 +745,12 @@ namespace out << l.front(); l.pop_front(); } - for (StringList::const_iterator i = l.begin(); i != l.end(); ++i) + for (const auto& i : l) { out << nl << "%"; - if (!i->empty()) + if (!i.empty()) { - out << space << *i; + out << space << i; } } } @@ -760,7 +760,7 @@ namespace // // Write the first sentence. // - for (StringList::const_iterator i = lines.begin(); i != lines.end(); ++i) + for (auto i = lines.begin(); i != lines.end(); ++i) { const string ws = " \t"; @@ -815,7 +815,7 @@ namespace // All references must be on one line. // out << nl << "% See also "; - for (StringList::const_iterator p = seeAlso.begin(); p != seeAlso.end(); ++p) + for (auto p = seeAlso.begin(); p != seeAlso.end(); ++p) { if (p != seeAlso.begin()) { @@ -1017,19 +1017,19 @@ namespace const ParameterList inParams = p->inParameters(); string ctxName = "context"; string resultName = "result"; - for (ParameterList::const_iterator q = inParams.begin(); q != inParams.end(); ++q) + for (const auto& inParam : inParams) { - if ((*q)->name() == "context") + if (inParam->name() == "context") { ctxName = "context_"; } - if ((*q)->name() == "result") + if (inParam->name() == "result") { resultName = "result_"; } - out << nl << "% " << fixIdent((*q)->name()) << " (" << typeToString((*q)->type()) << ")"; - map::const_iterator r = docParameters.find((*q)->name()); + out << nl << "% " << fixIdent(inParam->name()) << " (" << typeToString(inParam->type()) << ")"; + auto r = docParameters.find(inParam->name()); if (r != docParameters.end() && !r->second.empty()) { out << " - "; @@ -1048,9 +1048,9 @@ namespace const ParameterList outParams = p->outParameters(); if (p->returnType() || !outParams.empty()) { - for (ParameterList::const_iterator q = outParams.begin(); q != outParams.end(); ++q) + for (const auto& outParam : outParams) { - if ((*q)->name() == "result") + if (outParam->name() == "result") { resultName = "result_"; } @@ -1070,7 +1070,7 @@ namespace else if (!p->returnType() && outParams.size() == 1) { out << nl << "% Returns (" << typeToString(outParams.front()->type()) << ")"; - map::const_iterator q = docParameters.find(outParams.front()->name()); + auto q = docParameters.find(outParams.front()->name()); if (q != docParameters.end() && !q->second.empty()) { out << " - "; @@ -1090,10 +1090,11 @@ namespace writeDocLines(out, docReturns, false, " "); } } - for (ParameterList::const_iterator q = outParams.begin(); q != outParams.end(); ++q) + for (const auto& outParam : outParams) { - out << nl << "% " << fixIdent((*q)->name()) << " (" << typeToString((*q)->type()) << ")"; - map::const_iterator r = docParameters.find((*q)->name()); + out << nl << "% " << fixIdent(outParam->name()) << " (" << typeToString(outParam->type()) + << ")"; + auto r = docParameters.find(outParam->name()); if (r != docParameters.end() && !r->second.empty()) { out << " - "; @@ -1182,9 +1183,8 @@ namespace const OperationList ops = p->operations(); if (!ops.empty()) { - for (OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q) + for (const auto& op : ops) { - OperationPtr op = *q; DocCommentPtr opdoc = op->parseDocComment(matlabLinkFormatter, true); out << nl << "% " << fixOp(op->name()); if (opdoc) @@ -1423,13 +1423,13 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { out << nl << "properties"; out.inc(); - for (DataMemberList::const_iterator q = pub.begin(); q != pub.end(); ++q) + for (const auto& q : pub) { - writeMemberDoc(out, *q); - out << nl << fixIdent((*q)->name()); - if (declarePropertyType((*q)->type(), (*q)->optional())) + writeMemberDoc(out, q); + out << nl << fixIdent(q->name()); + if (declarePropertyType(q->type(), q->optional())) { - out << " " << typeToString((*q)->type()); + out << " " << typeToString(q->type()); } } out.dec(); @@ -1439,13 +1439,13 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { out << nl << "properties(Access=protected)"; out.inc(); - for (DataMemberList::const_iterator q = prot.begin(); q != prot.end(); ++q) + for (const auto& q : prot) { - writeMemberDoc(out, *q); - out << nl << fixIdent((*q)->name()); - if (declarePropertyType((*q)->type(), (*q)->optional())) + writeMemberDoc(out, q); + out << nl << fixIdent(q->name()); + if (declarePropertyType(q->type(), q->optional())) { - out << " " << typeToString((*q)->type()); + out << " " << typeToString(q->type()); } } out.dec(); @@ -1478,9 +1478,9 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) else { vector allNames; - for (MemberInfoList::const_iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - allNames.push_back(q->fixedName); + allNames.push_back(allMember.fixedName); } out << nl << "function " << self << " = " << name << spar << allNames << epar; out.inc(); @@ -1488,9 +1488,9 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { out << nl << "if nargin == 0"; out.inc(); - for (MemberInfoList::const_iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - out << nl << q->fixedName << " = " << defaultValue(q->dataMember) << ';'; + out << nl << allMember.fixedName << " = " << defaultValue(allMember.dataMember) << ';'; } writeBaseClassArrayParams(out, allMembers, false); out.dec(); @@ -1508,11 +1508,11 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) out << nl << "if ne(" << allMembers.begin()->fixedName << ", IceInternal.NoInit.Instance)"; out.inc(); - for (MemberInfoList::const_iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (!q->inherited) + if (!allMember.inherited) { - out << nl << self << "." << q->fixedName << " = " << q->fixedName << ';'; + out << nl << self << "." << allMember.fixedName << " = " << allMember.fixedName << ';'; } } out.dec(); @@ -1522,16 +1522,16 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { out << nl << "if nargin == 0"; out.inc(); - for (MemberInfoList::const_iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - out << nl << self << "." << q->fixedName << " = " << defaultValue(q->dataMember) << ';'; + out << nl << self << "." << allMember.fixedName << " = " << defaultValue(allMember.dataMember) << ';'; } out.dec(); out << nl << "elseif ne(" << allMembers.begin()->fixedName << ", IceInternal.NoInit.Instance)"; out.inc(); - for (MemberInfoList::const_iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - out << nl << self << "." << q->fixedName << " = " << q->fixedName << ';'; + out << nl << self << "." << allMember.fixedName << " = " << allMember.fixedName << ';'; } out.dec(); out << nl << "end"; @@ -1551,11 +1551,11 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) out << nl << "end"; DataMemberList convertMembers; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (needsConversion((*d)->type())) + if (needsConversion(member->type())) { - convertMembers.push_back(*d); + convertMembers.push_back(member); } } @@ -1571,10 +1571,10 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) out << nl << "end"; out << nl << "function icePostUnmarshal(obj)"; out.inc(); - for (DataMemberList::const_iterator d = convertMembers.begin(); d != convertMembers.end(); ++d) + for (const auto& convertMember : convertMembers) { - string m = "obj." + fixIdent((*d)->name()); - convertValueType(out, m, m, (*d)->type(), (*d)->optional()); + string m = "obj." + fixIdent(convertMember->name()); + convertValueType(out, m, m, convertMember->type(), convertMember->optional()); } if (base) { @@ -1595,16 +1595,22 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) out << nl << "function iceWriteImpl(obj, os)"; out.inc(); out << nl << "os.startSlice('" << scoped << "', " << p->compactId() << (!base ? ", true" : ", false") << ");"; - for (DataMemberList::const_iterator d = members.begin(); d != members.end(); ++d) + for (const auto& member : members) { - if (!(*d)->optional()) + if (!member->optional()) { - marshal(out, "os", "obj." + fixIdent((*d)->name()), (*d)->type(), false, 0); + marshal(out, "os", "obj." + fixIdent(member->name()), member->type(), false, 0); } } - for (DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) + for (const auto& optionalMember : optionalMembers) { - marshal(out, "os", "obj." + fixIdent((*d)->name()), (*d)->type(), true, (*d)->tag()); + marshal( + out, + "os", + "obj." + fixIdent(optionalMember->name()), + optionalMember->type(), + true, + optionalMember->tag()); } out << nl << "os.endSlice();"; if (base) @@ -1650,9 +1656,9 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // For each class data member, we generate an "iceSetMember_" method that is called when the // instance is eventually unmarshaled. // - for (DataMemberList::const_iterator d = classMembers.begin(); d != classMembers.end(); ++d) + for (const auto& classMember : classMembers) { - string m = fixIdent((*d)->name()); + string m = fixIdent(classMember->name()); out << nl << "function iceSetMember_" << m << "(obj, v)"; out.inc(); out << nl << "obj." << m << " = v;"; @@ -1730,7 +1736,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) out << nl << "classdef " << prxName << " < "; if (!bases.empty()) { - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end(); ++q) + for (auto q = bases.begin(); q != bases.end(); ++q) { if (q != bases.begin()) { @@ -1754,9 +1760,8 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // bool hasExceptions = false; const OperationList ops = p->operations(); - for (OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q) + for (const auto& op : ops) { - OperationPtr op = *q; ParamInfoList requiredInParams, optionalInParams; getInParams(op, requiredInParams, optionalInParams); ParamInfoList requiredOutParams, optionalOutParams; @@ -1775,16 +1780,16 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // Ensure no parameter is named "obj". // string self = "obj"; - for (ParamInfoList::const_iterator r = allOutParams.begin(); r != allOutParams.end(); ++r) + for (const auto& allOutParam : allOutParams) { - if (r->fixedName == "obj") + if (allOutParam.fixedName == "obj") { self = "obj_"; } } - for (ParamInfoList::const_iterator r = allInParams.begin(); r != allInParams.end(); ++r) + for (const auto& allInParam : allInParams) { - if (r->fixedName == "obj") + if (allInParam.fixedName == "obj") { self = "obj_"; } @@ -1797,7 +1802,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (allOutParams.size() > 1) { out << "["; - for (ParamInfoList::const_iterator r = allOutParams.begin(); r != allOutParams.end(); ++r) + for (auto r = allOutParams.begin(); r != allOutParams.end(); ++r) { if (r != allOutParams.begin()) { @@ -1814,9 +1819,9 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) out << fixOp(op->name()) << spar; out << self; - for (ParamInfoList::const_iterator r = allInParams.begin(); r != allInParams.end(); ++r) + for (const auto& allInParam : allInParams) { - out << r->fixedName; + out << allInParam.fixedName; } out << "varargin"; // For the optional context out << epar; @@ -1834,13 +1839,19 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { out << nl << "os_ = " << self << ".iceStartWriteParams([]);"; } - for (ParamInfoList::const_iterator r = requiredInParams.begin(); r != requiredInParams.end(); ++r) + for (const auto& requiredInParam : requiredInParams) { - marshal(out, "os_", r->fixedName, r->type, false, 0); + marshal(out, "os_", requiredInParam.fixedName, requiredInParam.type, false, 0); } - for (ParamInfoList::const_iterator r = optionalInParams.begin(); r != optionalInParams.end(); ++r) + for (const auto& optionalInParam : optionalInParams) { - marshal(out, "os_", r->fixedName, r->type, r->optional, r->tag); + marshal( + out, + "os_", + optionalInParam.fixedName, + optionalInParam.type, + optionalInParam.optional, + optionalInParam.tag); } if (op->sendsClasses()) { @@ -1879,26 +1890,26 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // ParamInfoList classParams; ParamInfoList convertParams; - for (ParamInfoList::const_iterator r = requiredOutParams.begin(); r != requiredOutParams.end(); ++r) + for (const auto& requiredOutParam : requiredOutParams) { - if (r->param) + if (requiredOutParam.param) { string param; - if (r->type->isClassType()) + if (requiredOutParam.type->isClassType()) { - out << nl << r->fixedName << "_h_ = IceInternal.ValueHolder();"; - param = "@(v) " + r->fixedName + "_h_.set(v)"; - classParams.push_back(*r); + out << nl << requiredOutParam.fixedName << "_h_ = IceInternal.ValueHolder();"; + param = "@(v) " + requiredOutParam.fixedName + "_h_.set(v)"; + classParams.push_back(requiredOutParam); } else { - param = r->fixedName; + param = requiredOutParam.fixedName; } - unmarshal(out, "is_", param, r->type, false, -1); + unmarshal(out, "is_", param, requiredOutParam.type, false, -1); - if (needsConversion(r->type)) + if (needsConversion(requiredOutParam.type)) { - convertParams.push_back(*r); + convertParams.push_back(requiredOutParam); } } } @@ -1907,7 +1918,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // if (!requiredOutParams.empty() && !requiredOutParams.begin()->param) { - ParamInfoList::const_iterator r = requiredOutParams.begin(); + auto r = requiredOutParams.begin(); string param; if (r->type->isClassType()) { @@ -1929,24 +1940,24 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // // Now unmarshal all optional out parameters. They are already sorted by tag. // - for (ParamInfoList::const_iterator r = optionalOutParams.begin(); r != optionalOutParams.end(); ++r) + for (const auto& optionalOutParam : optionalOutParams) { string param; - if (r->type->isClassType()) + if (optionalOutParam.type->isClassType()) { - out << nl << r->fixedName << "_h_ = IceInternal.ValueHolder();"; - param = "@(v) " + r->fixedName + "_h_.set(v)"; - classParams.push_back(*r); + out << nl << optionalOutParam.fixedName << "_h_ = IceInternal.ValueHolder();"; + param = "@(v) " + optionalOutParam.fixedName + "_h_.set(v)"; + classParams.push_back(optionalOutParam); } else { - param = r->fixedName; + param = optionalOutParam.fixedName; } - unmarshal(out, "is_", param, r->type, r->optional, r->tag); + unmarshal(out, "is_", param, optionalOutParam.type, optionalOutParam.optional, optionalOutParam.tag); - if (needsConversion(r->type)) + if (needsConversion(optionalOutParam.type)) { - convertParams.push_back(*r); + convertParams.push_back(optionalOutParam); } } if (op->returnsClasses()) @@ -1958,14 +1969,19 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // After calling readPendingValues(), all callback functions have been invoked. // Now we need to collect the values. // - for (ParamInfoList::const_iterator r = classParams.begin(); r != classParams.end(); ++r) + for (const auto& classParam : classParams) { - out << nl << r->fixedName << " = " << r->fixedName << "_h_.value;"; + out << nl << classParam.fixedName << " = " << classParam.fixedName << "_h_.value;"; } - for (ParamInfoList::const_iterator r = convertParams.begin(); r != convertParams.end(); ++r) + for (const auto& convertParam : convertParams) { - convertValueType(out, r->fixedName, r->fixedName, r->type, r->optional); + convertValueType( + out, + convertParam.fixedName, + convertParam.fixedName, + convertParam.type, + convertParam.optional); } } @@ -1977,9 +1993,9 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // out << nl << "function r_ = " << op->name() << "Async" << spar; out << self; - for (ParamInfoList::const_iterator r = allInParams.begin(); r != allInParams.end(); ++r) + for (const auto& allInParam : allInParams) { - out << r->fixedName; + out << allInParam.fixedName; } out << "varargin"; // For the optional context out << epar; @@ -1997,13 +2013,19 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { out << nl << "os_ = " << self << ".iceStartWriteParams([]);"; } - for (ParamInfoList::const_iterator r = requiredInParams.begin(); r != requiredInParams.end(); ++r) + for (const auto& requiredInParam : requiredInParams) { - marshal(out, "os_", r->fixedName, r->type, false, 0); + marshal(out, "os_", requiredInParam.fixedName, requiredInParam.type, false, 0); } - for (ParamInfoList::const_iterator r = optionalInParams.begin(); r != optionalInParams.end(); ++r) + for (const auto& optionalInParam : optionalInParams) { - marshal(out, "os_", r->fixedName, r->type, r->optional, r->tag); + marshal( + out, + "os_", + optionalInParam.fixedName, + optionalInParam.type, + optionalInParam.optional, + optionalInParam.tag); } if (op->sendsClasses()) { @@ -2024,21 +2046,27 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // * unmarshal the required return value (if any) // * unmarshal all optional out parameters (this includes an optional return value) // - for (ParamInfoList::const_iterator r = requiredOutParams.begin(); r != requiredOutParams.end(); ++r) + for (const auto& requiredOutParam : requiredOutParams) { - if (r->param) + if (requiredOutParam.param) { string param; - if (r->type->isClassType()) + if (requiredOutParam.type->isClassType()) { - out << nl << r->fixedName << " = IceInternal.ValueHolder();"; - param = "@(v) " + r->fixedName + ".set(v)"; + out << nl << requiredOutParam.fixedName << " = IceInternal.ValueHolder();"; + param = "@(v) " + requiredOutParam.fixedName + ".set(v)"; } else { - param = r->fixedName; + param = requiredOutParam.fixedName; } - unmarshal(out, "is_", param, r->type, r->optional, r->tag); + unmarshal( + out, + "is_", + param, + requiredOutParam.type, + requiredOutParam.optional, + requiredOutParam.tag); } } // @@ -2046,7 +2074,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // if (!requiredOutParams.empty() && !requiredOutParams.begin()->param) { - ParamInfoList::const_iterator r = requiredOutParams.begin(); + auto r = requiredOutParams.begin(); string param; if (r->type->isClassType()) { @@ -2062,57 +2090,69 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // // Now unmarshal all optional out parameters. They are already sorted by tag. // - for (ParamInfoList::const_iterator r = optionalOutParams.begin(); r != optionalOutParams.end(); ++r) + for (const auto& optionalOutParam : optionalOutParams) { string param; - if (r->type->isClassType()) + if (optionalOutParam.type->isClassType()) { - out << nl << r->fixedName << " = IceInternal.ValueHolder();"; - param = "@(v) " + r->fixedName + ".set(v)"; + out << nl << optionalOutParam.fixedName << " = IceInternal.ValueHolder();"; + param = "@(v) " + optionalOutParam.fixedName + ".set(v)"; } else { - param = r->fixedName; + param = optionalOutParam.fixedName; } - unmarshal(out, "is_", param, r->type, r->optional, r->tag); + unmarshal(out, "is_", param, optionalOutParam.type, optionalOutParam.optional, optionalOutParam.tag); } if (op->returnsClasses()) { out << nl << "is_.readPendingValues();"; } out << nl << "is_.endEncapsulation();"; - for (ParamInfoList::const_iterator r = requiredOutParams.begin(); r != requiredOutParams.end(); ++r) + for (const auto& requiredOutParam : requiredOutParams) { - if (r->type->isClassType()) + if (requiredOutParam.type->isClassType()) { - out << nl << "varargout{" << r->pos << "} = " << r->fixedName << ".value;"; + out << nl << "varargout{" << requiredOutParam.pos << "} = " << requiredOutParam.fixedName + << ".value;"; } - else if (needsConversion(r->type)) + else if (needsConversion(requiredOutParam.type)) { ostringstream dest; - dest << "varargout{" << r->pos << "}"; - convertValueType(out, dest.str(), r->fixedName, r->type, r->optional); + dest << "varargout{" << requiredOutParam.pos << "}"; + convertValueType( + out, + dest.str(), + requiredOutParam.fixedName, + requiredOutParam.type, + requiredOutParam.optional); } else { - out << nl << "varargout{" << r->pos << "} = " << r->fixedName << ';'; + out << nl << "varargout{" << requiredOutParam.pos << "} = " << requiredOutParam.fixedName << ';'; } } - for (ParamInfoList::const_iterator r = optionalOutParams.begin(); r != optionalOutParams.end(); ++r) + for (const auto& optionalOutParam : optionalOutParams) { - if (r->type->isClassType()) + if (optionalOutParam.type->isClassType()) { - out << nl << "varargout{" << r->pos << "} = " << r->fixedName << ".value;"; + out << nl << "varargout{" << optionalOutParam.pos << "} = " << optionalOutParam.fixedName + << ".value;"; } - else if (needsConversion(r->type)) + else if (needsConversion(optionalOutParam.type)) { ostringstream dest; - dest << "varargout{" << r->pos << "}"; - convertValueType(out, dest.str(), r->fixedName, r->type, r->optional); + dest << "varargout{" << optionalOutParam.pos << "}"; + convertValueType( + out, + dest.str(), + optionalOutParam.fixedName, + optionalOutParam.type, + optionalOutParam.optional); } else { - out << nl << "varargout{" << r->pos << "} = " << r->fixedName << ';'; + out << nl << "varargout{" << optionalOutParam.pos << "} = " << optionalOutParam.fixedName << ';'; } } out.dec(); @@ -2194,10 +2234,8 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // out << nl << "properties(Constant,Access=private)"; out.inc(); - for (OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q) + for (const auto& op : ops) { - OperationPtr op = *q; - // Arrange exceptions into most-derived to least-derived order. If we don't // do this, a base exception handler can appear before a derived exception // handler, causing compiler warnings and resulting in the base exception @@ -2208,7 +2246,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (!exceptions.empty()) { out << nl << op->name() << "_ex_ = { "; - for (ExceptionList::const_iterator e = exceptions.begin(); e != exceptions.end(); ++e) + for (auto e = exceptions.begin(); e != exceptions.end(); ++e) { if (e != exceptions.begin()) { @@ -2263,13 +2301,13 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p) { out << nl << "properties"; out.inc(); - for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - writeMemberDoc(out, *q); - out << nl << fixExceptionMember((*q)->name()); - if (declarePropertyType((*q)->type(), (*q)->optional())) + writeMemberDoc(out, member); + out << nl << fixExceptionMember(member->name()); + if (declarePropertyType(member->type(), member->optional())) { - out << " " << typeToString((*q)->type()); + out << " " << typeToString(member->type()); } } out.dec(); @@ -2281,13 +2319,13 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p) vector allNames; MemberInfoList convertMembers; - for (MemberInfoList::const_iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - allNames.push_back(q->fixedName); + allNames.push_back(allMember.fixedName); - if (!q->inherited && needsConversion(q->dataMember->type())) + if (!allMember.inherited && needsConversion(allMember.dataMember->type())) { - convertMembers.push_back(*q); + convertMembers.push_back(allMember); } } out << nl << "methods"; @@ -2350,15 +2388,15 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p) out.inc(); out << nl << "function obj = icePostUnmarshal(obj)"; out.inc(); - for (DataMemberList::const_iterator q = classMembers.begin(); q != classMembers.end(); ++q) + for (const auto& classMember : classMembers) { - string m = fixExceptionMember((*q)->name()); + string m = fixExceptionMember(classMember->name()); out << nl << "obj." << m << " = obj." << m << ".value;"; } - for (MemberInfoList::const_iterator q = convertMembers.begin(); q != convertMembers.end(); ++q) + for (const auto& convertMember : convertMembers) { - string m = "obj." + q->fixedName; - convertValueType(out, m, m, q->dataMember->type(), q->dataMember->optional()); + string m = "obj." + convertMember.fixedName; + convertValueType(out, m, m, convertMember.dataMember->type(), convertMember.dataMember->optional()); } if (base && base->usesClasses()) { @@ -2448,20 +2486,20 @@ CodeVisitor::visitStructStart(const StructPtr& p) out.inc(); vector memberNames; DataMemberList convertMembers; - for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - const string m = fixStructMember((*q)->name()); + const string m = fixStructMember(member->name()); memberNames.push_back(m); - writeMemberDoc(out, *q); + writeMemberDoc(out, member); out << nl << m; - if (declarePropertyType((*q)->type(), false)) + if (declarePropertyType(member->type(), false)) { - out << " " << typeToString((*q)->type()); + out << " " << typeToString(member->type()); } - if (needsConversion((*q)->type())) + if (needsConversion(member->type())) { - convertMembers.push_back(*q); + convertMembers.push_back(member); } } out.dec(); @@ -2474,16 +2512,16 @@ CodeVisitor::visitStructStart(const StructPtr& p) out.inc(); out << nl << "if nargin == 0"; out.inc(); - for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - out << nl << self << "." << fixStructMember((*q)->name()) << " = " << defaultValue(*q) << ';'; + out << nl << self << "." << fixStructMember(member->name()) << " = " << defaultValue(member) << ';'; } out.dec(); out << nl << "elseif ne(" << fixStructMember((*members.begin())->name()) << ", IceInternal.NoInit.Instance)"; out.inc(); - for (vector::const_iterator q = memberNames.begin(); q != memberNames.end(); ++q) + for (const auto& memberName : memberNames) { - out << nl << self << "." << *q << " = " << *q << ';'; + out << nl << self << "." << memberName << " = " << memberName << ';'; } out.dec(); out << nl << "end"; @@ -2528,9 +2566,9 @@ CodeVisitor::visitStructStart(const StructPtr& p) out << nl << "v = " << abs << "();"; out.dec(); out << nl << "end"; - for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - marshal(out, "os", "v." + fixStructMember((*q)->name()), (*q)->type(), false, 0); + marshal(out, "os", "v." + fixStructMember(member->name()), member->type(), false, 0); } out.dec(); out << nl << "end"; @@ -3213,11 +3251,11 @@ CodeVisitor::visitEnum(const EnumPtr& p) out.inc(); out << nl << "switch v"; out.inc(); - for (EnumeratorList::const_iterator q = enumerators.begin(); q != enumerators.end(); ++q) + for (const auto& enumerator : enumerators) { - out << nl << "case " << (*q)->value(); + out << nl << "case " << enumerator->value(); out.inc(); - out << nl << "r = " << abs << "." << fixEnumerator((*q)->name()) << ";"; + out << nl << "r = " << abs << "." << fixEnumerator(enumerator->name()) << ";"; out.dec(); } out << nl << "otherwise"; @@ -3292,12 +3330,12 @@ CodeVisitor::collectClassMembers(const ClassDefPtr& p, MemberInfoList& allMember DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { MemberInfo m; - m.fixedName = fixIdent((*q)->name()); + m.fixedName = fixIdent(member->name()); m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -3313,12 +3351,12 @@ CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, MemberInfoList& allM DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { MemberInfo m; - m.fixedName = fixExceptionMember((*q)->name()); + m.fixedName = fixExceptionMember(member->name()); m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -3328,14 +3366,14 @@ CodeVisitor::getAllInParams(const OperationPtr& op) { const ParameterList l = op->inParameters(); ParamInfoList r; - for (ParameterList::const_iterator p = l.begin(); p != l.end(); ++p) + for (const auto& p : l) { ParamInfo info; - info.fixedName = fixIdent((*p)->name()); - info.type = (*p)->type(); - info.optional = (*p)->optional(); - info.tag = (*p)->tag(); - info.param = *p; + info.fixedName = fixIdent(p->name()); + info.type = p->type(); + info.optional = p->optional(); + info.tag = p->tag(); + info.param = p; r.push_back(info); } return r; @@ -3345,15 +3383,15 @@ void CodeVisitor::getInParams(const OperationPtr& op, ParamInfoList& required, ParamInfoList& optional) { const ParamInfoList params = getAllInParams(op); - for (ParamInfoList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { - if (p->optional) + if (param.optional) { - optional.push_back(*p); + optional.push_back(param); } else { - required.push_back(*p); + required.push_back(param); } } @@ -3381,9 +3419,9 @@ CodeVisitor::getAllOutParams(const OperationPtr& op) info.fixedName = "result"; info.pos = pos++; - for (ParameterList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { - if ((*p)->name() == "result") + if (param->name() == "result") { info.fixedName = "result_"; break; @@ -3395,15 +3433,15 @@ CodeVisitor::getAllOutParams(const OperationPtr& op) l.push_back(info); } - for (ParameterList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { ParamInfo info; - info.fixedName = fixIdent((*p)->name()); - info.type = (*p)->type(); - info.optional = (*p)->optional(); - info.tag = (*p)->tag(); + info.fixedName = fixIdent(param->name()); + info.type = param->type(); + info.optional = param->optional(); + info.tag = param->tag(); info.pos = pos++; - info.param = *p; + info.param = param; l.push_back(info); } @@ -3414,15 +3452,15 @@ void CodeVisitor::getOutParams(const OperationPtr& op, ParamInfoList& required, ParamInfoList& optional) { const ParamInfoList params = getAllOutParams(op); - for (ParamInfoList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { - if (p->optional) + if (param.optional) { - optional.push_back(*p); + optional.push_back(param); } else { - required.push_back(*p); + required.push_back(param); } } @@ -3974,18 +4012,18 @@ CodeVisitor::writeBaseClassArrayParams(IceInternal::Output& out, const MemberInf { out << nl << "v = { "; bool first = true; - for (MemberInfoList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - if (q->inherited) + if (member.inherited) { if (first) { - out << (noInit ? "IceInternal.NoInit.Instance" : q->fixedName); + out << (noInit ? "IceInternal.NoInit.Instance" : member.fixedName); first = false; } else { - out << ", " << (noInit ? "[]" : q->fixedName); + out << ", " << (noInit ? "[]" : member.fixedName); } } } @@ -4077,21 +4115,21 @@ compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& arg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + arg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& arg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + arg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -4146,12 +4184,12 @@ compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // // Ignore duplicates. // - vector::iterator p = find(args.begin(), args.end(), *i); + auto p = find(args.begin(), args.end(), *i); if (p != i) { continue; diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index f62dc2176e2..ee034d11a4e 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -205,26 +205,26 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << nl << "parent::__construct("; int count = 0; - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (q->inherited) + if (allMember.inherited) { if (count) { _out << ", "; } - _out << '$' << q->fixedName; + _out << '$' << allMember.fixedName; ++count; } } _out << ");"; } { - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (!q->inherited) + if (!allMember.inherited) { - writeAssign(*q); + writeAssign(allMember); } } } @@ -292,9 +292,9 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << type << ";"; seenType.push_back(type); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - string type = getType((*q)->type()); + string type = getType(member->type()); if (find(seenType.begin(), seenType.end(), type) == seenType.end()) { seenType.push_back(type); @@ -325,7 +325,7 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) if (!members.empty()) { _out << "array("; - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (auto q = members.begin(); q != members.end(); ++q) { if (q != members.begin()) { @@ -410,7 +410,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) if (!bases.empty()) { _out << "array("; - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end(); ++q) + for (auto q = bases.begin(); q != bases.end(); ++q) { if (q != bases.begin()) { @@ -437,12 +437,12 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _out << sp; vector seenTypes; - for (OperationList::const_iterator p = ops.begin(); p != ops.end(); ++p) + for (const auto& op : ops) { - ParameterList params = (*p)->parameters(); - for (ParameterList::const_iterator q = params.begin(); q != params.end(); ++q) + ParameterList params = op->parameters(); + for (const auto& param : params) { - string type = getType((*q)->type()); + string type = getType(param->type()); if (find(seenTypes.begin(), seenTypes.end(), type) == seenTypes.end()) { seenTypes.push_back(type); @@ -450,9 +450,9 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } } - if ((*p)->returnType()) + if (op->returnType()) { - string type = getType((*p)->returnType()); + string type = getType(op->returnType()); if (find(seenTypes.begin(), seenTypes.end(), type) == seenTypes.end()) { seenTypes.push_back(type); @@ -461,22 +461,22 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } } - for (OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli) + for (const auto& op : ops) { - ParameterList params = (*oli)->parameters(); + ParameterList params = op->parameters(); ParameterList::iterator t; int count; // We encode nullopt as -1. - optional opFormat = (*oli)->format(); + optional opFormat = op->format(); int phpFormat = -1; if (opFormat) { phpFormat = static_cast(*opFormat); } - _out << nl << "IcePHP_defineOperation(" << prxType << ", '" << (*oli)->name() << "', " - << getOperationMode((*oli)->mode()) << ", " << phpFormat << ", "; + _out << nl << "IcePHP_defineOperation(" << prxType << ", '" << op->name() << "', " + << getOperationMode(op->mode()) << ", " << phpFormat << ", "; for (t = params.begin(), count = 0; t != params.end(); ++t) { if (!(*t)->isOutParam()) @@ -539,7 +539,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << "null"; } _out << ", "; - TypePtr returnType = (*oli)->returnType(); + TypePtr returnType = op->returnType(); if (returnType) { // The return type has the same format as an in/out parameter: @@ -547,9 +547,9 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // Type, Optional?, OptionalTag _out << "array("; writeType(returnType); - if ((*oli)->returnIsOptional()) + if (op->returnIsOptional()) { - _out << ", " << (*oli)->returnTag(); + _out << ", " << op->returnTag(); } _out << ')'; } @@ -559,11 +559,11 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } _out << ", "; - ExceptionList exceptions = (*oli)->throws(); + ExceptionList exceptions = op->throws(); if (!exceptions.empty()) { _out << "array("; - for (ExceptionList::iterator u = exceptions.begin(); u != exceptions.end(); ++u) + for (auto u = exceptions.begin(); u != exceptions.end(); ++u) { if (u != exceptions.begin()) { @@ -635,18 +635,18 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p) if (!members.empty()) { _out << sp; - for (DataMemberList::iterator dmli = members.begin(); dmli != members.end(); ++dmli) + for (const auto& member : members) { - _out << nl << "public $" << fixIdent((*dmli)->name()) << ";"; + _out << nl << "public $" << fixIdent(member->name()) << ";"; } } _out << eb; vector seenType; - for (DataMemberList::iterator dmli = members.begin(); dmli != members.end(); ++dmli) + for (const auto& member : members) { - string type = getType((*dmli)->type()); + string type = getType(member->type()); if (find(seenType.begin(), seenType.end(), type) == seenType.end()) { seenType.push_back(type); @@ -673,7 +673,7 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p) if (!members.empty()) { _out << "array("; - for (DataMemberList::iterator dmli = members.begin(); dmli != members.end(); ++dmli) + for (auto dmli = members.begin(); dmli != members.end(); ++dmli) { if (dmli != members.begin()) { @@ -710,12 +710,12 @@ CodeVisitor::visitStructStart(const StructPtr& p) { DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - memberList.push_back(MemberInfo()); - memberList.back().fixedName = fixIdent((*q)->name()); + memberList.emplace_back(); + memberList.back().fixedName = fixIdent(member->name()); memberList.back().inherited = false; - memberList.back().dataMember = *q; + memberList.back().dataMember = member; } } @@ -729,9 +729,9 @@ CodeVisitor::visitStructStart(const StructPtr& p) writeConstructorParams(memberList); _out << ")"; _out << sb; - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - writeAssign(*r); + writeAssign(r); } _out << eb; @@ -746,9 +746,9 @@ CodeVisitor::visitStructStart(const StructPtr& p) if (!memberList.empty()) { _out << sp; - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - _out << nl << "public $" << r->fixedName << ';'; + _out << nl << "public $" << r.fixedName << ';'; } } @@ -756,9 +756,9 @@ CodeVisitor::visitStructStart(const StructPtr& p) _out << sp; vector seenType; - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - string type = getType(r->dataMember->type()); + string type = getType(r.dataMember->type()); if (find(seenType.begin(), seenType.end(), type) == seenType.end()) { seenType.push_back(type); @@ -774,7 +774,7 @@ CodeVisitor::visitStructStart(const StructPtr& p) // ('MemberName', MemberType) // // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (auto r = memberList.begin(); r != memberList.end(); ++r) { if (r != memberList.begin()) { @@ -894,7 +894,7 @@ CodeVisitor::visitEnum(const EnumPtr& p) // Emit the type information. _out << sp << nl << type << " = IcePHP_defineEnum('" << scoped << "', array("; - for (EnumeratorList::const_iterator q = enumerators.begin(); q != enumerators.end(); ++q) + for (auto q = enumerators.begin(); q != enumerators.end(); ++q) { if (q != enumerators.begin()) { @@ -1173,7 +1173,7 @@ CodeVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePtr& va void CodeVisitor::writeConstructorParams(const MemberInfoList& members) { - for (MemberInfoList::const_iterator p = members.begin(); p != members.end(); ++p) + for (auto p = members.begin(); p != members.end(); ++p) { if (p != members.begin()) { @@ -1216,12 +1216,12 @@ CodeVisitor::collectClassMembers(const ClassDefPtr& p, MemberInfoList& allMember DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { MemberInfo m; - m.fixedName = fixIdent((*q)->name()); + m.fixedName = fixIdent(member->name()); m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -1237,12 +1237,12 @@ CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, MemberInfoList& allM DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { MemberInfo m; - m.fixedName = fixIdent((*q)->name()); + m.fixedName = fixIdent(member->name()); m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -1253,9 +1253,9 @@ generate(const UnitPtr& un, bool all, const vector& includePaths, Output if (!all) { vector paths = includePaths; - for (vector::iterator p = paths.begin(); p != paths.end(); ++p) + for (auto& path : paths) { - *p = fullPath(*p); + path = fullPath(path); } StringList includes = un->includeFiles(); @@ -1264,9 +1264,9 @@ generate(const UnitPtr& un, bool all, const vector& includePaths, Output out << sp; out << nl << "namespace"; out << sb; - for (StringList::const_iterator q = includes.begin(); q != includes.end(); ++q) + for (const auto& include : includes) { - string file = changeInclude(*q, paths); + string file = changeInclude(include, paths); out << nl << "require_once '" << file << ".php';"; } out << eb; @@ -1379,21 +1379,21 @@ compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + optarg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + optarg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -1446,10 +1446,10 @@ compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // Ignore duplicates. - vector::iterator p = find(args.begin(), args.end(), *i); + auto p = find(args.begin(), args.end(), *i); if (p != i) { continue; diff --git a/cpp/src/slice2php/PHPUtil.cpp b/cpp/src/slice2php/PHPUtil.cpp index cdf4a58eaee..91e545e270f 100644 --- a/cpp/src/slice2php/PHPUtil.cpp +++ b/cpp/src/slice2php/PHPUtil.cpp @@ -154,9 +154,9 @@ Slice::PHP::fixIdent(const string& ident) vector ids = splitScopedName(ident); transform(ids.begin(), ids.end(), ids.begin(), [](const string& id) -> string { return lookupKwd(id); }); stringstream result; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (const auto& id : ids) { - result << "::" + *i; + result << "::" + id; } return result.str(); } diff --git a/cpp/src/slice2py/Python.cpp b/cpp/src/slice2py/Python.cpp index 189994cbc83..545884fd2f8 100644 --- a/cpp/src/slice2py/Python.cpp +++ b/cpp/src/slice2py/Python.cpp @@ -87,13 +87,13 @@ namespace // Create all necessary subdirectories. // string path = output; - for (vector::iterator p = elements.begin(); p != elements.end(); ++p) + for (const auto& element : elements) { if (!path.empty()) { path += "/"; } - path += *p; + path += element; IceInternal::structstat st; if (IceInternal::stat(path, &st) < 0) { @@ -185,8 +185,8 @@ namespace StringList& _modules; }; - const string moduleTag = "# Modules:"; // NOLINT:cert-err58-cpp - const string submoduleTag = "# Submodules:"; // NOLINT:cert-err58-cpp + const string moduleTag = "# Modules:"; // NOLINT(cert-err58-cpp) + const string submoduleTag = "# Submodules:"; // NOLINT(cert-err58-cpp) PackageVisitor::PackageVisitor(StringList& modules) : _modules(modules) {} @@ -196,16 +196,16 @@ namespace PackageVisitor v(modules); unt->visit(&v); - for (StringList::iterator p = modules.begin(); p != modules.end(); ++p) + for (const auto& p : modules) { vector vs; - if (!IceInternal::splitString(*p, ".", vs)) + if (!IceInternal::splitString(p, ".", vs)) { assert(false); } string currentModule; string path = dir.empty() ? "." : dir; - for (vector::iterator q = vs.begin(); q != vs.end(); ++q) + for (auto q = vs.begin(); q != vs.end(); ++q) { if (q != vs.begin()) { @@ -248,7 +248,7 @@ namespace // StringList modules, submodules; readInit(dir, modules, submodules); - StringList::iterator p = find(modules.begin(), modules.end(), name); + auto p = find(modules.begin(), modules.end(), name); if (p == modules.end()) { modules.push_back(name); @@ -263,7 +263,7 @@ namespace // StringList modules, submodules; readInit(dir, modules, submodules); - StringList::iterator p = find(submodules.begin(), submodules.end(), name); + auto p = find(submodules.begin(), submodules.end(), name); if (p == submodules.end()) { submodules.push_back(name); @@ -385,16 +385,16 @@ namespace os << "# Generated by slice2py - DO NOT EDIT!" << endl << "#" << endl; os << endl << "import Ice" << endl << "Ice.updateModule(\"" << name << "\")" << endl << endl; os << moduleTag << endl; - for (StringList::const_iterator p = modules.begin(); p != modules.end(); ++p) + for (const auto& module : modules) { - os << "import " << *p << endl; + os << "import " << module << endl; } os << endl; os << submoduleTag << endl; - for (StringList::const_iterator p = submodules.begin(); p != submodules.end(); ++p) + for (const auto& submodule : submodules) { - os << "from . import " << *p << endl; + os << "from . import " << submodule << endl; } } @@ -467,21 +467,21 @@ Slice::Python::compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& arg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + arg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& arg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + arg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -542,12 +542,12 @@ Slice::Python::compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // // Ignore duplicates. // - vector::iterator p = find(args.begin(), args.end(), *i); + auto p = find(args.begin(), args.end(), *i); if (p != i) { continue; diff --git a/cpp/src/slice2py/PythonUtil.cpp b/cpp/src/slice2py/PythonUtil.cpp index 92b47185c78..9e81ab114b4 100644 --- a/cpp/src/slice2py/PythonUtil.cpp +++ b/cpp/src/slice2py/PythonUtil.cpp @@ -21,9 +21,9 @@ namespace { ParameterList params = p->parameters(); - for (ParameterList::const_iterator i = params.begin(); i != params.end(); ++i) + for (const auto& param : params) { - if ((*i)->name() == name) + if (param->name() == name) { return name + "_"; } @@ -357,9 +357,9 @@ Slice::Python::ModuleVisitor::visitModuleStart(const ModulePtr& p) vector v; splitString(pkg, ".", v); string mod; - for (vector::iterator q = v.begin(); q != v.end(); ++q) + for (const auto& q : v) { - mod = mod.empty() ? *q : mod + "." + *q; + mod = mod.empty() ? q : mod + "." + q; if (_history.count(mod) == 0) { _out << nl << "_M_" << mod << " = Ice.openModule('" << mod << "')"; @@ -419,9 +419,9 @@ Slice::Python::CodeVisitor::visitModuleStart(const ModulePtr& p) vector v; splitString(pkg, ".", v); string mod; - for (vector::iterator q = v.begin(); q != v.end(); ++q) + for (const auto& q : v) { - mod = mod.empty() ? *q : mod + "." + *q; + mod = mod.empty() ? q : mod + "." + q; if (_moduleHistory.count(mod) == 0) // Don't emit this more than once for each module. { _out << nl << "_M_" << mod << " = Ice.openModule('" << mod << "')"; @@ -592,20 +592,20 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) if (base) { _out << nl << getSymbol(base) << ".__init__(self"; - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (q->inherited) + if (allMember.inherited) { - _out << ", " << q->fixedName; + _out << ", " << allMember.fixedName; } } _out << ')'; } - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (!q->inherited) + if (!allMember.inherited) { - writeAssign(*q); + writeAssign(allMember); } } } @@ -675,7 +675,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << nl; } bool isProtected = p->hasMetadata("protected"); - for (DataMemberList::iterator r = members.begin(); r != members.end(); ++r) + for (auto r = members.begin(); r != members.end(); ++r) { if (r != members.begin()) { @@ -739,10 +739,10 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { vector baseClasses; - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end(); ++q) + for (const auto& base : bases) { - InterfaceDefPtr d = *q; - baseClasses.push_back(getSymbol(*q, "", "Prx")); + InterfaceDefPtr d = base; + baseClasses.push_back(getSymbol(base, "", "Prx")); } if (baseClasses.empty()) @@ -751,7 +751,7 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } else { - vector::const_iterator q = baseClasses.begin(); + auto q = baseClasses.begin(); while (q != baseClasses.end()) { _out << *q; @@ -803,25 +803,25 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // Find the last required parameter, all optional parameters after the last required parameter will use // None as the default. ParameterPtr lastRequiredParameter; - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - if (!(*q)->isOutParam() && !(*q)->optional()) + if (!q->isOutParam() && !q->optional()) { - lastRequiredParameter = *q; + lastRequiredParameter = q; } } bool afterLastRequiredParameter = lastRequiredParameter == nullptr; - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - if (!(*q)->isOutParam()) + if (!q->isOutParam()) { if (!inParams.empty()) { inParams.append(", "); inParamsDecl.append(", "); } - string param = fixIdent((*q)->name()); + string param = fixIdent(q->name()); inParams.append(param); if (afterLastRequiredParameter) { @@ -829,7 +829,7 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } inParamsDecl.append(param); - if (*q == lastRequiredParameter) + if (q == lastRequiredParameter) { afterLastRequiredParameter = true; } @@ -907,10 +907,10 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << nl << "class " << className << '('; { vector baseClasses; - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end(); ++q) + for (const auto& base : bases) { - InterfaceDefPtr d = *q; - baseClasses.push_back(getSymbol(*q, "", "")); + InterfaceDefPtr d = base; + baseClasses.push_back(getSymbol(base, "", "")); } if (baseClasses.empty()) @@ -919,7 +919,7 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } else { - vector::const_iterator q = baseClasses.begin(); + auto q = baseClasses.begin(); while (q != baseClasses.end()) { _out << *q; @@ -942,7 +942,7 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << sp << nl << "def ice_ids(self, current=None):"; _out.inc(); _out << nl << "return ("; - for (StringList::iterator q = ids.begin(); q != ids.end(); ++q) + for (auto q = ids.begin(); q != ids.end(); ++q) { if (q != ids.begin()) { @@ -1089,7 +1089,7 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } _out << ", ("; ExceptionList exceptions = operation->throws(); - for (ExceptionList::iterator u = exceptions.begin(); u != exceptions.end(); ++u) + for (auto u = exceptions.begin(); u != exceptions.end(); ++u) { if (u != exceptions.begin()) { @@ -1169,20 +1169,20 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) if (base) { _out << nl << baseName << ".__init__(self"; - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (q->inherited) + if (allMember.inherited) { - _out << ", " << q->fixedName; + _out << ", " << allMember.fixedName; } } _out << ')'; } - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (!q->inherited) + if (!allMember.inherited) { - writeAssign(*q); + writeAssign(allMember); } } } @@ -1232,7 +1232,7 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) // // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. // - for (DataMemberList::iterator dmli = members.begin(); dmli != members.end(); ++dmli) + for (auto dmli = members.begin(); dmli != members.end(); ++dmli) { if (dmli != members.begin()) { @@ -1274,12 +1274,12 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p) MemberInfoList memberList; { - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - memberList.push_back(MemberInfo()); - memberList.back().fixedName = fixIdent((*q)->name()); + memberList.emplace_back(); + memberList.back().fixedName = fixIdent(member->name()); memberList.back().inherited = false; - memberList.back().dataMember = *q; + memberList.back().dataMember = member; } } @@ -1295,9 +1295,9 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p) writeConstructorParams(memberList); _out << "):"; _out.inc(); - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - writeAssign(*r); + writeAssign(r); } _out.dec(); @@ -1310,10 +1310,10 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p) _out.inc(); _out << nl << "_h = 0"; int iter = 0; - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - string s = "self." + r->fixedName; - writeHash(s, r->dataMember->type(), iter); + string s = "self." + r.fixedName; + writeHash(s, r.dataMember->type(), iter); } _out << nl << "return _h % 0x7fffffff"; _out.dec(); @@ -1334,25 +1334,25 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p) _out.dec(); _out << nl << "else:"; _out.inc(); - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { // // The None value is not orderable in Python 3. // - _out << nl << "if self." << r->fixedName << " is None or other." << r->fixedName << " is None:"; + _out << nl << "if self." << r.fixedName << " is None or other." << r.fixedName << " is None:"; _out.inc(); - _out << nl << "if self." << r->fixedName << " != other." << r->fixedName << ':'; + _out << nl << "if self." << r.fixedName << " != other." << r.fixedName << ':'; _out.inc(); - _out << nl << "return (-1 if self." << r->fixedName << " is None else 1)"; + _out << nl << "return (-1 if self." << r.fixedName << " is None else 1)"; _out.dec(); _out.dec(); _out << nl << "else:"; _out.inc(); - _out << nl << "if self." << r->fixedName << " < other." << r->fixedName << ':'; + _out << nl << "if self." << r.fixedName << " < other." << r.fixedName << ':'; _out.inc(); _out << nl << "return -1"; _out.dec(); - _out << nl << "elif self." << r->fixedName << " > other." << r->fixedName << ':'; + _out << nl << "elif self." << r.fixedName << " > other." << r.fixedName << ':'; _out.inc(); _out << nl << "return 1"; _out.dec(); @@ -1458,12 +1458,12 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p) _out.dec(); _out << nl << "else:"; _out.inc(); - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { // // The None value is not orderable in Python 3. // - _out << nl << "if self." << r->fixedName << " != other." << r->fixedName << ':'; + _out << nl << "if self." << r.fixedName << " != other." << r.fixedName << ':'; _out.inc(); _out << nl << "return False"; _out.dec(); @@ -1507,7 +1507,7 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p) _out.inc(); _out << nl; } - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (auto r = memberList.begin(); r != memberList.end(); ++r) { if (r != memberList.begin()) { @@ -1610,7 +1610,7 @@ Slice::Python::CodeVisitor::visitEnum(const EnumPtr& p) << enumerator->value() << ')'; } _out << nl << name << "._enumerators = { "; - for (EnumeratorList::const_iterator q = enumerators.begin(); q != enumerators.end(); ++q) + for (auto q = enumerators.begin(); q != enumerators.end(); ++q) { if (q != enumerators.begin()) { @@ -1940,11 +1940,11 @@ Slice::Python::CodeVisitor::writeConstantValue( void Slice::Python::CodeVisitor::writeConstructorParams(const MemberInfoList& members) { - for (MemberInfoList::const_iterator p = members.begin(); p != members.end(); ++p) + for (const auto& p : members) { - _out << ", " << p->fixedName << "="; + _out << ", " << p.fixedName << "="; - const DataMemberPtr member = p->dataMember; + const DataMemberPtr member = p.dataMember; if (member->defaultValueType()) { writeConstantValue(member->type(), member->defaultValueType(), member->defaultValue()); @@ -2013,12 +2013,12 @@ Slice::Python::CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, Membe DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { MemberInfo m; - m.fixedName = fixIdent((*q)->name()); + m.fixedName = fixIdent(member->name()); m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -2214,9 +2214,9 @@ Slice::Python::CodeVisitor::writeDocstring(const string& comment, const string& _out << nl << prefix << tripleQuotes; - for (vector::const_iterator q = lines.begin(); q != lines.end(); ++q) + for (const auto& line : lines) { - _out << nl << *q; + _out << nl << line; } _out << nl << tripleQuotes; @@ -2263,7 +2263,7 @@ Slice::Python::CodeVisitor::writeDocstring(const string& comment, const DataMemb for (const auto& member : members) { _out << nl << fixIdent(member->name()) << " : " << typeToDocstring(member->type(), member->optional()); - map>::iterator p = docs.find(member->name()); + auto p = docs.find(member->name()); if (p != docs.end()) { for (const auto& line : p->second) @@ -2289,9 +2289,9 @@ Slice::Python::CodeVisitor::writeDocstring(const string& comment, const Enumerat _out << nl << tripleQuotes; - for (vector::const_iterator q = lines.begin(); q != lines.end(); ++q) + for (const auto& line : lines) { - _out << nl << *q; + _out << nl << line; } if (!enumerators.empty()) @@ -2317,10 +2317,10 @@ Slice::Python::CodeVisitor::writeDocstring(const string& comment, const Enumerat for (const auto& enumerator : enumerators) { _out << nl << fixIdent(enumerator->name()) << " -- "; - map>::iterator p = docs.find(enumerator->name()); + auto p = docs.find(enumerator->name()); if (p != docs.end()) { - for (vector::const_iterator q = p->second.begin(); q != p->second.end(); ++q) + for (auto q = p->second.begin(); q != p->second.end(); ++q) { if (q != p->second.begin()) { @@ -2353,7 +2353,7 @@ Slice::Python::CodeVisitor::parseOpDocComment(const string& comment, OpDocCommen // string name; bool inParam = false, inException = false, inReturn = false; - vector::iterator i = lines.begin(); + auto i = lines.begin(); while (i != lines.end()) { string l = *i; @@ -2729,7 +2729,7 @@ Slice::Python::getImportFileName(const string& file, const UnitPtr& ut, const ve IceInternal::splitString(pkgdir, "/", names); assert(!names.empty()); pkgdir = ""; - for (vector::iterator p = names.begin(); p != names.end(); ++p) + for (auto p = names.begin(); p != names.end(); ++p) { if (p != names.begin()) { @@ -2772,15 +2772,15 @@ Slice::Python::generate(const UnitPtr& un, bool all, const vector& inclu if (!all) { vector paths = includePaths; - for (vector::iterator p = paths.begin(); p != paths.end(); ++p) + for (auto& path : paths) { - *p = fullPath(*p); + path = fullPath(path); } StringList includes = un->includeFiles(); - for (StringList::const_iterator q = includes.begin(); q != includes.end(); ++q) + for (const auto& include : includes) { - out << nl << "import " << getImportFileName(*q, un, paths); + out << nl << "import " << getImportFileName(include, un, paths); } } @@ -2823,9 +2823,9 @@ Slice::Python::fixIdent(const string& ident) vector ids = splitScopedName(ident); transform(ids.begin(), ids.end(), ids.begin(), [](const string& id) -> string { return lookupKwd(id); }); stringstream result; - for (vector::const_iterator i = ids.begin(); i != ids.end(); ++i) + for (const auto& id : ids) { - result << "::" + *i; + result << "::" + id; } return result.str(); } @@ -2911,7 +2911,7 @@ Slice::Python::MetadataVisitor::visitUnitStart(const UnitPtr& unit) { DefinitionContextPtr dc = unit->findDefinitionContext(file); MetadataList fileMetadata = dc->getMetadata(); - for (MetadataList::const_iterator r = fileMetadata.begin(); r != fileMetadata.end();) + for (auto r = fileMetadata.begin(); r != fileMetadata.end();) { MetadataPtr meta = *r++; string_view directive = meta->directive(); @@ -2943,7 +2943,7 @@ bool Slice::Python::MetadataVisitor::visitModuleStart(const ModulePtr& p) { MetadataList metadata = p->getMetadata(); - for (MetadataList::const_iterator r = metadata.begin(); r != metadata.end();) + for (auto r = metadata.begin(); r != metadata.end();) { MetadataPtr meta = *r++; string_view directive = meta->directive(); @@ -3043,7 +3043,7 @@ Slice::Python::MetadataVisitor::validateSequence(const ContainedPtr& cont, const { static const string prefix = "python:"; MetadataList newMetadata = cont->getMetadata(); - for (MetadataList::const_iterator p = newMetadata.begin(); p != newMetadata.end();) + for (auto p = newMetadata.begin(); p != newMetadata.end();) { MetadataPtr s = *p++; string_view directive = s->directive(); @@ -3110,7 +3110,7 @@ Slice::Python::MetadataVisitor::reject(const ContainedPtr& cont) { MetadataList localMetadata = cont->getMetadata(); - for (MetadataList::const_iterator p = localMetadata.begin(); p != localMetadata.end();) + for (auto p = localMetadata.begin(); p != localMetadata.end();) { MetadataPtr s = *p++; if (s->directive().find("python:") == 0) diff --git a/cpp/src/slice2rb/Ruby.cpp b/cpp/src/slice2rb/Ruby.cpp index 7b83e286839..bbee2a7a459 100644 --- a/cpp/src/slice2rb/Ruby.cpp +++ b/cpp/src/slice2rb/Ruby.cpp @@ -95,21 +95,21 @@ Slice::Ruby::compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + optarg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + optarg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -151,12 +151,12 @@ Slice::Ruby::compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // // Ignore duplicates. // - vector::iterator p = find(args.begin(), args.end(), *i); + auto p = find(args.begin(), args.end(), *i); if (p != i) { continue; diff --git a/cpp/src/slice2rb/RubyUtil.cpp b/cpp/src/slice2rb/RubyUtil.cpp index 112d932e58f..801301f5ac0 100644 --- a/cpp/src/slice2rb/RubyUtil.cpp +++ b/cpp/src/slice2rb/RubyUtil.cpp @@ -21,9 +21,9 @@ namespace { ParameterList params = p->parameters(); - for (ParameterList::const_iterator i = params.begin(); i != params.end(); ++i) + for (const auto& param : params) { - if ((*i)->name() == name) + if (param->name() == name) { return name + "_"; } @@ -293,9 +293,9 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out.inc(); bool inheritsMembers = false; - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (q->inherited) + if (allMember.inherited) { inheritsMembers = true; break; @@ -305,21 +305,21 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) if (inheritsMembers) { _out << nl << "super" << spar; - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (q->inherited) + if (allMember.inherited) { - _out << q->lowerName; + _out << allMember.lowerName; } } _out << epar; } - for (MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + for (const auto& allMember : allMembers) { - if (!q->inherited) + if (!allMember.inherited) { - _out << nl << '@' << q->fixedName << " = " << q->lowerName; + _out << nl << '@' << allMember.fixedName << " = " << allMember.lowerName; } } @@ -336,7 +336,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) DataMemberList protectedMembers; _out << sp << nl << "attr_accessor "; - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (auto q = members.begin(); q != members.end(); ++q) { if (q != members.begin()) { @@ -352,7 +352,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) if (!protectedMembers.empty()) { _out << nl << "protected "; - for (DataMemberList::iterator q = protectedMembers.begin(); q != protectedMembers.end(); ++q) + for (auto q = protectedMembers.begin(); q != protectedMembers.end(); ++q) { if (q != protectedMembers.begin()) { @@ -408,7 +408,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << nl; } { - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (auto q = members.begin(); q != members.end(); ++q) { if (q != members.begin()) { @@ -451,31 +451,31 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << nl << "module " << name << "Prx_mixin"; _out.inc(); - for (InterfaceList::iterator cli = bases.begin(); cli != bases.end(); ++cli) + for (const auto& base : bases) { - InterfaceDefPtr def = *cli; - _out << nl << "include " << getAbsolute(*cli, IdentToUpper) << "Prx_mixin"; + InterfaceDefPtr def = base; + _out << nl << "include " << getAbsolute(base, IdentToUpper) << "Prx_mixin"; } - for (OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli) + for (const auto& op : ops) { - string fixedOpName = fixIdent((*oli)->name(), IdentNormal); + string fixedOpName = fixIdent(op->name(), IdentNormal); if (fixedOpName == "checkedCast" || fixedOpName == "uncheckedCast") { fixedOpName.insert(0, "_"); } - TypePtr ret = (*oli)->returnType(); - ParameterList paramList = (*oli)->parameters(); + TypePtr ret = op->returnType(); + ParameterList paramList = op->parameters(); string inParams; - for (ParameterList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) + for (const auto& q : paramList) { - if (!(*q)->isOutParam()) + if (!q->isOutParam()) { if (!inParams.empty()) { inParams.append(", "); } - inParams.append(fixIdent((*q)->name(), IdentToLower)); + inParams.append(fixIdent(q->name(), IdentToLower)); } } @@ -484,10 +484,10 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _out << inParams << ", "; } - const string contextParamName = getEscapedParamName(*oli, "context"); + const string contextParamName = getEscapedParamName(op, "context"); _out << contextParamName << "=nil)"; _out.inc(); - _out << nl << name << "Prx_mixin::OP_" << (*oli)->name() << ".invoke(self, [" << inParams; + _out << nl << name << "Prx_mixin::OP_" << op->name() << ".invoke(self, [" << inParams; _out << "], " << contextParamName << ")"; _out.dec(); _out << nl << "end"; @@ -531,13 +531,13 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << ", ["; { int interfaceCount = 0; - for (InterfaceList::const_iterator q = bases.begin(); q != bases.end(); ++q) + for (const auto& base : bases) { if (interfaceCount > 0) { _out << ", "; } - _out << getAbsolute(*q, IdentToUpper, "T_") << "Prx"; + _out << getAbsolute(base, IdentToUpper, "T_") << "Prx"; ++interfaceCount; } } @@ -635,7 +635,7 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } _out << ", ["; ExceptionList exceptions = op->throws(); - for (ExceptionList::iterator u = exceptions.begin(); u != exceptions.end(); ++u) + for (auto u = exceptions.begin(); u != exceptions.end(); ++u) { if (u != exceptions.begin()) { @@ -697,7 +697,7 @@ Slice::Ruby::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) if (!members.empty()) { _out << sp << nl << "attr_accessor "; - for (DataMemberList::iterator dmli = members.begin(); dmli != members.end(); ++dmli) + for (auto dmli = members.begin(); dmli != members.end(); ++dmli) { if (dmli != members.begin()) { @@ -735,7 +735,7 @@ Slice::Ruby::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) // // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. // - for (DataMemberList::iterator dmli = members.begin(); dmli != members.end(); ++dmli) + for (auto dmli = members.begin(); dmli != members.end(); ++dmli) { if (dmli != members.begin()) { @@ -768,13 +768,13 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) { DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - memberList.push_back(MemberInfo()); - memberList.back().lowerName = fixIdent((*q)->name(), IdentToLower); - memberList.back().fixedName = fixIdent((*q)->name(), IdentNormal); + memberList.emplace_back(); + memberList.back().lowerName = fixIdent(member->name(), IdentToLower); + memberList.back().fixedName = fixIdent(member->name(), IdentNormal); memberList.back().inherited = false; - memberList.back().dataMember = *q; + memberList.back().dataMember = member; } } @@ -789,9 +789,9 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) writeConstructorParams(memberList); _out << ")"; _out.inc(); - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - _out << nl << '@' << r->fixedName << " = " << r->lowerName; + _out << nl << '@' << r.fixedName << " = " << r.lowerName; } _out.dec(); _out << nl << "end"; @@ -804,9 +804,9 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) _out.inc(); _out << nl << "_h = 0"; int iter = 0; - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - writeHash("@" + r->fixedName, r->dataMember->type(), iter); + writeHash("@" + r.fixedName, r.dataMember->type(), iter); } _out << nl << "_h % 0x7fffffff"; _out.dec(); @@ -820,9 +820,9 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) _out << nl << "return false if"; _out.inc(); _out << " !other.is_a? " << getAbsolute(p, IdentToUpper); - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (const auto& r : memberList) { - _out << " or" << nl << "@" << r->fixedName << " != other." << r->fixedName; + _out << " or" << nl << "@" << r.fixedName << " != other." << r.fixedName; } _out.dec(); _out << nl << "true"; @@ -846,7 +846,7 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) if (!memberList.empty()) { _out << sp << nl << "attr_accessor "; - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (auto r = memberList.begin(); r != memberList.end(); ++r) { if (r != memberList.begin()) { @@ -875,7 +875,7 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) _out.inc(); _out << nl; } - for (MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r) + for (auto r = memberList.begin(); r != memberList.end(); ++r) { if (r != memberList.begin()) { @@ -1017,7 +1017,7 @@ Slice::Ruby::CodeVisitor::visitEnum(const EnumPtr& p) // _out << sp; int i = 0; - for (EnumeratorList::const_iterator q = enumerators.begin(); q != enumerators.end(); ++q, ++i) + for (auto q = enumerators.begin(); q != enumerators.end(); ++q, ++i) { ostringstream idx; idx << i; @@ -1026,7 +1026,7 @@ Slice::Ruby::CodeVisitor::visitEnum(const EnumPtr& p) } _out << sp << nl << "@@_enumerators = {"; - for (EnumeratorList::const_iterator q = enumerators.begin(); q != enumerators.end(); ++q) + for (auto q = enumerators.begin(); q != enumerators.end(); ++q) { if (q != enumerators.begin()) { @@ -1261,7 +1261,7 @@ Slice::Ruby::CodeVisitor::writeConstantValue( void Slice::Ruby::CodeVisitor::writeConstructorParams(const MemberInfoList& members) { - for (MemberInfoList::const_iterator p = members.begin(); p != members.end(); ++p) + for (auto p = members.begin(); p != members.end(); ++p) { if (p != members.begin()) { @@ -1296,13 +1296,13 @@ Slice::Ruby::CodeVisitor::collectClassMembers(const ClassDefPtr& p, MemberInfoLi DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { MemberInfo m; - m.lowerName = fixIdent((*q)->name(), IdentToLower); - m.fixedName = fixIdent((*q)->name(), IdentNormal); + m.lowerName = fixIdent(member->name(), IdentToLower); + m.fixedName = fixIdent(member->name(), IdentNormal); m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -1318,13 +1318,13 @@ Slice::Ruby::CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, MemberI DataMemberList members = p->dataMembers(); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { MemberInfo m; - m.lowerName = fixIdent((*q)->name(), IdentToLower); - m.fixedName = fixIdent((*q)->name(), IdentNormal); + m.lowerName = fixIdent(member->name(), IdentToLower); + m.fixedName = fixIdent(member->name(), IdentNormal); m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -1341,9 +1341,9 @@ Slice::Ruby::generate(const UnitPtr& un, bool all, const vector& include if (!all) { vector paths = includePaths; - for (vector::iterator p = paths.begin(); p != paths.end(); ++p) + for (auto& path : paths) { - *p = fullPath(*p); + path = fullPath(path); } for (string file : un->includeFiles()) diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp index a76fb685b49..9d9e8b93979 100644 --- a/cpp/src/slice2swift/Gen.cpp +++ b/cpp/src/slice2swift/Gen.cpp @@ -145,9 +145,9 @@ Gen::ImportVisitor::visitClassDefStart(const ClassDefPtr& p) // Add imports required for data members // const DataMemberList allDataMembers = p->allDataMembers(); - for (DataMemberList::const_iterator i = allDataMembers.begin(); i != allDataMembers.end(); ++i) + for (const auto& allDataMember : allDataMembers) { - addImport((*i)->type(), p); + addImport(allDataMember->type(), p); } return false; @@ -160,27 +160,27 @@ Gen::ImportVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // Add imports required for base interfaces // InterfaceList bases = p->bases(); - for (InterfaceList::const_iterator i = bases.begin(); i != bases.end(); ++i) + for (const auto& base : bases) { - addImport(dynamic_pointer_cast(*i), p); + addImport(dynamic_pointer_cast(base), p); } // // Add imports required for operation parameters and return type // const OperationList operationList = p->allOperations(); - for (OperationList::const_iterator i = operationList.begin(); i != operationList.end(); ++i) + for (const auto& i : operationList) { - const TypePtr ret = (*i)->returnType(); + const TypePtr ret = i->returnType(); if (ret && ret->definitionContext()) { addImport(ret, p); } - const ParameterList paramList = (*i)->parameters(); - for (ParameterList::const_iterator j = paramList.begin(); j != paramList.end(); ++j) + const ParameterList paramList = i->parameters(); + for (const auto& j : paramList) { - addImport((*j)->type(), p); + addImport(j->type(), p); } } @@ -194,9 +194,9 @@ Gen::ImportVisitor::visitStructStart(const StructPtr& p) // Add imports required for data members // const DataMemberList dataMembers = p->dataMembers(); - for (DataMemberList::const_iterator i = dataMembers.begin(); i != dataMembers.end(); ++i) + for (const auto& dataMember : dataMembers) { - addImport((*i)->type(), p); + addImport(dataMember->type(), p); } return true; @@ -218,9 +218,9 @@ Gen::ImportVisitor::visitExceptionStart(const ExceptionPtr& p) // Add imports required for data members // const DataMemberList allDataMembers = p->allDataMembers(); - for (DataMemberList::const_iterator i = allDataMembers.begin(); i != allDataMembers.end(); ++i) + for (const auto& allDataMember : allDataMembers) { - addImport((*i)->type(), p); + addImport(allDataMember->type(), p); } return true; } @@ -247,9 +247,9 @@ Gen::ImportVisitor::visitDictionary(const DictionaryPtr& dict) void Gen::ImportVisitor::writeImports() { - for (vector::const_iterator i = _imports.begin(); i != _imports.end(); ++i) + for (const auto& import : _imports) { - out << nl << "import " << *i; + out << nl << "import " << import; } } @@ -306,7 +306,7 @@ Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) ostringstream ids; ids << "["; - for (StringList::const_iterator r = allIds.begin(); r != allIds.end(); ++r) + for (auto r = allIds.begin(); r != allIds.end(); ++r) { if (r != allIds.begin()) { @@ -343,7 +343,7 @@ Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) ostringstream factory; factory << prefix; vector parts = splitScopedName(p->scoped()); - for (vector::const_iterator it = parts.begin(); it != parts.end();) + for (auto it = parts.begin(); it != parts.end();) { factory << (*it); if (++it != parts.end()) @@ -415,18 +415,16 @@ Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) out << sb; out << nl << "ostr.startSlice(typeId: " << fixIdent(name) << ".ice_staticId(), compactId: -1, last: " << (!base ? "true" : "false") << ")"; - for (DataMemberList::const_iterator i = members.begin(); i != members.end(); ++i) + for (const auto& member : members) { - DataMemberPtr member = *i; if (!member->optional()) { writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), true); } } - for (DataMemberList::const_iterator i = optionalMembers.begin(); i != optionalMembers.end(); ++i) + for (const auto& member : optionalMembers) { - DataMemberPtr member = *i; writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), true, member->tag()); } out << nl << "ostr.endSlice()"; @@ -441,18 +439,16 @@ Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) << ") throws"; out << sb; out << nl << "_ = try istr.startSlice()"; - for (DataMemberList::const_iterator i = members.begin(); i != members.end(); ++i) + for (const auto& member : members) { - DataMemberPtr member = *i; if (!member->optional()) { writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), false); } } - for (DataMemberList::const_iterator i = optionalMembers.begin(); i != optionalMembers.end(); ++i) + for (const auto& member : optionalMembers) { - DataMemberPtr member = *i; writeMarshalUnmarshalCode(out, member->type(), p, "self." + fixIdent(member->name()), false, member->tag()); } @@ -1031,7 +1027,7 @@ Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } else { - for (InterfaceList::const_iterator i = bases.begin(); i != bases.end();) + for (auto i = bases.begin(); i != bases.end();) { out << " " << getRelativeTypeString(*i, swiftModule) << "Prx"; if (++i != bases.end()) @@ -1238,7 +1234,7 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p) ostringstream factory; factory << prefix; vector parts = splitScopedName(p->scoped()); - for (vector::const_iterator it = parts.begin(); it != parts.end();) + for (auto it = parts.begin(); it != parts.end();) { factory << (*it); if (++it != parts.end()) @@ -1387,10 +1383,10 @@ Gen::ObjectVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) back_inserter(allOpNames), [](const ContainedPtr& it) { return it->name(); }); - allOpNames.push_back("ice_id"); - allOpNames.push_back("ice_ids"); - allOpNames.push_back("ice_isA"); - allOpNames.push_back("ice_ping"); + allOpNames.emplace_back("ice_id"); + allOpNames.emplace_back("ice_ids"); + allOpNames.emplace_back("ice_isA"); + allOpNames.emplace_back("ice_ping"); out << sp; out << nl; @@ -1430,9 +1426,9 @@ Gen::ObjectVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // InterfaceList bases = p->bases(); StringList baseNames; - for (InterfaceList::const_iterator i = bases.begin(); i != bases.end(); ++i) + for (const auto& base : bases) { - baseNames.push_back(fixIdent(getRelativeTypeString(*i, swiftModule))); + baseNames.push_back(fixIdent(getRelativeTypeString(base, swiftModule))); } // Check for 'swift:inherits' metadata. @@ -1452,7 +1448,7 @@ Gen::ObjectVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) out << ":"; } - for (StringList::const_iterator i = baseNames.begin(); i != baseNames.end();) + for (auto i = baseNames.begin(); i != baseNames.end();) { out << " " << (*i); if (++i != baseNames.end()) @@ -1484,10 +1480,10 @@ Gen::ObjectVisitor::visitOperation(const OperationPtr& op) writeOpDocSummary(out, op, true); out << nl << "func " << opName; out << spar; - for (ParamInfoList::const_iterator q = allInParams.begin(); q != allInParams.end(); ++q) + for (const auto& allInParam : allInParams) { ostringstream s; - s << q->name << ": " << q->typeStr; + s << allInParam.name << ": " << allInParam.typeStr; out << s.str(); } out << ("current: " + getUnqualified("Ice.Current", swiftModule)); diff --git a/cpp/src/slice2swift/Main.cpp b/cpp/src/slice2swift/Main.cpp index e446b2058fc..f7431c75e00 100644 --- a/cpp/src/slice2swift/Main.cpp +++ b/cpp/src/slice2swift/Main.cpp @@ -101,21 +101,21 @@ compile(const vector& argv) vector cppArgs; vector optargs = opts.argVec("D"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-D" + *i); + cppArgs.push_back("-D" + optarg); } optargs = opts.argVec("U"); - for (vector::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for (const auto& optarg : optargs) { - cppArgs.push_back("-U" + *i); + cppArgs.push_back("-U" + optarg); } vector includePaths = opts.argVec("I"); - for (vector::const_iterator i = includePaths.begin(); i != includePaths.end(); ++i) + for (const auto& includePath : includePaths) { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); + cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(includePath)); } bool preprocess = opts.isSet("E"); @@ -166,7 +166,7 @@ compile(const vector& argv) os << "\n" << endl; } - for (vector::const_iterator i = args.begin(); i != args.end(); ++i) + for (auto i = args.begin(); i != args.end(); ++i) { // // Ignore duplicates. diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index 588a35e588c..51231820ce7 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -292,7 +292,7 @@ SwiftGenerator::writeDocSentence(IceInternal::Output& out, const StringList& lin // // Write the first sentence. // - for (StringList::const_iterator i = lines.begin(); i != lines.end(); ++i) + for (auto i = lines.begin(); i != lines.end(); ++i) { const string ws = " \t"; @@ -939,16 +939,14 @@ SwiftGenerator::writeMemberwiseInitializer( out << sp; out << nl; out << "public init" << spar; - for (DataMemberList::const_iterator i = allMembers.begin(); i != allMembers.end(); ++i) + for (const auto& m : allMembers) { - DataMemberPtr m = *i; out << (fixIdent(m->name()) + ": " + typeToString(m->type(), p, m->optional())); } out << epar; out << sb; - for (DataMemberList::const_iterator i = members.begin(); i != members.end(); ++i) + for (const auto& m : members) { - DataMemberPtr m = *i; out << nl << "self." << fixIdent(m->name()) << " = " << fixIdent(m->name()); } @@ -956,9 +954,9 @@ SwiftGenerator::writeMemberwiseInitializer( { out << nl << "super.init"; out << spar; - for (DataMemberList::const_iterator i = baseMembers.begin(); i != baseMembers.end(); ++i) + for (const auto& baseMember : baseMembers) { - const string name = fixIdent((*i)->name()); + const string name = fixIdent(baseMember->name()); out << (name + ": " + name); } out << epar; @@ -977,9 +975,8 @@ SwiftGenerator::writeMembers( string swiftModule = getSwiftModule(getTopLevelModule(p)); bool protocol = (typeCtx & TypeContextProtocol) != 0; string access = protocol ? "" : "public "; - for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - DataMemberPtr member = *q; TypePtr type = member->type(); const string defaultValue = member->defaultValue(); @@ -1288,7 +1285,7 @@ SwiftGenerator::MetadataVisitor::visitModuleStart(const ModulePtr& p) string swiftModule = getSwiftModule(p, swiftPrefix); const string filename = p->definitionContext()->filename(); - ModuleMap::const_iterator current = _modules.find(filename); + auto current = _modules.find(filename); if (current == _modules.end()) { @@ -1302,7 +1299,7 @@ SwiftGenerator::MetadataVisitor::visitModuleStart(const ModulePtr& p) unit->error(p->file(), p->line(), os.str()); } - ModulePrefix::iterator prefixes = _prefixes.find(swiftModule); + auto prefixes = _prefixes.find(swiftModule); if (prefixes == _prefixes.end()) { ModuleMap mappings; @@ -1340,9 +1337,9 @@ string SwiftGenerator::paramLabel(const string& param, const ParameterList& params) { string s = param; - for (ParameterList::const_iterator q = params.begin(); q != params.end(); ++q) + for (const auto& q : params) { - if ((*q)->name() == param) + if (q->name() == param) { s = "_" + s; break; @@ -1379,7 +1376,7 @@ SwiftGenerator::operationReturnType(const OperationPtr& op) os << typeToString(returnType, op, op->returnIsOptional()); } - for (ParameterList::const_iterator q = outParams.begin(); q != outParams.end(); ++q) + for (auto q = outParams.begin(); q != outParams.end(); ++q) { if (returnType || q != outParams.begin()) { @@ -1420,7 +1417,7 @@ SwiftGenerator::operationReturnDeclaration(const OperationPtr& op) os << ("iceP_" + paramLabel("returnValue", outParams)); } - for (ParameterList::const_iterator q = outParams.begin(); q != outParams.end(); ++q) + for (auto q = outParams.begin(); q != outParams.end(); ++q) { if (returnType || q != outParams.begin()) { @@ -1452,7 +1449,7 @@ SwiftGenerator::operationInParamsDeclaration(const OperationPtr& op) { os << "("; } - for (ParameterList::const_iterator q = inParams.begin(); q != inParams.end(); ++q) + for (auto q = inParams.begin(); q != inParams.end(); ++q) { if (q != inParams.begin()) { @@ -1472,7 +1469,7 @@ SwiftGenerator::operationInParamsDeclaration(const OperationPtr& op) { os << "("; } - for (ParameterList::const_iterator q = inParams.begin(); q != inParams.end(); ++q) + for (auto q = inParams.begin(); q != inParams.end(); ++q) { if (q != inParams.begin()) { @@ -1495,15 +1492,15 @@ SwiftGenerator::getAllInParams(const OperationPtr& op) { const ParameterList l = op->inParameters(); ParamInfoList r; - for (ParameterList::const_iterator p = l.begin(); p != l.end(); ++p) + for (const auto& p : l) { ParamInfo info; - info.name = (*p)->name(); - info.type = (*p)->type(); - info.typeStr = typeToString(info.type, op, (*p)->optional()); - info.optional = (*p)->optional(); - info.tag = (*p)->tag(); - info.param = *p; + info.name = p->name(); + info.type = p->type(); + info.typeStr = typeToString(info.type, op, p->optional()); + info.optional = p->optional(); + info.tag = p->tag(); + info.param = p; r.push_back(info); } return r; @@ -1513,15 +1510,15 @@ void SwiftGenerator::getInParams(const OperationPtr& op, ParamInfoList& required, ParamInfoList& optional) { const ParamInfoList params = getAllInParams(op); - for (ParamInfoList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { - if (p->optional) + if (param.optional) { - optional.push_back(*p); + optional.push_back(param); } else { - required.push_back(*p); + required.push_back(param); } } @@ -1542,15 +1539,15 @@ SwiftGenerator::getAllOutParams(const OperationPtr& op) ParameterList params = op->outParameters(); ParamInfoList l; - for (ParameterList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { ParamInfo info; - info.name = (*p)->name(); - info.type = (*p)->type(); - info.typeStr = typeToString(info.type, op, (*p)->optional()); - info.optional = (*p)->optional(); - info.tag = (*p)->tag(); - info.param = *p; + info.name = param->name(); + info.type = param->type(); + info.typeStr = typeToString(info.type, op, param->optional()); + info.optional = param->optional(); + info.tag = param->tag(); + info.param = param; l.push_back(info); } @@ -1572,15 +1569,15 @@ void SwiftGenerator::getOutParams(const OperationPtr& op, ParamInfoList& required, ParamInfoList& optional) { const ParamInfoList params = getAllOutParams(op); - for (ParamInfoList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { - if (p->optional) + if (param.optional) { - optional.push_back(*p); + optional.push_back(param); } else { - required.push_back(*p); + required.push_back(param); } } @@ -1609,14 +1606,20 @@ SwiftGenerator::writeMarshalInParams(::IceInternal::Output& out, const Operation // 2. optional // - for (ParamInfoList::const_iterator q = requiredInParams.begin(); q != requiredInParams.end(); ++q) + for (const auto& requiredInParam : requiredInParams) { - writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true); + writeMarshalUnmarshalCode(out, requiredInParam.type, op, "iceP_" + requiredInParam.name, true); } - for (ParamInfoList::const_iterator q = optionalInParams.begin(); q != optionalInParams.end(); ++q) + for (const auto& optionalInParam : optionalInParams) { - writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true, q->tag); + writeMarshalUnmarshalCode( + out, + optionalInParam.type, + op, + "iceP_" + optionalInParam.name, + true, + optionalInParam.tag); } if (op->sendsClasses()) @@ -1639,14 +1642,20 @@ SwiftGenerator::writeMarshalOutParams(::IceInternal::Output& out, const Operatio // 2. optional (including optional return) // - for (ParamInfoList::const_iterator q = requiredOutParams.begin(); q != requiredOutParams.end(); ++q) + for (const auto& requiredOutParam : requiredOutParams) { - writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true); + writeMarshalUnmarshalCode(out, requiredOutParam.type, op, "iceP_" + requiredOutParam.name, true); } - for (ParamInfoList::const_iterator q = optionalOutParams.begin(); q != optionalOutParams.end(); ++q) + for (const auto& optionalOutParam : optionalOutParams) { - writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true, q->tag); + writeMarshalUnmarshalCode( + out, + optionalOutParam.type, + op, + "iceP_" + optionalOutParam.name, + true, + optionalOutParam.tag); } if (op->returnsClasses()) @@ -1668,14 +1677,20 @@ SwiftGenerator::writeMarshalAsyncOutParams(::IceInternal::Output& out, const Ope // 2. optional (including optional return) // - for (ParamInfoList::const_iterator q = requiredOutParams.begin(); q != requiredOutParams.end(); ++q) + for (const auto& requiredOutParam : requiredOutParams) { - writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true); + writeMarshalUnmarshalCode(out, requiredOutParam.type, op, "iceP_" + requiredOutParam.name, true); } - for (ParamInfoList::const_iterator q = optionalOutParams.begin(); q != optionalOutParams.end(); ++q) + for (const auto& optionalOutParam : optionalOutParams) { - writeMarshalUnmarshalCode(out, q->type, op, "iceP_" + q->name, true, q->tag); + writeMarshalUnmarshalCode( + out, + optionalOutParam.type, + op, + "iceP_" + optionalOutParam.name, + true, + optionalOutParam.tag); } if (op->returnsClasses()) @@ -1700,34 +1715,34 @@ SwiftGenerator::writeUnmarshalOutParams(::IceInternal::Output& out, const Operat // out << "{ istr in"; out.inc(); - for (ParamInfoList::const_iterator q = requiredOutParams.begin(); q != requiredOutParams.end(); ++q) + for (const auto& requiredOutParam : requiredOutParams) { string param; - if (q->type->isClassType()) + if (requiredOutParam.type->isClassType()) { - out << nl << "var iceP_" << q->name << ": " << q->typeStr; - param = "iceP_" + q->name; + out << nl << "var iceP_" << requiredOutParam.name << ": " << requiredOutParam.typeStr; + param = "iceP_" + requiredOutParam.name; } else { - param = "let iceP_" + q->name + ": " + q->typeStr; + param = "let iceP_" + requiredOutParam.name + ": " + requiredOutParam.typeStr; } - writeMarshalUnmarshalCode(out, q->type, op, param, false); + writeMarshalUnmarshalCode(out, requiredOutParam.type, op, param, false); } - for (ParamInfoList::const_iterator q = optionalOutParams.begin(); q != optionalOutParams.end(); ++q) + for (const auto& optionalOutParam : optionalOutParams) { string param; - if (q->type->isClassType()) + if (optionalOutParam.type->isClassType()) { - out << nl << "var iceP_" << q->name << ": " << q->typeStr; - param = "iceP_" + q->name; + out << nl << "var iceP_" << optionalOutParam.name << ": " << optionalOutParam.typeStr; + param = "iceP_" + optionalOutParam.name; } else { - param = "let iceP_" + q->name + ": " + q->typeStr; + param = "let iceP_" + optionalOutParam.name + ": " + optionalOutParam.typeStr; } - writeMarshalUnmarshalCode(out, q->type, op, param, false, q->tag); + writeMarshalUnmarshalCode(out, optionalOutParam.type, op, param, false, optionalOutParam.tag); } if (op->returnsClasses()) @@ -1746,11 +1761,11 @@ SwiftGenerator::writeUnmarshalOutParams(::IceInternal::Output& out, const Operat out << ("iceP_" + paramLabel("returnValue", op->outParameters())); } - for (ParamInfoList::const_iterator q = allOutParams.begin(); q != allOutParams.end(); ++q) + for (const auto& allOutParam : allOutParams) { - if (q->param) + if (allOutParam.param) { - out << ("iceP_" + q->name); + out << ("iceP_" + allOutParam.name); } } @@ -1774,37 +1789,37 @@ SwiftGenerator::writeUnmarshalInParams(::IceInternal::Output& out, const Operati // 1. required // 3. optional // - for (ParamInfoList::const_iterator q = requiredInParams.begin(); q != requiredInParams.end(); ++q) + for (const auto& requiredInParam : requiredInParams) { - if (q->param) + if (requiredInParam.param) { string param; - if (q->type->isClassType()) + if (requiredInParam.type->isClassType()) { - out << nl << "var iceP_" << q->name << ": " << q->typeStr; - param = "iceP_" + q->name; + out << nl << "var iceP_" << requiredInParam.name << ": " << requiredInParam.typeStr; + param = "iceP_" + requiredInParam.name; } else { - param = "let iceP_" + q->name + ": " + q->typeStr; + param = "let iceP_" + requiredInParam.name + ": " + requiredInParam.typeStr; } - writeMarshalUnmarshalCode(out, q->type, op, param, false); + writeMarshalUnmarshalCode(out, requiredInParam.type, op, param, false); } } - for (ParamInfoList::const_iterator q = optionalInParams.begin(); q != optionalInParams.end(); ++q) + for (const auto& optionalInParam : optionalInParams) { string param; - if (q->type->isClassType()) + if (optionalInParam.type->isClassType()) { - out << nl << "var iceP_" << q->name << ": " << q->typeStr; - param = "iceP_" + q->name; + out << nl << "var iceP_" << optionalInParam.name << ": " << optionalInParam.typeStr; + param = "iceP_" + optionalInParam.name; } else { - param = "let iceP_" + q->name + ": " + q->typeStr; + param = "let iceP_" + optionalInParam.name + ": " + optionalInParam.typeStr; } - writeMarshalUnmarshalCode(out, q->type, op, param, false, q->tag); + writeMarshalUnmarshalCode(out, optionalInParam.type, op, param, false, optionalInParam.tag); } if (op->sendsClasses()) @@ -1870,7 +1885,7 @@ SwiftGenerator::writeProxyOperation(::IceInternal::Output& out, const OperationP writeOpDocSummary(out, op, false); out << nl << "func " << opName; out << spar; - for (ParamInfoList::const_iterator q = allInParams.begin(); q != allInParams.end(); ++q) + for (auto q = allInParams.begin(); q != allInParams.end(); ++q) { if (allInParams.size() == 1) { @@ -2103,7 +2118,7 @@ SwiftGenerator::MetadataVisitor::validate(const SyntaxTreeBasePtr& p, const Cont { MetadataList newMetadata = cont->getMetadata(); - for (MetadataList::const_iterator m = newMetadata.begin(); m != newMetadata.end();) + for (auto m = newMetadata.begin(); m != newMetadata.end();) { MetadataPtr meta = *m++; string_view directive = meta->directive(); diff --git a/cpp/test/DataStorm/types/Reader.cpp b/cpp/test/DataStorm/types/Reader.cpp index db4d1ead24b..a8017fd6057 100644 --- a/cpp/test/DataStorm/types/Reader.cpp +++ b/cpp/test/DataStorm/types/Reader.cpp @@ -42,18 +42,18 @@ namespace { topic.setReaderDefaultConfig(ReaderConfig(-1, std::nullopt, ClearHistoryPolicy::Never)); map readers; - for (auto p : add) + for (const auto& p : add) { readers.emplace(p.first, makeSingleKeyReader(topic, p.first)); auto s = readers.at(p.first).getNextUnread(); test(s.getEvent() == SampleEvent::Add && compare(s.getValue(), p.second)); } - for (auto p : update) + for (const auto& p : update) { auto s = readers.at(p.first).getNextUnread(); test(s.getEvent() == SampleEvent::Update && compare(s.getValue(), p.second)); } - for (auto p : add) + for (const auto& p : add) { auto s = readers.at(p.first).getNextUnread(); test(s.getEvent() == SampleEvent::Remove); diff --git a/cpp/test/DataStorm/types/Writer.cpp b/cpp/test/DataStorm/types/Writer.cpp index ae17ffa23ab..9a3eff58185 100644 --- a/cpp/test/DataStorm/types/Writer.cpp +++ b/cpp/test/DataStorm/types/Writer.cpp @@ -24,21 +24,21 @@ namespace topic.setWriterDefaultConfig(WriterConfig(-1, std::nullopt, ClearHistoryPolicy::Never)); using WriterType = decltype(makeSingleKeyWriter(topic, typename decltype(add)::key_type())); map writers; - for (auto p : add) + for (const auto& p : add) { writers.emplace(p.first, makeSingleKeyWriter(topic, p.first)); writers.at(p.first).waitForReaders(); writers.at(p.first).add(p.second); } - for (auto p : update) + for (const auto& p : update) { writers.at(p.first).update(p.second); } - for (auto p : add) + for (const auto& p : add) { writers.at(p.first).remove(); } - for (auto p : add) + for (const auto& p : add) { writers.at(p.first).waitForNoReaders(); } diff --git a/cpp/test/Glacier2/dynamicFiltering/TestControllerI.cpp b/cpp/test/Glacier2/dynamicFiltering/TestControllerI.cpp index bd8d52d39fd..12484ea36fc 100644 --- a/cpp/test/Glacier2/dynamicFiltering/TestControllerI.cpp +++ b/cpp/test/Glacier2/dynamicFiltering/TestControllerI.cpp @@ -20,30 +20,30 @@ TestControllerI::TestControllerI(const string& endpoint) { TestConfiguration current; current.description = "No filters at all"; - current.cases.push_back(TestCase("foo/bar:" + endpoint, true)); + current.cases.emplace_back("foo/bar:" + endpoint, true); _configurations.push_back(current); current = TestConfiguration(); current.description = "Category filter"; - current.cases.push_back(TestCase("foo/barA:" + endpoint, true)); - current.cases.push_back(TestCase("bar/fooA:" + endpoint, false)); - current.cases.push_back(TestCase("\"a cat with spaces/fooX\":" + endpoint, true)); - current.categoryFiltersAccept.push_back("foo"); - current.categoryFiltersAccept.push_back("a cat with spaces"); + current.cases.emplace_back("foo/barA:" + endpoint, true); + current.cases.emplace_back("bar/fooA:" + endpoint, false); + current.cases.emplace_back("\"a cat with spaces/fooX\":" + endpoint, true); + current.categoryFiltersAccept.emplace_back("foo"); + current.categoryFiltersAccept.emplace_back("a cat with spaces"); _configurations.push_back(current); current = TestConfiguration(); current.description = "Adapter id filter"; - current.cases.push_back(TestCase("fooB @ bar", true)); - current.cases.push_back(TestCase("bazB @ baz", false)); - current.adapterIdFiltersAccept.push_back("bar"); + current.cases.emplace_back("fooB @ bar", true); + current.cases.emplace_back("bazB @ baz", false); + current.adapterIdFiltersAccept.emplace_back("bar"); _configurations.push_back(current); current = TestConfiguration(); current.description = "Object id filter"; - current.cases.push_back(TestCase("foo/barC:" + endpoint, true)); - current.cases.push_back(TestCase("bar/fooC:" + endpoint, false)); + current.cases.emplace_back("foo/barC:" + endpoint, true); + current.cases.emplace_back("bar/fooC:" + endpoint, false); Identity id; id.category = "foo"; id.name = "barC"; diff --git a/cpp/test/Ice/admin/AllTests.cpp b/cpp/test/Ice/admin/AllTests.cpp index e3e5ccb3206..f88c947c3a5 100644 --- a/cpp/test/Ice/admin/AllTests.cpp +++ b/cpp/test/Ice/admin/AllTests.cpp @@ -397,7 +397,7 @@ allTests(Test::TestHelper* helper) test(logMessages.size() == 4); test(prefix == "NullLogger"); - LogMessageSeq::const_iterator p = logMessages.begin(); + auto p = logMessages.begin(); test(p->traceCategory == "testCat" && p++->message == "trace"); test(p++->message == "warning"); test(p++->message == "error"); @@ -438,7 +438,7 @@ allTests(Test::TestHelper* helper) messageTypes.push_back(LogMessageType::TraceMessage); StringSeq categories; - categories.push_back("testCat"); + categories.emplace_back("testCat"); logMessages = logger->getLog(messageTypes, categories, -1, prefix); test(logMessages.size() == 5); @@ -486,9 +486,9 @@ allTests(Test::TestHelper* helper) logger->attachRemoteLogger(myProxy, LogMessageTypeSeq(), StringSeq(), -1); test(remoteLogger->wait(1)); - for (LogMessageSeq::const_iterator i = logMessages.begin(); i != logMessages.end(); ++i) + for (const auto& logMessage : logMessages) { - remoteLogger->checkNextInit(prefix, i->type, i->message, i->traceCategory); + remoteLogger->checkNextInit(prefix, logMessage.type, logMessage.message, logMessage.traceCategory); } com->trace("testCat", "rtrace"); @@ -513,9 +513,9 @@ allTests(Test::TestHelper* helper) logger->attachRemoteLogger(myProxy, messageTypes, categories, 4); test(remoteLogger->wait(1)); - for (LogMessageSeq::const_iterator i = logMessages.begin(); i != logMessages.end(); ++i) + for (const auto& logMessage : logMessages) { - remoteLogger->checkNextInit(prefix, i->type, i->message, i->traceCategory); + remoteLogger->checkNextInit(prefix, logMessage.type, logMessage.message, logMessage.traceCategory); } com->warning("rwarning2"); diff --git a/cpp/test/Ice/admin/TestI.cpp b/cpp/test/Ice/admin/TestI.cpp index b03135d74be..f51a4a9a5ed 100644 --- a/cpp/test/Ice/admin/TestI.cpp +++ b/cpp/test/Ice/admin/TestI.cpp @@ -149,9 +149,9 @@ RemoteCommunicatorFactoryI::createCommunicator(PropertyDict props, const Current // InitializationData init; init.properties = createProperties(); - for (PropertyDict::const_iterator p = props.begin(); p != props.end(); ++p) + for (const auto& prop : props) { - init.properties->setProperty(p->first, p->second); + init.properties->setProperty(prop.first, prop.second); } if (init.properties->getPropertyAsInt("NullLogger") > 0) diff --git a/cpp/test/Ice/ami/AllTests.cpp b/cpp/test/Ice/ami/AllTests.cpp index 37783ea6a41..a0d97a10695 100644 --- a/cpp/test/Ice/ami/AllTests.cpp +++ b/cpp/test/Ice/ami/AllTests.cpp @@ -743,7 +743,7 @@ allTests(TestHelper* helper, bool collocated) { TestIntfPrx q = p->ice_adapterId("dummy"); - for (int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) // NOLINT(modernize-loop-convert): clang-tidy confusion { { promise promise; @@ -1116,13 +1116,13 @@ allTests(TestHelper* helper, bool collocated) // ByteSeq seq; seq.resize(1024 * 10); - for (ByteSeq::iterator q = seq.begin(); q != seq.end(); ++q) + for (auto& q : seq) { - *q = static_cast(IceInternal::random(255)); + q = static_cast(IceInternal::random(255)); } // - // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod. + // Send multiple opWithPayload, followed by a close and followed by multiple opWithPayload. // The goal is to make sure that none of the opWithPayload fail even if the server closes // the connection gracefully in between. // diff --git a/cpp/test/Ice/background/AllTests.cpp b/cpp/test/Ice/background/AllTests.cpp index 0db294465d7..3ed2bf255db 100644 --- a/cpp/test/Ice/background/AllTests.cpp +++ b/cpp/test/Ice/background/AllTests.cpp @@ -1114,9 +1114,9 @@ readWriteTests( Ice::ByteSeq seq; seq.resize(10024); // Make sure the request doesn't compress too well. - for (Ice::ByteSeq::iterator p = seq.begin(); p != seq.end(); ++p) + for (auto& p : seq) { - *p = static_cast(IceInternal::random(255)); + p = static_cast(IceInternal::random(255)); } // Fill up the receive and send buffers diff --git a/cpp/test/Ice/background/Connector.cpp b/cpp/test/Ice/background/Connector.cpp index 1a9c177c142..c7a4b461d84 100644 --- a/cpp/test/Ice/background/Connector.cpp +++ b/cpp/test/Ice/background/Connector.cpp @@ -34,7 +34,7 @@ Connector::toString() const bool Connector::operator==(const IceInternal::Connector& r) const { - const Connector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -46,7 +46,7 @@ Connector::operator==(const IceInternal::Connector& r) const bool Connector::operator<(const IceInternal::Connector& r) const { - const Connector* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return type() < r.type(); diff --git a/cpp/test/Ice/background/EndpointI.cpp b/cpp/test/Ice/background/EndpointI.cpp index 3d39b34d7b8..c6b638d0169 100644 --- a/cpp/test/Ice/background/EndpointI.cpp +++ b/cpp/test/Ice/background/EndpointI.cpp @@ -148,9 +148,9 @@ EndpointI::connectorsAsync( selType, [response](vector connectors) { - for (vector::iterator it = connectors.begin(); it != connectors.end(); ++it) + for (auto& connector : connectors) { - *it = make_shared(*it); + connector = make_shared(connector); } response(std::move(connectors)); }, @@ -237,7 +237,7 @@ EndpointI::getInfo() const noexcept bool EndpointI::operator==(const Ice::Endpoint& r) const { - const EndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { return false; @@ -254,10 +254,10 @@ EndpointI::operator==(const Ice::Endpoint& r) const bool EndpointI::operator<(const Ice::Endpoint& r) const { - const EndpointI* p = dynamic_cast(&r); + const auto* p = dynamic_cast(&r); if (!p) { - const IceInternal::EndpointI* e = dynamic_cast(&r); + const auto* e = dynamic_cast(&r); if (!e) { return false; diff --git a/cpp/test/Ice/background/Transceiver.cpp b/cpp/test/Ice/background/Transceiver.cpp index 59cdafc0f42..cf68e498530 100644 --- a/cpp/test/Ice/background/Transceiver.cpp +++ b/cpp/test/Ice/background/Transceiver.cpp @@ -103,8 +103,8 @@ Transceiver::read(IceInternal::Buffer& buf) } } assert(_readBuffer.i > _readBufferPos); - size_t requested = static_cast(buf.b.end() - buf.i); - size_t available = static_cast(_readBuffer.i - _readBufferPos); + auto requested = static_cast(buf.b.end() - buf.i); + auto available = static_cast(_readBuffer.i - _readBufferPos); assert(available > 0); if (available >= requested) { diff --git a/cpp/test/Ice/binding/AllTests.cpp b/cpp/test/Ice/binding/AllTests.cpp index 166859551b3..77e278e8262 100644 --- a/cpp/test/Ice/binding/AllTests.cpp +++ b/cpp/test/Ice/binding/AllTests.cpp @@ -208,9 +208,9 @@ allTests(Test::TestHelper* helper) { adpts.resize(1); } - for (vector>::iterator p = adpts.begin(); p != adpts.end(); ++p) + for (auto& adpt : adpts) { - *p = adapters[IceInternal::random(static_cast(adapters.size()))]; + adpt = adapters[IceInternal::random(static_cast(adapters.size()))]; } proxies[i] = createTestIntfPrx(adpts); } @@ -291,10 +291,9 @@ allTests(Test::TestHelper* helper) // always send the request over the same connection.) // { - for (vector>::const_iterator p = adapters.begin(); p != adapters.end(); - ++p) + for (const auto& adapter : adapters) { - (*p)->getTestIntf()->ice_ping(); + adapter->getTestIntf()->ice_ping(); } TestIntfPrx test = createTestIntfPrx(adapters); @@ -920,10 +919,10 @@ allTests(Test::TestHelper* helper) serverProps.push_back(localipv6); bool ipv6NotSupported = false; - for (vector::const_iterator p = serverProps.begin(); p != serverProps.end(); ++p) + for (const auto& serverProp : serverProps) { Ice::InitializationData serverInitData; - serverInitData.properties = *p; + serverInitData.properties = serverProp; Ice::CommunicatorPtr serverCommunicator = Ice::initialize(serverInitData); Ice::ObjectAdapterPtr oa; try @@ -938,7 +937,7 @@ allTests(Test::TestHelper* helper) } catch (const Ice::SocketException&) { - if (*p == ipv6) + if (serverProp == ipv6) { ipv6NotSupported = true; } @@ -961,10 +960,10 @@ allTests(Test::TestHelper* helper) } string strPrx = prx->ice_toString(); - for (vector::const_iterator q = clientProps.begin(); q != clientProps.end(); ++q) + for (const auto& clientProp : clientProps) { Ice::InitializationData clientInitData; - clientInitData.properties = *q; + clientInitData.properties = clientProp; Ice::CommunicatorHolder clientCommunicator(clientInitData); Ice::ObjectPrx clientPrx(clientCommunicator.communicator(), strPrx); try @@ -987,12 +986,17 @@ allTests(Test::TestHelper* helper) catch (const Ice::SocketException&) { test( - (*p == ipv4 && *q == ipv6) || (*p == ipv6 && *q == ipv4) || - (*p == bothPreferIPv4 && *q == ipv6) || (*p == bothPreferIPv6 && *q == ipv4) || - (*p == bothPreferIPv6 && *q == ipv6 && ipv6NotSupported) || (*p == anyipv4 && *q == ipv6) || - (*p == anyipv6 && *q == ipv4) || (*p == localipv4 && *q == ipv6) || - (*p == localipv6 && *q == ipv4) || (*p == ipv6 && *q == bothPreferIPv4) || - (*p == ipv6 && *q == bothPreferIPv6) || (*p == bothPreferIPv6 && *q == ipv6)); + (serverProp == ipv4 && clientProp == ipv6) || (serverProp == ipv6 && clientProp == ipv4) || + (serverProp == bothPreferIPv4 && clientProp == ipv6) || + (serverProp == bothPreferIPv6 && clientProp == ipv4) || + (serverProp == bothPreferIPv6 && clientProp == ipv6 && ipv6NotSupported) || + (serverProp == anyipv4 && clientProp == ipv6) || + (serverProp == anyipv6 && clientProp == ipv4) || + (serverProp == localipv4 && clientProp == ipv6) || + (serverProp == localipv6 && clientProp == ipv4) || + (serverProp == ipv6 && clientProp == bothPreferIPv4) || + (serverProp == ipv6 && clientProp == bothPreferIPv6) || + (serverProp == bothPreferIPv6 && clientProp == ipv6)); } } serverCommunicator->destroy(); diff --git a/cpp/test/Ice/custom/AllTests.cpp b/cpp/test/Ice/custom/AllTests.cpp index e2328400204..a57a80ff121 100644 --- a/cpp/test/Ice/custom/AllTests.cpp +++ b/cpp/test/Ice/custom/AllTests.cpp @@ -209,9 +209,9 @@ allTests(TestHelper* helper) { MyByteSeq in(5); int i = 0; - for (MyByteSeq::iterator p = in.begin(); p != in.end(); ++p) + for (auto& p : in) { - *p = static_cast('1' + i++); + p = static_cast('1' + i++); } MyByteSeq out; @@ -236,11 +236,11 @@ allTests(TestHelper* helper) { list in; - in.push_back("THESE"); - in.push_back("ARE"); - in.push_back("FIVE"); - in.push_back("SHORT"); - in.push_back("STRINGS."); + in.emplace_back("THESE"); + in.emplace_back("ARE"); + in.emplace_back("FIVE"); + in.emplace_back("SHORT"); + in.emplace_back("STRINGS."); list out; list ret = t->opStringList(in, out); @@ -265,9 +265,9 @@ allTests(TestHelper* helper) { list in(5); short num = 1; - for (list::iterator p = in.begin(); p != in.end(); ++p) + for (auto& p : in) { - (*p).s = num++; + p.s = num++; } list out; @@ -386,7 +386,7 @@ allTests(TestHelper* helper) auto op = out.begin(); auto rp = ret.begin(); - for (auto i : in) + for (const auto& i : in) { test(*op++ == i); test(*rp++ == i); @@ -395,18 +395,18 @@ allTests(TestHelper* helper) { list> in; - in.push_back(DPrx(communicator, "C1:" + endp + " -t 10000")); - in.push_back(DPrx(communicator, "C2:" + endp + " -t 10001")); - in.push_back(DPrx(communicator, "C3:" + endp + " -t 10002")); - in.push_back(DPrx(communicator, "C4:" + endp + " -t 10003")); - in.push_back(DPrx(communicator, "C5:" + endp + " -t 10004")); + in.emplace_back(DPrx(communicator, "C1:" + endp + " -t 10000")); + in.emplace_back(DPrx(communicator, "C2:" + endp + " -t 10001")); + in.emplace_back(DPrx(communicator, "C3:" + endp + " -t 10002")); + in.emplace_back(DPrx(communicator, "C4:" + endp + " -t 10003")); + in.emplace_back(DPrx(communicator, "C5:" + endp + " -t 10004")); list> out; list> ret = t->opDPrxList(in, out); auto op = out.begin(); auto rp = ret.begin(); - for (auto i : in) + for (const auto& i : in) { test(*op++ == i); test(*rp++ == i); @@ -489,7 +489,7 @@ allTests(TestHelper* helper) test(out == idict); test(ret.size() == 1000); - for (CustomMap::const_iterator i = ret.begin(); i != ret.end(); ++i) + for (auto i = ret.begin(); i != ret.end(); ++i) { test(i->second == i->first * i->first); } @@ -687,9 +687,9 @@ allTests(TestHelper* helper) { MyByteSeq in(5); int i = 0; - for (MyByteSeq::iterator p = in.begin(); p != in.end(); ++p) + for (auto& p : in) { - *p = static_cast('1' + i++); + p = static_cast('1' + i++); } auto r = t->opMyByteSeqAsync(in).get(); @@ -712,11 +712,11 @@ allTests(TestHelper* helper) { list in; - in.push_back("THESE"); - in.push_back("ARE"); - in.push_back("FIVE"); - in.push_back("SHORT"); - in.push_back("STRINGS."); + in.emplace_back("THESE"); + in.emplace_back("ARE"); + in.emplace_back("FIVE"); + in.emplace_back("SHORT"); + in.emplace_back("STRINGS."); auto r = t->opStringListAsync(in).get(); test(std::get<1>(r) == in); @@ -739,9 +739,9 @@ allTests(TestHelper* helper) { list in(5); short num = 1; - for (list::iterator p = in.begin(); p != in.end(); ++p) + for (auto& p : in) { - (*p).s = num++; + p.s = num++; } auto r = t->opFixedListAsync(in).get(); @@ -855,7 +855,7 @@ allTests(TestHelper* helper) auto op = std::get<1>(r).begin(); auto rp = std::get<0>(r).begin(); - for (auto i : in) + for (const auto& i : in) { test(*op++ == i); test(*rp++ == i); @@ -864,11 +864,11 @@ allTests(TestHelper* helper) { list> in; - in.push_back(DPrx(communicator, "C1:" + endp + " -t 10000")); - in.push_back(DPrx(communicator, "C2:" + endp + " -t 10001")); - in.push_back(DPrx(communicator, "C3:" + endp + " -t 10002")); - in.push_back(DPrx(communicator, "C4:" + endp + " -t 10003")); - in.push_back(DPrx(communicator, "C5:" + endp + " -t 10004")); + in.emplace_back(DPrx(communicator, "C1:" + endp + " -t 10000")); + in.emplace_back(DPrx(communicator, "C2:" + endp + " -t 10001")); + in.emplace_back(DPrx(communicator, "C3:" + endp + " -t 10002")); + in.emplace_back(DPrx(communicator, "C4:" + endp + " -t 10003")); + in.emplace_back(DPrx(communicator, "C5:" + endp + " -t 10004")); auto r = t->opDPrxListAsync(in).get(); @@ -878,7 +878,7 @@ allTests(TestHelper* helper) auto op = std::get<1>(r).begin(); auto rp = std::get<0>(r).begin(); - for (auto i : in) + for (const auto& i : in) { test(*op++ == i); test(*rp++ == i); @@ -898,7 +898,7 @@ allTests(TestHelper* helper) test(std::get<0>(r).size() == in.size()); auto rp = std::get<0>(r).begin(); - for (auto o : std::get<1>(r)) + for (const auto& o : std::get<1>(r)) { test(o == std::get<1>(r)[0]); test(*rp++ == o); @@ -1143,9 +1143,9 @@ allTests(TestHelper* helper) { MyByteSeq in(5); int i = 0; - for (MyByteSeq::iterator p = in.begin(); p != in.end(); ++p) + for (auto& p : in) { - *p = static_cast('1' + i++); + p = static_cast('1' + i++); } promise done; @@ -1188,11 +1188,11 @@ allTests(TestHelper* helper) { list in; - in.push_back("THESE"); - in.push_back("ARE"); - in.push_back("FIVE"); - in.push_back("SHORT"); - in.push_back("STRINGS."); + in.emplace_back("THESE"); + in.emplace_back("ARE"); + in.emplace_back("FIVE"); + in.emplace_back("SHORT"); + in.emplace_back("STRINGS."); promise done; @@ -1235,9 +1235,9 @@ allTests(TestHelper* helper) { list in(5); short num = 1; - for (list::iterator p = in.begin(); p != in.end(); ++p) + for (auto& p : in) { - (*p).s = num++; + p.s = num++; } promise done; @@ -1422,7 +1422,7 @@ allTests(TestHelper* helper) test(ret.size() == in.size()); auto op = out.begin(); auto rp = ret.begin(); - for (auto i : in) + for (const auto& i : in) { test(*op++ == i); test(*rp++ == i); @@ -1436,11 +1436,11 @@ allTests(TestHelper* helper) { list> in; - in.push_back(DPrx(communicator, "C1:" + endp + " -t 10000")); - in.push_back(DPrx(communicator, "C2:" + endp + " -t 10001")); - in.push_back(DPrx(communicator, "C3:" + endp + " -t 10002")); - in.push_back(DPrx(communicator, "C4:" + endp + " -t 10003")); - in.push_back(DPrx(communicator, "C5:" + endp + " -t 10004")); + in.emplace_back(DPrx(communicator, "C1:" + endp + " -t 10000")); + in.emplace_back(DPrx(communicator, "C2:" + endp + " -t 10001")); + in.emplace_back(DPrx(communicator, "C3:" + endp + " -t 10002")); + in.emplace_back(DPrx(communicator, "C4:" + endp + " -t 10003")); + in.emplace_back(DPrx(communicator, "C5:" + endp + " -t 10004")); promise done; @@ -1451,7 +1451,7 @@ allTests(TestHelper* helper) test(ret.size() == in.size()); auto op = out.begin(); auto rp = ret.begin(); - for (auto i : in) + for (const auto& i : in) { test(*op++ == i); test(*rp++ == i); @@ -1558,7 +1558,7 @@ allTests(TestHelper* helper) auto r = t->opVarDictAsync(idict).get(); test(std::get<1>(r) == idict); test(std::get<0>(r).size() == 1000); - for (auto i : std::get<0>(r)) + for (const auto& i : std::get<0>(r)) { test(i.second == i.first * i.first); } @@ -1606,7 +1606,7 @@ allTests(TestHelper* helper) [&](CustomMap ret, CustomMap out) { test(out == idict); - for (auto i : ret) + for (const auto& i : ret) { test(i.second == i.first * i.first); } @@ -1623,7 +1623,7 @@ allTests(TestHelper* helper) cout << "testing wstring... " << flush; Test1::WstringSeq wseq1; - wseq1.push_back(L"WIDE STRING"); + wseq1.emplace_back(L"WIDE STRING"); Test2::WstringSeq wseq2; wseq2 = wseq1; diff --git a/cpp/test/Ice/custom/StringConverterI.cpp b/cpp/test/Ice/custom/StringConverterI.cpp index 2605de18dc7..9b63a74489c 100644 --- a/cpp/test/Ice/custom/StringConverterI.cpp +++ b/cpp/test/Ice/custom/StringConverterI.cpp @@ -10,7 +10,7 @@ using namespace Ice; byte* Test::StringConverterI::toUTF8(const char* sourceStart, const char* sourceEnd, UTF8Buffer& buffer) const { - size_t size = static_cast(sourceEnd - sourceStart); + auto size = static_cast(sourceEnd - sourceStart); byte* targetStart = buffer.getMoreBytes(size, nullptr); byte* targetEnd = targetStart + size; @@ -25,7 +25,7 @@ Test::StringConverterI::toUTF8(const char* sourceStart, const char* sourceEnd, U void Test::StringConverterI::fromUTF8(const byte* sourceStart, const byte* sourceEnd, string& target) const { - size_t size = static_cast(sourceEnd - sourceStart); + auto size = static_cast(sourceEnd - sourceStart); target.resize(size); for (size_t i = 0; i < size; ++i) { @@ -54,9 +54,9 @@ void Test::WstringConverterI::fromUTF8(const byte* sourceStart, const byte* sourceEnd, wstring& target) const { string s(reinterpret_cast(sourceStart), reinterpret_cast(sourceEnd)); - for (size_t i = 0; i < s.size(); ++i) + for (char& i : s) { - s[i] = static_cast(toupper(s[i])); + i = static_cast(toupper(i)); } target = stringToWstring(s); } diff --git a/cpp/test/Ice/executor/AllTests.cpp b/cpp/test/Ice/executor/AllTests.cpp index bd91e739b0d..8877273f362 100644 --- a/cpp/test/Ice/executor/AllTests.cpp +++ b/cpp/test/Ice/executor/AllTests.cpp @@ -149,9 +149,9 @@ allTests(TestHelper* helper) ByteSeq seq; seq.resize(1024); // Make sure the request doesn't compress too well. - for (ByteSeq::iterator q = seq.begin(); q != seq.end(); ++q) + for (auto& q : seq) { - *q = static_cast(IceInternal::random(255)); + q = static_cast(IceInternal::random(255)); } vector>> completed; @@ -174,7 +174,7 @@ allTests(TestHelper* helper) } } testController->resumeAdapter(); - for (auto& c : completed) + for (const auto& c : completed) { c->get_future().get(); } diff --git a/cpp/test/Ice/faultTolerance/AllTests.cpp b/cpp/test/Ice/faultTolerance/AllTests.cpp index 53f6482c8f8..48efacbe82d 100644 --- a/cpp/test/Ice/faultTolerance/AllTests.cpp +++ b/cpp/test/Ice/faultTolerance/AllTests.cpp @@ -15,9 +15,9 @@ allTests(Test::TestHelper* helper, const vector& ports) Ice::CommunicatorPtr communicator = helper->communicator(); ostringstream ref; ref << "test"; - for (vector::const_iterator p = ports.begin(); p != ports.end(); ++p) + for (int port : ports) { - ref << ":" << helper->getTestEndpoint(*p); + ref << ":" << helper->getTestEndpoint(port); } TestIntfPrx obj(communicator, ref.str()); diff --git a/cpp/test/Ice/info/AllTests.cpp b/cpp/test/Ice/info/AllTests.cpp index f81d2af7344..9d030d42fe9 100644 --- a/cpp/test/Ice/info/AllTests.cpp +++ b/cpp/test/Ice/info/AllTests.cpp @@ -149,9 +149,9 @@ allTests(Test::TestHelper* helper) publishedEndpoints = adapter->getPublishedEndpoints(); test(publishedEndpoints.size() == 1); - for (Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) + for (const auto& endpoint : endpoints) { - ipEndpoint = getTCPEndpointInfo((*p)->getInfo()); + ipEndpoint = getTCPEndpointInfo(endpoint->getInfo()); test(ipEndpoint->port == port); } diff --git a/cpp/test/Ice/info/TestI.cpp b/cpp/test/Ice/info/TestI.cpp index 99f79db0ad7..2819666bd74 100644 --- a/cpp/test/Ice/info/TestI.cpp +++ b/cpp/test/Ice/info/TestI.cpp @@ -101,9 +101,9 @@ TestI::getConnectionInfoAsContext(const Current& c) WSConnectionInfoPtr wsinfo = dynamic_pointer_cast(info); if (wsinfo) { - for (HeaderDict::const_iterator p = wsinfo->headers.begin(); p != wsinfo->headers.end(); ++p) + for (const auto& header : wsinfo->headers) { - ctx["ws." + p->first] = p->second; + ctx["ws." + header.first] = header.second; } } diff --git a/cpp/test/Ice/location/ServerLocator.cpp b/cpp/test/Ice/location/ServerLocator.cpp index 5b3c2848991..415e4f9fd1b 100644 --- a/cpp/test/Ice/location/ServerLocator.cpp +++ b/cpp/test/Ice/location/ServerLocator.cpp @@ -76,7 +76,7 @@ ServerLocatorRegistry::addObject(optional object, const Current&) optional ServerLocatorRegistry::getAdapter(const string& adapter) const { - map>::const_iterator p = _adapters.find(adapter); + auto p = _adapters.find(adapter); if (_adapters.find(adapter) == _adapters.end()) { throw AdapterNotFoundException(); @@ -87,7 +87,7 @@ ServerLocatorRegistry::getAdapter(const string& adapter) const optional ServerLocatorRegistry::getObject(const Identity& id) const { - map>::const_iterator p = _objects.find(id); + auto p = _objects.find(id); if (p == _objects.end()) { throw ObjectNotFoundException(); diff --git a/cpp/test/Ice/maxConnections/AllTests.cpp b/cpp/test/Ice/maxConnections/AllTests.cpp index 3838f90091a..4a874155627 100644 --- a/cpp/test/Ice/maxConnections/AllTests.cpp +++ b/cpp/test/Ice/maxConnections/AllTests.cpp @@ -25,7 +25,7 @@ testCreateConnections(TestIntfPrx p, int connectionCount, function postC } // Close all connections - for (auto& connection : connectionList) + for (const auto& connection : connectionList) { connection->close().get(); } @@ -65,7 +65,7 @@ testCreateConnectionsWithMax(TestIntfPrx p, int max, function postCloseD } // Close all connections - for (auto& connection : connectionList) + for (const auto& connection : connectionList) { connection->close().get(); } @@ -132,7 +132,7 @@ testCreateConnectionsWithMaxAndRecovery(TestIntfPrx p, int max, function connectionList.push_back(p->ice_getCachedConnection()); // Close all connections - for (auto& connection : connectionList) + for (const auto& connection : connectionList) { connection->close().get(); } diff --git a/cpp/test/Ice/maxDispatches/TestI.cpp b/cpp/test/Ice/maxDispatches/TestI.cpp index 4c57f9fa99b..507c2040c1f 100644 --- a/cpp/test/Ice/maxDispatches/TestI.cpp +++ b/cpp/test/Ice/maxDispatches/TestI.cpp @@ -17,7 +17,7 @@ ResponderI::start(const Ice::Current&) responses.swap(_responses); } - for (auto& response : responses) + for (const auto& response : responses) { response(); } diff --git a/cpp/test/Ice/metrics/AllTests.cpp b/cpp/test/Ice/metrics/AllTests.cpp index 1668765f093..d0e8110520a 100644 --- a/cpp/test/Ice/metrics/AllTests.cpp +++ b/cpp/test/Ice/metrics/AllTests.cpp @@ -25,13 +25,13 @@ namespace getClientProps(const Ice::PropertiesAdminPrx& pa, const Ice::PropertyDict& orig, const string& m = string()) { Ice::PropertyDict props = pa->getPropertiesForPrefix("IceMX.Metrics"); - for (Ice::PropertyDict::iterator p = props.begin(); p != props.end(); ++p) + for (auto& prop : props) { - p->second = ""; + prop.second = ""; } - for (Ice::PropertyDict::const_iterator p = orig.begin(); p != orig.end(); ++p) + for (const auto& p : orig) { - props[p->first] = p->second; + props[p.first] = p.second; } string map; if (!m.empty()) @@ -48,13 +48,13 @@ namespace getServerProps(const Ice::PropertiesAdminPrx& pa, const Ice::PropertyDict& orig, const string& m = string()) { Ice::PropertyDict props = pa->getPropertiesForPrefix("IceMX.Metrics"); - for (Ice::PropertyDict::iterator p = props.begin(); p != props.end(); ++p) + for (auto& prop : props) { - p->second = ""; + prop.second = ""; } - for (Ice::PropertyDict::const_iterator p = orig.begin(); p != orig.end(); ++p) + for (const auto& p : orig) { - props[p->first] = p->second; + props[p.first] = p.second; } string map; if (!m.empty()) @@ -135,9 +135,9 @@ namespace IceMX::MetricsView view = metrics->getMetricsView(viewName, timestamp); test(view.find(map) != view.end()); bool ok = true; - for (IceMX::MetricsMap::const_iterator m = view[map].begin(); m != view[map].end(); ++m) + for (const auto& m : view[map]) { - if ((*m)->current != value) + if (m->current != value) { ok = false; break; @@ -350,9 +350,9 @@ namespace map toMap(const IceMX::MetricsMap& mmap) { map m; - for (IceMX::MetricsMap::const_iterator p = mmap.begin(); p != mmap.end(); ++p) + for (const auto& p : mmap) { - m.insert(make_pair((*p)->id, *p)); + m.insert(make_pair(p->id, p)); } return m; } @@ -1210,9 +1210,9 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) cerr << "rim1->total = " << rim1->total << endl; cerr << "rim1->failures = " << rim1->failures << endl; IceMX::MetricsFailures f = clientMetrics->getMetricsFailures("View", "Invocation", im1->id); - for (IceMX::StringIntDict::const_iterator p = f.failures.begin(); p != f.failures.end(); ++p) + for (auto& failure : f.failures) { - cerr << p->first << " = " << p->second << endl; + cerr << failure.first << " = " << failure.second << endl; } } test(rim1->current == 0 && rim1->total == 6 && rim1->failures == 6); diff --git a/cpp/test/Ice/operations/TestAMDI.cpp b/cpp/test/Ice/operations/TestAMDI.cpp index 6689a938127..96c7e218034 100644 --- a/cpp/test/Ice/operations/TestAMDI.cpp +++ b/cpp/test/Ice/operations/TestAMDI.cpp @@ -716,9 +716,9 @@ MyDerivedClassI::opDoubleMarshalingAsync( { double d = 1278312346.0 / 13.0; test(p1 == d); - for (unsigned int i = 0; i < p2.size(); ++i) + for (double i : p2) { - test(p2[i] == d); + test(i == d); } response(); } diff --git a/cpp/test/Ice/operations/TestI.cpp b/cpp/test/Ice/operations/TestI.cpp index 9f73a4b42f5..cedc115181b 100644 --- a/cpp/test/Ice/operations/TestI.cpp +++ b/cpp/test/Ice/operations/TestI.cpp @@ -555,9 +555,9 @@ MyDerivedClassI::opDoubleMarshaling(double p1, Test::DoubleS p2, const Ice::Curr { double d = 1278312346.0 / 13.0; test(p1 == d); - for (unsigned int i = 0; i < p2.size(); ++i) + for (double i : p2) { - test(p2[i] == d); + test(i == d); } } diff --git a/cpp/test/Ice/operations/Twoways.cpp b/cpp/test/Ice/operations/Twoways.cpp index 6a3505f70ed..1e1990d7bee 100644 --- a/cpp/test/Ice/operations/Twoways.cpp +++ b/cpp/test/Ice/operations/Twoways.cpp @@ -463,11 +463,11 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: Test::StringS ssi1; Test::StringS ssi2; - ssi1.push_back("abc"); - ssi1.push_back("de"); - ssi1.push_back("fghi"); + ssi1.emplace_back("abc"); + ssi1.emplace_back("de"); + ssi1.emplace_back("fghi"); - ssi2.push_back("xyz"); + ssi2.emplace_back("xyz"); Test::StringS sso; Test::StringS rso; @@ -661,11 +661,11 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: Test::StringSS ssi2; ssi2.resize(3); - ssi1[0].push_back("abc"); - ssi1[1].push_back("de"); - ssi1[1].push_back("fghi"); + ssi1[0].emplace_back("abc"); + ssi1[1].emplace_back("de"); + ssi1[1].emplace_back("fghi"); - ssi2[2].push_back("xyz"); + ssi2[2].emplace_back("xyz"); Test::StringSS sso; Test::StringSS rso; @@ -692,20 +692,20 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: Test::StringSSS sssi1; sssi1.resize(2); sssi1[0].resize(2); - sssi1[0][0].push_back("abc"); - sssi1[0][0].push_back("de"); - sssi1[0][1].push_back("xyz"); + sssi1[0][0].emplace_back("abc"); + sssi1[0][0].emplace_back("de"); + sssi1[0][1].emplace_back("xyz"); sssi1[1].resize(1); - sssi1[1][0].push_back("hello"); + sssi1[1][0].emplace_back("hello"); Test::StringSSS sssi2; sssi2.resize(3); sssi2[0].resize(2); - sssi2[0][0].push_back(""); - sssi2[0][0].push_back(""); - sssi2[0][1].push_back("abcd"); + sssi2[0][0].emplace_back(""); + sssi2[0][0].emplace_back(""); + sssi2[0][1].emplace_back("abcd"); sssi2[1].resize(1); - sssi2[1][0].push_back(""); + sssi2[1][0].emplace_back(""); Test::StringSSS ssso; Test::StringSSS rsso; @@ -1538,15 +1538,15 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: Test::StringS si2; Test::StringS si3; - si1.push_back("abc"); - si1.push_back("de"); - si1.push_back("fghi"); + si1.emplace_back("abc"); + si1.emplace_back("de"); + si1.emplace_back("fghi"); - si2.push_back("xyz"); - si2.push_back("or"); + si2.emplace_back("xyz"); + si2.emplace_back("or"); - si3.push_back("and"); - si3.push_back("xor"); + si3.emplace_back("and"); + si3.emplace_back("xor"); sdi1["abc"] = si1; sdi1["def"] = si2; @@ -1621,15 +1621,15 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: { const int lengths[] = {0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000}; - for (unsigned int l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l) + for (int length : lengths) { Test::IntS s; - for (int i = 0; i < lengths[l]; ++i) + for (int i = 0; i < length; ++i) { s.push_back(i); } Test::IntS r = p->opIntS(s); - test(r.size() == static_cast(lengths[l])); + test(r.size() == static_cast(length)); for (int j = 0; j < static_cast(r.size()); ++j) { test(r[static_cast(j)] == -j); @@ -1670,11 +1670,11 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: // string impls[] = {"Shared", "PerThread"}; - for (int i = 0; i < 2; i++) + for (const auto& impl : impls) { Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); - initData.properties->setProperty("Ice.ImplicitContext", impls[i]); + initData.properties->setProperty("Ice.ImplicitContext", impl); Ice::CommunicatorPtr ic = Ice::initialize(initData); @@ -1716,7 +1716,7 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: test(ic->getImplicitContext()->remove("one") == "ONE"); - if (impls[i] == "PerThread") + if (impl == "PerThread") { auto invoker = make_shared(q->ice_context(Ice::Context())); auto invokerThread = std::thread([invoker] { invoker->run(); }); @@ -1783,7 +1783,7 @@ twoways(const Ice::CommunicatorPtr& communicator, Test::TestHelper*, const Test: p->opMSeq1(); StringS p1; - p1.push_back("test"); + p1.emplace_back("test"); StringS p2, p3; p3 = p->opMSeq2(p1, p2); test(p2 == p1 && p3 == p1); diff --git a/cpp/test/Ice/operations/TwowaysAMI.cpp b/cpp/test/Ice/operations/TwowaysAMI.cpp index 3f9e2999b53..fc41ca19fe6 100644 --- a/cpp/test/Ice/operations/TwowaysAMI.cpp +++ b/cpp/test/Ice/operations/TwowaysAMI.cpp @@ -1208,11 +1208,11 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) StringS ssi1; StringS ssi2; - ssi1.push_back("abc"); - ssi1.push_back("de"); - ssi1.push_back("fghi"); + ssi1.emplace_back("abc"); + ssi1.emplace_back("de"); + ssi1.emplace_back("fghi"); - ssi2.push_back("xyz"); + ssi2.emplace_back("xyz"); CallbackPtr cb = make_shared(); p->opStringSAsync( @@ -1328,11 +1328,11 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) StringSS ssi2; ssi2.resize(3); - ssi1[0].push_back("abc"); - ssi1[1].push_back("de"); - ssi1[1].push_back("fghi"); + ssi1[0].emplace_back("abc"); + ssi1[1].emplace_back("de"); + ssi1[1].emplace_back("fghi"); - ssi2[2].push_back("xyz"); + ssi2[2].emplace_back("xyz"); CallbackPtr cb = make_shared(); p->opStringSSAsync( @@ -1871,15 +1871,15 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) StringS si2; StringS si3; - si1.push_back("abc"); - si1.push_back("de"); - si1.push_back("fghi"); + si1.emplace_back("abc"); + si1.emplace_back("de"); + si1.emplace_back("fghi"); - si2.push_back("xyz"); - si2.push_back("or"); + si2.emplace_back("xyz"); + si2.emplace_back("or"); - si3.push_back("and"); - si3.push_back("xor"); + si3.emplace_back("and"); + si3.emplace_back("xor"); sdi1["abc"] = si1; sdi1["def"] = si2; @@ -1926,10 +1926,10 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) { const int lengths[] = {0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000}; - for (unsigned int l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l) + for (int length : lengths) { IntS s; - for (int i = 0; i < lengths[l]; ++i) + for (int i = 0; i < length; ++i) { s.push_back(i); } @@ -2007,11 +2007,11 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) // string impls[] = {"Shared", "PerThread"}; - for (int i = 0; i < 2; i++) + for (const auto& impl : impls) { InitializationData initData; initData.properties = communicator->getProperties()->clone(); - initData.properties->setProperty("Ice.ImplicitContext", impls[i]); + initData.properties->setProperty("Ice.ImplicitContext", impl); CommunicatorPtr ic = initialize(initData); @@ -2439,11 +2439,11 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) StringS ssi1; StringS ssi2; - ssi1.push_back("abc"); - ssi1.push_back("de"); - ssi1.push_back("fghi"); + ssi1.emplace_back("abc"); + ssi1.emplace_back("de"); + ssi1.emplace_back("fghi"); - ssi2.push_back("xyz"); + ssi2.emplace_back("xyz"); CallbackPtr cb = make_shared(); auto f = p->opStringSAsync(ssi1, ssi2); @@ -2521,11 +2521,11 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) StringSS ssi2; ssi2.resize(3); - ssi1[0].push_back("abc"); - ssi1[1].push_back("de"); - ssi1[1].push_back("fghi"); + ssi1[0].emplace_back("abc"); + ssi1[1].emplace_back("de"); + ssi1[1].emplace_back("fghi"); - ssi2[2].push_back("xyz"); + ssi2[2].emplace_back("xyz"); CallbackPtr cb = make_shared(); auto f = p->opStringSSAsync(ssi1, ssi2); @@ -3168,15 +3168,15 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) StringS si2; StringS si3; - si1.push_back("abc"); - si1.push_back("de"); - si1.push_back("fghi"); + si1.emplace_back("abc"); + si1.emplace_back("de"); + si1.emplace_back("fghi"); - si2.push_back("xyz"); - si2.push_back("or"); + si2.emplace_back("xyz"); + si2.emplace_back("or"); - si3.push_back("and"); - si3.push_back("xor"); + si3.emplace_back("and"); + si3.emplace_back("xor"); sdi1["abc"] = si1; sdi1["def"] = si2; @@ -3233,10 +3233,10 @@ twowaysAMI(const CommunicatorPtr& communicator, const MyClassPrx& p) { const int lengths[] = {0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000}; - for (unsigned int l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l) + for (int length : lengths) { IntS s; - for (int i = 0; i < lengths[l]; ++i) + for (int i = 0; i < length; ++i) { s.push_back(i); } diff --git a/cpp/test/Ice/optional/AllTests.cpp b/cpp/test/Ice/optional/AllTests.cpp index 0a9a1e696ac..9b3f9885dcc 100644 --- a/cpp/test/Ice/optional/AllTests.cpp +++ b/cpp/test/Ice/optional/AllTests.cpp @@ -483,7 +483,7 @@ allTests(Test::TestHelper* helper, bool) test(mo5->ivsd == mo1->ivsd); test(mo5->imipd.value().size() == mo1->imipd.value().size()); - for (auto& v : mo5->imipd.value()) + for (const auto& v : mo5->imipd.value()) { test(mo1->imipd.value()[v.first] == v.second); } @@ -1742,7 +1742,7 @@ allTests(Test::TestHelper* helper, bool) test(!p2 && !p3); Test::StringSeq seq; - seq.push_back("hello"); + seq.emplace_back("hello"); p1 = seq; p3 = initial->opMSeq2(p1, p2); test(p2 == p1 && p3 == p1); diff --git a/cpp/test/Ice/properties/Client.cpp b/cpp/test/Ice/properties/Client.cpp index f577d70f9e8..1f17d9db19e 100644 --- a/cpp/test/Ice/properties/Client.cpp +++ b/cpp/test/Ice/properties/Client.cpp @@ -45,7 +45,7 @@ Client::run(int, char**) cout << "testing using Ice.Config with multiple config files... " << flush; Ice::PropertiesPtr properties; Ice::StringSeq args; - args.push_back("--Ice.Config=config/config.1, config/config.2, config/config.3"); + args.emplace_back("--Ice.Config=config/config.1, config/config.2, config/config.3"); properties = Ice::createProperties(args); test(properties->getProperty("Config1") == "Config1"); test(properties->getProperty("Config2") == "Config2"); @@ -57,7 +57,7 @@ Client::run(int, char**) cout << "testing configuration file escapes... " << flush; Ice::PropertiesPtr properties; Ice::StringSeq args; - args.push_back("--Ice.Config=config/escapes.cfg"); + args.emplace_back("--Ice.Config=config/escapes.cfg"); properties = Ice::createProperties(args); string props[] = { diff --git a/cpp/test/Ice/retry/InstrumentationI.cpp b/cpp/test/Ice/retry/InstrumentationI.cpp index 6ec8494cd9d..b1e37e75c91 100644 --- a/cpp/test/Ice/retry/InstrumentationI.cpp +++ b/cpp/test/Ice/retry/InstrumentationI.cpp @@ -56,7 +56,7 @@ namespace } }; - // NOLINTNEXTLINE:cert-err58-cpp + // NOLINTNEXTLINE(cert-err58-cpp) Instrumentation::InvocationObserverPtr invocationObserver = make_shared(); class CommunicatorObserverI final : public Instrumentation::CommunicatorObserver @@ -98,7 +98,7 @@ namespace void setObserverUpdater(const Instrumentation::ObserverUpdaterPtr&) final {} }; - // NOLINTNEXTLINE:cert-err58-cpp + // NOLINTNEXTLINE(cert-err58-cpp) Instrumentation::CommunicatorObserverPtr communicatorObserver = make_shared(); void testEqual(int& value, int expected) diff --git a/cpp/test/Ice/slicing/objects/AllTests.cpp b/cpp/test/Ice/slicing/objects/AllTests.cpp index 84dc10d40a7..268641b7cc0 100644 --- a/cpp/test/Ice/slicing/objects/AllTests.cpp +++ b/cpp/test/Ice/slicing/objects/AllTests.cpp @@ -15,7 +15,7 @@ namespace template void breakCycles(const vector>& s) { - for (auto e : s) + for (const auto& e : s) { breakCycles(e); } @@ -23,7 +23,7 @@ namespace template void breakCycles(const map>& d) { - for (auto e : d) + for (const auto& e : d) { breakCycles(e.second); } @@ -394,7 +394,7 @@ namespace void exception_throwBaseAsBase(const ::Ice::Exception& ex) { test(string{ex.ice_id()} == "::Test::BaseException"); - const BaseException& e = dynamic_cast(ex); + const auto& e = dynamic_cast(ex); test(e.sbe == "sbe"); test(e.pb); test(e.pb->sb == "sb"); @@ -406,7 +406,7 @@ namespace void exception_throwDerivedAsBase(const ::Ice::Exception& ex) { test(string{ex.ice_id()} == "::Test::DerivedException"); - const DerivedException& e = dynamic_cast(ex); + const auto& e = dynamic_cast(ex); test(e.sbe == "sbe"); test(e.pb); test(e.pb->sb == "sb1"); @@ -423,7 +423,7 @@ namespace void exception_throwDerivedAsDerived(const ::Ice::Exception& ex) { test(string{ex.ice_id()} == "::Test::DerivedException"); - const DerivedException& e = dynamic_cast(ex); + const auto& e = dynamic_cast(ex); test(e.sbe == "sbe"); test(e.pb); test(e.pb->sb == "sb1"); @@ -440,7 +440,7 @@ namespace void exception_throwUnknownDerivedAsBase(const ::Ice::Exception& ex) { test(string{ex.ice_id()} == "::Test::BaseException"); - const BaseException& e = dynamic_cast(ex); + const auto& e = dynamic_cast(ex); test(e.sbe == "sbe"); test(e.pb); test(e.pb->sb == "sb d2"); diff --git a/cpp/test/Ice/slicing/objects/TestI.cpp b/cpp/test/Ice/slicing/objects/TestI.cpp index 95d2f4d21ca..f0e60dda436 100644 --- a/cpp/test/Ice/slicing/objects/TestI.cpp +++ b/cpp/test/Ice/slicing/objects/TestI.cpp @@ -15,7 +15,7 @@ namespace template void breakCycles(const vector>& s) { - for (auto e : s) + for (const auto& e : s) { breakCycles(e); } @@ -23,7 +23,7 @@ namespace template void breakCycles(const map>& d) { - for (auto e : d) + for (const auto& e : d) { breakCycles(e.second); } @@ -138,7 +138,7 @@ TestI::TestI() = default; TestI::~TestI() { - for (auto e : _values) + for (const auto& e : _values) { breakCycles(e); } diff --git a/cpp/test/Ice/stream/Client.cpp b/cpp/test/Ice/stream/Client.cpp index f1b8933aa2c..7a68f72044c 100644 --- a/cpp/test/Ice/stream/Client.cpp +++ b/cpp/test/Ice/stream/Client.cpp @@ -57,7 +57,7 @@ class TestObjectReader : public Ice::Value void patchObject(void* addr, const Ice::ValuePtr& v) { - Ice::ValuePtr* p = static_cast(addr); + auto* p = static_cast(addr); assert(p); *p = v; } @@ -316,7 +316,7 @@ allTests(Test::TestHelper* helper) BoolSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::BoolSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -346,7 +346,7 @@ allTests(Test::TestHelper* helper) ByteSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::ByteSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -375,7 +375,7 @@ allTests(Test::TestHelper* helper) ShortSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::ShortSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -404,7 +404,7 @@ allTests(Test::TestHelper* helper) IntSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::IntSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -433,7 +433,7 @@ allTests(Test::TestHelper* helper) LongSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::LongSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -462,7 +462,7 @@ allTests(Test::TestHelper* helper) FloatSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::FloatSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -491,7 +491,7 @@ allTests(Test::TestHelper* helper) DoubleSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::DoubleSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -506,10 +506,10 @@ allTests(Test::TestHelper* helper) { Ice::StringSeq arr; - arr.push_back("string1"); - arr.push_back("string2"); - arr.push_back("string3"); - arr.push_back("string4"); + arr.emplace_back("string1"); + arr.emplace_back("string2"); + arr.emplace_back("string3"); + arr.emplace_back("string4"); Ice::OutputStream out(communicator); out.write(arr); out.finished(data); @@ -520,7 +520,7 @@ allTests(Test::TestHelper* helper) StringSS arrS; arrS.push_back(arr); - arrS.push_back(Ice::StringSeq()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -550,7 +550,7 @@ allTests(Test::TestHelper* helper) MyEnumSS arrS; arrS.push_back(arr); - arrS.push_back(MyEnumS()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -599,7 +599,7 @@ allTests(Test::TestHelper* helper) LargeStructSS arrS; arrS.push_back(arr); - arrS.push_back(LargeStructS()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -655,10 +655,10 @@ allTests(Test::TestHelper* helper) c->seq7.push_back(3); c->seq7.push_back(4); - c->seq8.push_back("string1"); - c->seq8.push_back("string2"); - c->seq8.push_back("string3"); - c->seq8.push_back("string4"); + c->seq8.emplace_back("string1"); + c->seq8.emplace_back("string2"); + c->seq8.emplace_back("string3"); + c->seq8.emplace_back("string4"); c->seq9.push_back(MyEnum::enum3); c->seq9.push_back(MyEnum::enum2); @@ -697,7 +697,7 @@ allTests(Test::TestHelper* helper) MyClassSS arrS; arrS.push_back(arr); - arrS.push_back(MyClassS()); + arrS.emplace_back(); arrS.push_back(arr); Ice::OutputStream out2(communicator); @@ -713,43 +713,43 @@ allTests(Test::TestHelper* helper) test(arr2S[0].size() == arrS[0].size()); test(arr2S[1].size() == arrS[1].size()); test(arr2S[2].size() == arrS[2].size()); - for (size_t j = 0; j < arr2S.size(); ++j) + for (const auto& j : arr2S) { - for (size_t k = 0; k < arr2S[j].size(); ++k) + for (size_t k = 0; k < j.size(); ++k) { - test(arr2S[j][k]->c == arr2S[j][k]); - test(arr2S[j][k]->o == arr2S[j][k]); - test(arr2S[j][k]->s.e == MyEnum::enum2); - test(arr2S[j][k]->seq1 == arr[k]->seq1); - test(arr2S[j][k]->seq2 == arr[k]->seq2); - test(arr2S[j][k]->seq3 == arr[k]->seq3); - test(arr2S[j][k]->seq4 == arr[k]->seq4); - test(arr2S[j][k]->seq5 == arr[k]->seq5); - test(arr2S[j][k]->seq6 == arr[k]->seq6); - test(arr2S[j][k]->seq7 == arr[k]->seq7); - test(arr2S[j][k]->seq8 == arr[k]->seq8); - test(arr2S[j][k]->seq9 == arr[k]->seq9); - test(arr2S[j][k]->d["hi"] == arr2S[j][k]); + test(j[k]->c == j[k]); + test(j[k]->o == j[k]); + test(j[k]->s.e == MyEnum::enum2); + test(j[k]->seq1 == arr[k]->seq1); + test(j[k]->seq2 == arr[k]->seq2); + test(j[k]->seq3 == arr[k]->seq3); + test(j[k]->seq4 == arr[k]->seq4); + test(j[k]->seq5 == arr[k]->seq5); + test(j[k]->seq6 == arr[k]->seq6); + test(j[k]->seq7 == arr[k]->seq7); + test(j[k]->seq8 == arr[k]->seq8); + test(j[k]->seq9 == arr[k]->seq9); + test(j[k]->d["hi"] == j[k]); } } auto clearS = [](MyClassS& arr3) { - for (MyClassS::iterator p = arr3.begin(); p != arr3.end(); ++p) + for (const auto& p : arr3) { - if (*p) + if (p) { - (*p)->c = nullptr; - (*p)->o = nullptr; - (*p)->d["hi"] = nullptr; + p->c = nullptr; + p->o = nullptr; + p->d["hi"] = nullptr; } } }; auto clearSS = [clearS](MyClassSS& arr3) { - for (MyClassSS::iterator p = arr3.begin(); p != arr3.end(); ++p) + for (auto& p : arr3) { - clearS(*p); + clearS(p); } }; clearS(arr); @@ -835,10 +835,10 @@ allTests(Test::TestHelper* helper) c->seq7.push_back(3); c->seq7.push_back(4); - c->seq8.push_back("string1"); - c->seq8.push_back("string2"); - c->seq8.push_back("string3"); - c->seq8.push_back("string4"); + c->seq8.emplace_back("string1"); + c->seq8.emplace_back("string2"); + c->seq8.emplace_back("string3"); + c->seq8.emplace_back("string4"); c->seq9.push_back(MyEnum::enum3); c->seq9.push_back(MyEnum::enum2); diff --git a/cpp/test/IceBox/configuration/AllTests.cpp b/cpp/test/IceBox/configuration/AllTests.cpp index 0189b6234f3..84e045cfd67 100644 --- a/cpp/test/IceBox/configuration/AllTests.cpp +++ b/cpp/test/IceBox/configuration/AllTests.cpp @@ -28,8 +28,8 @@ allTests(Test::TestHelper* helper) test(service1->getProperty("Arg") == "1"); Ice::StringSeq args1; - args1.push_back("-a"); - args1.push_back("--Arg=2"); + args1.emplace_back("-a"); + args1.emplace_back("--Arg=2"); test(service1->getArgs() == args1); test(service2->getProperty("Ice.ProgramName") == "Test"); @@ -37,7 +37,7 @@ allTests(Test::TestHelper* helper) test(service2->getProperty("Service1.ArgProp") == ""); Ice::StringSeq args2; - args2.push_back("--Service1.ArgProp=1"); + args2.emplace_back("--Service1.ArgProp=1"); test(service2->getArgs() == args2); cout << "ok" << endl; @@ -57,7 +57,7 @@ allTests(Test::TestHelper* helper) test(service4->getProperty("Ice.Trace.Slicing") == "3"); Ice::StringSeq args4; - args4.push_back("--Service3.Prop=2"); + args4.emplace_back("--Service3.Prop=2"); test(service4->getArgs() == args4); cout << "ok" << endl; diff --git a/cpp/test/IceBridge/simple/TestI.cpp b/cpp/test/IceBridge/simple/TestI.cpp index fdc0e0ec48a..6244ab389f3 100644 --- a/cpp/test/IceBridge/simple/TestI.cpp +++ b/cpp/test/IceBridge/simple/TestI.cpp @@ -11,7 +11,7 @@ using namespace Test; namespace { - Ice::Identity callbackId{"callback", ""}; // NOLINT:cert-err58-cpp + Ice::Identity callbackId{"callback", ""}; // NOLINT(cert-err58-cpp) } void diff --git a/cpp/test/IceDiscovery/simple/AllTests.cpp b/cpp/test/IceDiscovery/simple/AllTests.cpp index 7c5ad9b106d..fbe3eaae5ba 100644 --- a/cpp/test/IceDiscovery/simple/AllTests.cpp +++ b/cpp/test/IceDiscovery/simple/AllTests.cpp @@ -21,30 +21,29 @@ allTests(Test::TestHelper* helper, int num) { ostringstream os; os << "controller" << i; - proxies.push_back(ControllerPrx(communicator, os.str())); + proxies.emplace_back(ControllerPrx(communicator, os.str())); } { ostringstream os; os << "controller" << i << "@control" << i; - indirectProxies.push_back(ControllerPrx(communicator, os.str())); + indirectProxies.emplace_back(ControllerPrx(communicator, os.str())); } } cout << "testing indirect proxies... " << flush; { - for (vector>::const_iterator p = indirectProxies.begin(); p != indirectProxies.end(); - ++p) + for (const auto& indirectProxy : indirectProxies) { - (*p)->ice_ping(); + indirectProxy->ice_ping(); } } cout << "ok" << endl; cout << "testing well-known proxies... " << flush; { - for (vector>::const_iterator p = proxies.begin(); p != proxies.end(); ++p) + for (const auto& proxy : proxies) { - (*p)->ice_ping(); + proxy->ice_ping(); } } cout << "ok" << endl; @@ -243,9 +242,9 @@ allTests(Test::TestHelper* helper, int num) cout << "ok" << endl; cout << "shutting down... " << flush; - for (vector>::const_iterator p = proxies.begin(); p != proxies.end(); ++p) + for (const auto& proxy : proxies) { - (*p)->shutdown(); + proxy->shutdown(); } cout << "ok" << endl; } diff --git a/cpp/test/IceGrid/activation/AllTests.cpp b/cpp/test/IceGrid/activation/AllTests.cpp index 0b0f9eaf312..009396b0281 100644 --- a/cpp/test/IceGrid/activation/AllTests.cpp +++ b/cpp/test/IceGrid/activation/AllTests.cpp @@ -433,7 +433,7 @@ allTests(Test::TestHelper* helper) { auto pinger = make_shared(invalid, 10); auto t = thread([pinger]() { pinger->run(); }); - pingers.push_back(make_pair(pinger, std::move(t))); + pingers.emplace_back(pinger, std::move(t)); } for (const auto& p : pingers) @@ -463,7 +463,7 @@ allTests(Test::TestHelper* helper) { auto pinger = make_shared(invalid, 10); auto t = thread([pinger]() { pinger->run(); }); - pingers.push_back(make_pair(pinger, std::move(t))); + pingers.emplace_back(pinger, std::move(t)); } for (const auto& p : pingers) @@ -493,7 +493,7 @@ allTests(Test::TestHelper* helper) { auto pinger = make_shared(invalid, 5); auto t = thread([pinger]() { pinger->run(); }); - pingers.push_back(make_pair(pinger, std::move(t))); + pingers.emplace_back(pinger, std::move(t)); } for (const auto& p : pingers) @@ -556,7 +556,7 @@ allTests(Test::TestHelper* helper) { auto pinger = make_shared(proxy, 1); auto t = thread([pinger]() { pinger->run(); }); - pingers.push_back(make_pair(pinger, std::move(t))); + pingers.emplace_back(pinger, std::move(t)); } for (const auto& p : pingers) diff --git a/cpp/test/IceGrid/deployer/AllTests.cpp b/cpp/test/IceGrid/deployer/AllTests.cpp index 56cd5490225..571d6892f48 100644 --- a/cpp/test/IceGrid/deployer/AllTests.cpp +++ b/cpp/test/IceGrid/deployer/AllTests.cpp @@ -553,13 +553,13 @@ allTests(Test::TestHelper* helper) cout << "testing variables... " << flush; vector> proxies; obj = TestIntfPrx(comm, "Server1@Server1.Server"); - proxies.push_back(obj); + proxies.emplace_back(obj); obj = TestIntfPrx(comm, "IceBox1-Service1@IceBox1.Service1.Service1"); - proxies.push_back(obj); + proxies.emplace_back(obj); obj = TestIntfPrx(comm, "SimpleServer@SimpleServer.Server"); - proxies.push_back(obj); + proxies.emplace_back(obj); obj = TestIntfPrx(comm, "SimpleIceBox-SimpleService@SimpleIceBox.SimpleService.SimpleService"); - proxies.push_back(obj); + proxies.emplace_back(obj); for (const auto& p : proxies) { @@ -680,10 +680,10 @@ allTests(Test::TestHelper* helper) cout << "testing validation... " << flush; TemplateDescriptor templ; - templ.parameters.push_back("name"); - templ.parameters.push_back("nam3"); - templ.parameters.push_back("nam2"); - templ.parameters.push_back("nam3"); + templ.parameters.emplace_back("name"); + templ.parameters.emplace_back("nam3"); + templ.parameters.emplace_back("nam2"); + templ.parameters.emplace_back("nam3"); templ.descriptor = make_shared(); ServerDescriptorPtr server = dynamic_pointer_cast(templ.descriptor); server->id = "test"; diff --git a/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp b/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp index 8cb3e47167f..e4fe820000b 100644 --- a/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp +++ b/cpp/test/IceGrid/noRestartUpdate/AllTests.cpp @@ -210,7 +210,7 @@ allTests(Test::TestHelper* helper) int server2Pid = admin->getServerPid("Server2"); TemplateDescriptor templ; - templ.parameters.push_back("name"); + templ.parameters.emplace_back("name"); templ.descriptor = make_shared(); server = dynamic_pointer_cast(templ.descriptor); server->id = "${name}"; @@ -271,7 +271,7 @@ allTests(Test::TestHelper* helper) cout << "testing server remove... " << flush; update = empty; - update.nodes[0].removeServers.push_back("Server2"); + update.nodes[0].removeServers.emplace_back("Server2"); try { admin->updateApplicationWithoutRestart(update); @@ -288,7 +288,7 @@ allTests(Test::TestHelper* helper) test(server2Pid == admin->getServerPid("Server2")); update = empty; - update.nodes[0].removeServers.push_back("Server1"); + update.nodes[0].removeServers.emplace_back("Server1"); try { admin->updateApplicationWithoutRestart(update); @@ -306,7 +306,7 @@ allTests(Test::TestHelper* helper) admin->stopServer("Server2"); update.nodes[0].removeServers.clear(); - update.nodes[0].removeServers.push_back("Server2"); + update.nodes[0].removeServers.emplace_back("Server2"); try { admin->updateApplicationWithoutRestart(update); diff --git a/cpp/test/IceGrid/replicaGroup/AllTests.cpp b/cpp/test/IceGrid/replicaGroup/AllTests.cpp index 82b88488df6..fe10a91e5d5 100644 --- a/cpp/test/IceGrid/replicaGroup/AllTests.cpp +++ b/cpp/test/IceGrid/replicaGroup/AllTests.cpp @@ -845,7 +845,7 @@ allTests(Test::TestHelper* helper) ApplicationUpdateDescriptor update; update.name = "Test"; - update.removeReplicaGroups.push_back("Random"); + update.removeReplicaGroups.emplace_back("Random"); try { admin->updateApplication(update); @@ -942,7 +942,7 @@ allTests(Test::TestHelper* helper) update = ApplicationUpdateDescriptor(); update.name = "Test1"; - update.removeReplicaGroups.push_back("ReplicatedAdapterFromTest1"); + update.removeReplicaGroups.emplace_back("ReplicatedAdapterFromTest1"); try { admin->updateApplication(update); @@ -972,13 +972,13 @@ allTests(Test::TestHelper* helper) cout << "testing replica group with different server encoding support... " << flush; { vector loadBalancings; - loadBalancings.push_back("Random"); - loadBalancings.push_back("RoundRobin"); - loadBalancings.push_back("RoundRobin-All"); - for (vector::const_iterator p = loadBalancings.begin(); p != loadBalancings.end(); ++p) + loadBalancings.emplace_back("Random"); + loadBalancings.emplace_back("RoundRobin"); + loadBalancings.emplace_back("RoundRobin-All"); + for (const auto& loadBalancing : loadBalancings) { map params; - params["replicaGroup"] = *p; + params["replicaGroup"] = loadBalancing; params["id"] = "Server1"; params["encoding"] = "1.0"; instantiateServer(admin, "Server", "localnode", params); @@ -989,7 +989,7 @@ allTests(Test::TestHelper* helper) params["encoding"] = "1.0"; instantiateServer(admin, "Server", "localnode", params); - TestIntfPrx obj(comm, *p); + TestIntfPrx obj(comm, loadBalancing); obj = obj->ice_locatorCacheTimeout(0); obj = obj->ice_connectionCached(false); diff --git a/cpp/test/IceGrid/replicaGroup/RegistryPlugin.cpp b/cpp/test/IceGrid/replicaGroup/RegistryPlugin.cpp index 0a1acddbc5f..22a16e171cd 100644 --- a/cpp/test/IceGrid/replicaGroup/RegistryPlugin.cpp +++ b/cpp/test/IceGrid/replicaGroup/RegistryPlugin.cpp @@ -41,16 +41,18 @@ namespace if (_testFacade) { _testFacade = false; // Only test once. - for (Ice::StringSeq::const_iterator p = adpts.begin(); p != adpts.end(); ++p) + for (const auto& adpt : adpts) { try { - test(_facade->getApplicationInfo(_facade->getAdapterApplication(*p)).descriptor.name == "Test"); - test(_facade->getServerInfo(_facade->getAdapterServer(*p)).application == "Test"); - test(_facade->getNodeInfo(_facade->getAdapterNode(*p)).name == "localnode"); - test(_facade->getNodeLoad(_facade->getAdapterNode(*p)).avg1 >= 0.0); - test(_facade->getAdapterInfo(*p)[0].replicaGroupId == id); - test(_facade->getPropertyForAdapter(*p, "Identity") == id); + test( + _facade->getApplicationInfo(_facade->getAdapterApplication(adpt)).descriptor.name == + "Test"); + test(_facade->getServerInfo(_facade->getAdapterServer(adpt)).application == "Test"); + test(_facade->getNodeInfo(_facade->getAdapterNode(adpt)).name == "localnode"); + test(_facade->getNodeLoad(_facade->getAdapterNode(adpt)).avg1 >= 0.0); + test(_facade->getAdapterInfo(adpt)[0].replicaGroupId == id); + test(_facade->getPropertyForAdapter(adpt, "Identity") == id); } catch (const Ice::Exception& ex) { diff --git a/cpp/test/IceGrid/replication/AllTests.cpp b/cpp/test/IceGrid/replication/AllTests.cpp index d218beb88c6..046454a2008 100644 --- a/cpp/test/IceGrid/replication/AllTests.cpp +++ b/cpp/test/IceGrid/replication/AllTests.cpp @@ -17,10 +17,10 @@ using namespace IceGrid; namespace { - // NOLINTBEGIN:cert-err58-cpp + // NOLINTBEGIN(cert-err58-cpp) const auto sleepTime = 100ms; const int maxRetry = static_cast(120000 / sleepTime.count()); // 2 minutes - // NOLINTEND + // NOLINTEND(cert-err58-cpp) void waitForServerState(const optional& admin, const string& server, bool up) { diff --git a/cpp/test/IceGrid/session/AllTests.cpp b/cpp/test/IceGrid/session/AllTests.cpp index 5bbea46c754..fb04ad847c0 100644 --- a/cpp/test/IceGrid/session/AllTests.cpp +++ b/cpp/test/IceGrid/session/AllTests.cpp @@ -24,7 +24,7 @@ class ObserverBase { for (const auto& p : _observers) { - vector::const_iterator q = p.second->_stack.begin(); + auto q = p.second->_stack.begin(); if (p.second->_stack.size() > 10) { q = p.second->_stack.begin() + @@ -374,9 +374,9 @@ class RegistryObserverI final : public RegistryObserver, public ObserverBase void registryInit(RegistryInfoSeq info, const Ice::Current&) override { lock_guard lg(_mutex); - for (RegistryInfoSeq::const_iterator p = info.begin(); p != info.end(); ++p) + for (const auto& p : info) { - registries[p->name] = *p; + registries[p.name] = p; } updated("init"); } @@ -1543,7 +1543,7 @@ allTests(TestHelper* helper) auto server = make_shared(); server->id = "node-1"; server->exe = properties->getProperty("IceGridNodeExe"); - server->options.push_back("--nowarn"); + server->options.emplace_back("--nowarn"); server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; diff --git a/cpp/test/IceGrid/update/AllTests.cpp b/cpp/test/IceGrid/update/AllTests.cpp index 6767b7c7834..70e67284df9 100644 --- a/cpp/test/IceGrid/update/AllTests.cpp +++ b/cpp/test/IceGrid/update/AllTests.cpp @@ -26,11 +26,11 @@ addProperty(const CommunicatorDescriptorPtr& communicator, const string& name, c string getProperty(const PropertyDescriptorSeq& properties, const string& name) { - for (PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) + for (const auto& prop : properties) { - if (q->name == name) + if (prop.name == name) { - return q->value; + return prop.value; } } return ""; @@ -48,13 +48,11 @@ createProperty(const string& name, const string& value) bool hasProperty(const CommunicatorDescriptorPtr& desc, const string& name, const string& value) { - for (PropertyDescriptorSeq::const_iterator p = desc->propertySet.properties.begin(); - p != desc->propertySet.properties.end(); - ++p) + for (const auto& prop : desc->propertySet.properties) { - if (p->name == name) + if (prop.name == name) { - return p->value == value; + return prop.value == value; } } return false; @@ -154,7 +152,7 @@ allTests(Test::TestHelper* helper) } TemplateDescriptor templ; - templ.parameters.push_back("name"); + templ.parameters.emplace_back("name"); templ.descriptor = make_shared(); server = dynamic_pointer_cast(templ.descriptor); server->id = "${name}"; @@ -226,7 +224,7 @@ allTests(Test::TestHelper* helper) cout << "testing server remove... " << flush; update = empty; - update.nodes[0].removeServers.push_back("Server2"); + update.nodes[0].removeServers.emplace_back("Server2"); try { admin->updateApplication(update); @@ -262,7 +260,7 @@ allTests(Test::TestHelper* helper) } update = empty; - update.removeServerTemplates.push_back("ServerTemplate"); + update.removeServerTemplates.emplace_back("ServerTemplate"); try { admin->updateApplication(update); @@ -279,7 +277,7 @@ allTests(Test::TestHelper* helper) } update = empty; - update.nodes[0].removeServers.push_back("Server1"); + update.nodes[0].removeServers.emplace_back("Server1"); try { admin->updateApplication(update); @@ -300,7 +298,7 @@ allTests(Test::TestHelper* helper) } update = empty; - update.removeServerTemplates.push_back("ServerTemplate"); + update.removeServerTemplates.emplace_back("ServerTemplate"); try { admin->updateApplication(update); @@ -690,7 +688,7 @@ allTests(Test::TestHelper* helper) cout << "testing node remove... " << flush; update.nodes.clear(); - update.removeNodes.push_back("node1"); + update.removeNodes.emplace_back("node1"); try { admin->updateApplication(update); @@ -725,8 +723,8 @@ allTests(Test::TestHelper* helper) addProperty(server, "ServerParamVar", "${serverparamvar}"); TemplateDescriptor templ; - templ.parameters.push_back("name"); - templ.parameters.push_back("serverparamvar"); + templ.parameters.emplace_back("name"); + templ.parameters.emplace_back("serverparamvar"); templ.descriptor = server; ApplicationDescriptor testApp; @@ -763,7 +761,7 @@ allTests(Test::TestHelper* helper) ApplicationUpdateDescriptor empty; empty.name = "TestApp"; ApplicationUpdateDescriptor update = empty; - update.removeVariables.push_back("appvar"); + update.removeVariables.emplace_back("appvar"); try { admin->updateApplication(update); @@ -783,7 +781,7 @@ allTests(Test::TestHelper* helper) update = empty; NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "node1"; - nodeUpdate.removeVariables.push_back("nodevar"); + nodeUpdate.removeVariables.emplace_back("nodevar"); update.nodes.push_back(nodeUpdate); try { @@ -880,7 +878,7 @@ allTests(Test::TestHelper* helper) addProperty(service, "ServiceProp", "test"); TemplateDescriptor svcTempl; - svcTempl.parameters.push_back("name"); + svcTempl.parameters.emplace_back("name"); svcTempl.descriptor = service; ServiceInstanceDescriptor serviceInstance; @@ -894,13 +892,13 @@ allTests(Test::TestHelper* helper) server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; - server->propertySet.references.push_back("ApplicationPropertySet"); - server->propertySet.references.push_back("NodePropertySet"); + server->propertySet.references.emplace_back("ApplicationPropertySet"); + server->propertySet.references.emplace_back("NodePropertySet"); addProperty(server, "ServerProp", "test"); server->services.push_back(serviceInstance); TemplateDescriptor templ; - templ.parameters.push_back("name"); + templ.parameters.emplace_back("name"); templ.descriptor = server; ApplicationDescriptor testApp; @@ -999,7 +997,7 @@ allTests(Test::TestHelper* helper) nodeUpdate.serverInstances.clear(); nodeUpdate.propertySets["NodePropertySet"].properties.clear(); nodeUpdate.propertySets["NodePropertySet"].properties.push_back(createProperty("NodeProp", "updated")); - nodeUpdate.removePropertySets.push_back("NodePropertySet1"); + nodeUpdate.removePropertySets.emplace_back("NodePropertySet1"); update.nodes.push_back(nodeUpdate); admin->updateApplication(update); info = admin->getServerInfo("Server"); @@ -1013,7 +1011,7 @@ allTests(Test::TestHelper* helper) update.propertySets["ApplicationPropertySet"].properties.clear(); update.propertySets["ApplicationPropertySet"].properties.push_back( createProperty("ApplicationProp", "updated")); - update.removePropertySets.push_back("ApplicationPropertySet1"); + update.removePropertySets.emplace_back("ApplicationPropertySet1"); admin->updateApplication(update); info = admin->getServerInfo("Server"); test(hasProperty(info.descriptor, "ApplicationProp", "updated")); @@ -1099,7 +1097,7 @@ allTests(Test::TestHelper* helper) server->pwd = "."; server->applicationDistrib = false; server->allocatable = false; - server->options.push_back("--nowarn"); + server->options.emplace_back("--nowarn"); addProperty(server, "IceGrid.Node.Name", "node-${index}"); addProperty(server, "IceGrid.Node.Data", properties->getProperty("TestDir") + "/db/node-${index}"); @@ -1108,7 +1106,7 @@ allTests(Test::TestHelper* helper) addProperty(server, "Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); nodeApp.serverTemplates["nodeTemplate"].descriptor = server; - nodeApp.serverTemplates["nodeTemplate"].parameters.push_back("index"); + nodeApp.serverTemplates["nodeTemplate"].parameters.emplace_back("index"); ServerInstanceDescriptor instance; instance._cpp_template = "nodeTemplate"; @@ -1203,7 +1201,7 @@ allTests(Test::TestHelper* helper) NodeUpdateDescriptor nodeUpdate; nodeUpdate.name = "node-1"; - nodeUpdate.removeServers.push_back("Server"); + nodeUpdate.removeServers.emplace_back("Server"); update.nodes.push_back(nodeUpdate); nodeUpdate.name = "node-2"; nodeUpdate.servers.push_back(server); @@ -1243,7 +1241,7 @@ allTests(Test::TestHelper* helper) update.name = "TestApp"; nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "node-2"; - nodeUpdate.removeServers.push_back("Server"); + nodeUpdate.removeServers.emplace_back("Server"); update.nodes.push_back(nodeUpdate); nodeUpdate = NodeUpdateDescriptor(); nodeUpdate.name = "unknownNode"; diff --git a/cpp/test/IceSSL/configuration/AllTests.cpp b/cpp/test/IceSSL/configuration/AllTests.cpp index 8ea58619930..5bf249c4c47 100644 --- a/cpp/test/IceSSL/configuration/AllTests.cpp +++ b/cpp/test/IceSSL/configuration/AllTests.cpp @@ -21,7 +21,7 @@ string toHexString(vector data) { ostringstream os; - for (vector::const_iterator i = data.begin(); i != data.end();) + for (auto i = data.begin(); i != data.end();) { unsigned char c = *i; os.fill('0'); diff --git a/cpp/test/IceSSL/configuration/TestI.cpp b/cpp/test/IceSSL/configuration/TestI.cpp index e4969308f6d..4902b832942 100644 --- a/cpp/test/IceSSL/configuration/TestI.cpp +++ b/cpp/test/IceSSL/configuration/TestI.cpp @@ -58,9 +58,9 @@ ServerFactoryI::createServer(Test::Properties props, const Current&) { InitializationData initData; initData.properties = createProperties(); - for (Test::Properties::const_iterator p = props.begin(); p != props.end(); ++p) + for (const auto& prop : props) { - initData.properties->setProperty(p->first, p->second); + initData.properties->setProperty(prop.first, prop.second); } initData.properties->setProperty("IceSSL.DefaultDir", _defaultDir); @@ -77,7 +77,7 @@ ServerFactoryI::createServer(Test::Properties props, const Current&) void ServerFactoryI::destroyServer(optional srv, const Ice::Current&) { - map::iterator p = _servers.find(srv->ice_getIdentity()); + auto p = _servers.find(srv->ice_getIdentity()); if (p != _servers.end()) { p->second->destroy(); diff --git a/cpp/test/IceStorm/rep1/Publisher.cpp b/cpp/test/IceStorm/rep1/Publisher.cpp index 002799bd44b..17103a37c53 100644 --- a/cpp/test/IceStorm/rep1/Publisher.cpp +++ b/cpp/test/IceStorm/rep1/Publisher.cpp @@ -87,7 +87,7 @@ Publisher::run(int argc, char** argv) { Ice::EndpointSeq e; e.push_back(p); - single.push_back(prx->ice_endpoints(e)); + single.emplace_back(prx->ice_endpoints(e)); } } if (single.size() <= 1) diff --git a/cpp/test/IceStorm/stress/Subscriber.cpp b/cpp/test/IceStorm/stress/Subscriber.cpp index 93000dd4b8b..a93e5cd7239 100644 --- a/cpp/test/IceStorm/stress/Subscriber.cpp +++ b/cpp/test/IceStorm/stress/Subscriber.cpp @@ -389,7 +389,7 @@ Subscriber::run(int argc, char** argv) IceStorm::QoS qos; string reliability = ""; - IceStorm::QoS::const_iterator q = p.qos.find("reliability"); + auto q = p.qos.find("reliability"); if (q != p.qos.end()) { reliability = q->second; diff --git a/cpp/test/IceUtil/sha1/Client.cpp b/cpp/test/IceUtil/sha1/Client.cpp index 4e9a7f93ed1..1146e61b972 100644 --- a/cpp/test/IceUtil/sha1/Client.cpp +++ b/cpp/test/IceUtil/sha1/Client.cpp @@ -58,11 +58,11 @@ namespace string toHex(const string& data) { ostringstream os; - for (size_t i = 0; i < data.size(); ++i) + for (char i : data) { os.width(2); os.fill('0'); - os << hex << (int)static_cast(data[i]); + os << hex << (int)static_cast(i); } return os.str(); } @@ -95,7 +95,7 @@ Client::run(int, char*[]) // // Test adding the data in chunks // - const unsigned char* begin = reinterpret_cast(&item->data[0]); + const auto* begin = reinterpret_cast(&item->data[0]); const unsigned char* end = begin + strlen(item->data); while (begin != end) { diff --git a/cpp/test/Slice/structure/Client.cpp b/cpp/test/Slice/structure/Client.cpp index d8f551498e5..c931c56cca6 100644 --- a/cpp/test/Slice/structure/Client.cpp +++ b/cpp/test/Slice/structure/Client.cpp @@ -26,9 +26,9 @@ allTests(const Ice::CommunicatorPtr& communicator) def_s2.f = 1.0; def_s2.d = 2.0; def_s2.str = "string"; - def_s2.ss.push_back("one"); - def_s2.ss.push_back("two"); - def_s2.ss.push_back("three"); + def_s2.ss.emplace_back("one"); + def_s2.ss.emplace_back("two"); + def_s2.ss.emplace_back("three"); def_s2.il.push_back(1); def_s2.il.push_back(2); def_s2.il.push_back(3);