Skip to content

Make iterators const if possible #1195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hazelcast/include/hazelcast/client/iexecutor_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ class HAZELCAST_API iexecutor_service : public proxy::ProxyImpl
void execute_on_members(const HazelcastSerializable& command,
const std::vector<member>& members)
{
for (std::vector<member>::const_iterator it = members.begin();
it != members.end();
for (std::vector<member>::const_iterator it = members.cbegin();
it != members.cend();
++it) {
submit_to_member<HazelcastSerializable, executor_marker>(command,
*it);
Expand Down Expand Up @@ -241,8 +241,8 @@ class HAZELCAST_API iexecutor_service : public proxy::ProxyImpl
{
std::vector<member> memberList =
get_context().get_client_cluster_service().get_member_list();
for (std::vector<member>::const_iterator it = memberList.begin();
it != memberList.end();
for (std::vector<member>::const_iterator it = memberList.cbegin();
it != memberList.cend();
++it) {
submit_to_member<HazelcastSerializable, executor_marker>(command,
*it);
Expand Down
6 changes: 3 additions & 3 deletions hazelcast/include/hazelcast/client/imap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ class HAZELCAST_API imap : public proxy::IMapImpl
resultFutures.push_back(
put_all_internal(partitionId, std::move(partitionEntry.second)));
}
return boost::when_all(resultFutures.begin(), resultFutures.end())
return boost::when_all(resultFutures.cbegin(), resultFutures.cend())
.then(boost::launch::sync,
[](boost::future<boost::csbl::vector<
boost::future<protocol::ClientMessage>>> futures) {
Expand Down Expand Up @@ -1308,8 +1308,8 @@ class HAZELCAST_API imap : public proxy::IMapImpl
query::iteration_type iteration_type,
std::vector<std::pair<K, boost::optional<V>>> entries)
{
std::sort(entries.begin(),
entries.end(),
std::sort(entries.cbegin(),
entries.cend(),
[&](const std::pair<K, boost::optional<V>>& lhs,
const std::pair<K, boost::optional<V>>& rhs) {
auto comparator = predicate.getComparator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ConfigUtils
const std::string& item_name)
{
auto candidate = config_patterns.find(item_name);
if (candidate != config_patterns.end()) {
if (candidate != config_patterns.cend()) {
return &candidate->second;
}
auto size = config_patterns.size();
Expand All @@ -50,7 +50,7 @@ class ConfigUtils
config_pattern_matcher.matches(keys, item_name);
if (configPatternKey) {
candidate = config_patterns.find(*configPatternKey);
if (candidate != config_patterns.end()) {
if (candidate != config_patterns.cend()) {
return &candidate->second;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class BaseHeapNearCacheRecordStore
entries = ANCRS::records_->entry_set();
for (typename std::vector<std::pair<std::shared_ptr<KS>,
std::shared_ptr<R>>>::const_iterator
it = entries.begin();
it != entries.end();
it = entries.cbegin();
it != entries.cend();
++it) {
const std::pair<std::shared_ptr<KS>, std::shared_ptr<R>>& entry =
(*it);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class HeapNearCacheRecordMap
}
int actualEvictedCount = 0;
for (typename std::vector<std::shared_ptr<C>>::const_iterator it =
eviction_candidates->begin();
it != eviction_candidates->end();
eviction_candidates->cbegin();
it != eviction_candidates->cend();
++it) {
const std::shared_ptr<C>& evictionCandidate = *it;
if (util::SynchronizedMap<std::shared_ptr<KS>, R>::remove(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class NearCachedClientMapProxy
std::move(entry.second));
bool marked = false;
auto foundEntry = markers->find(key);
if (foundEntry != markers->end()) {
if (foundEntry != markers->cend()) {
marked = foundEntry->second;
markers->erase(foundEntry);
}
Expand Down Expand Up @@ -601,8 +601,8 @@ class NearCachedClientMapProxy

void unmark_remaining_marked_keys(MARKER_MAP& markers)
{
for (MARKER_MAP::const_iterator it = markers.begin();
it != markers.end();
for (MARKER_MAP::const_iterator it = markers.cbegin();
it != markers.cend();
++it) {
if (it->second) {
key_state_marker_->force_unmark(*it->first);
Expand Down
6 changes: 3 additions & 3 deletions hazelcast/include/hazelcast/client/pipelining.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class pipelining : public std::enable_shared_from_this<pipelining<E>>
{
std::vector<boost::optional<E>> result;
result.reserve(futures_.size());
auto result_futures = when_all(futures_.begin(), futures_.end());
auto result_futures = when_all(futures_.cbegin(), futures_.cend());
for (auto& f : result_futures.get()) {
result.emplace_back(f.get());
}
Expand Down Expand Up @@ -163,8 +163,8 @@ class pipelining : public std::enable_shared_from_this<pipelining<E>>
}

if (!outStandingFutures.empty()) {
boost::when_any(outStandingFutures.begin(),
outStandingFutures.end())
boost::when_any(outStandingFutures.cbegin(),
outStandingFutures.cend())
.get();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ClientMessageBuilder
bool result = false;

auto found = partial_messages_.find(fragmentation_id);
if (partial_messages_.end() != found) {
if (partial_messages_.cend() != found) {
found->second->append(std::move(msg));
if (is_end_fragment) {
// remove from message from map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class HAZELCAST_API SerializingProxy
inline boost::future<std::unordered_map<K, V>> to_object_map(
std::vector<boost::future<EntryVector>>& futures)
{
return boost::when_all(futures.begin(), futures.end())
return boost::when_all(futures.cbegin(), futures.cend())
.then(boost::launch::sync,
[this](
boost::future<boost::csbl::vector<boost::future<EntryVector>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ const std::vector<byte>& data_output::to_byte_array() const

void data_output::append_bytes(const std::vector<byte>& bytes)
{
output_stream_.insert(output_stream_.end(), bytes.begin(), bytes.end());
output_stream_.insert(output_stream_.cend(), bytes.cbegin(), bytes.cend());
}

void data_output::write_zero_bytes(size_t number_of_bytes)
{
output_stream_.insert(output_stream_.end(), number_of_bytes, 0);
output_stream_.insert(output_stream_.cend(), number_of_bytes, 0);
}

size_t data_output::position() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class HAZELCAST_API ClassDefinition
* Internal API
* @param fieldDefinition to be added
*/
void add_field_def(FieldDefinition& field_definition);
void add_field_def(const FieldDefinition& field_definition);

/**
* @param fieldName field name
Expand Down
2 changes: 1 addition & 1 deletion hazelcast/include/hazelcast/client/spi/ProxyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class HAZELCAST_API ProxyManager

std::lock_guard<std::recursive_mutex> guard(lock_);
auto it = proxies_.find(ns);
if (it != proxies_.end()) {
if (it != proxies_.cend()) {
auto proxy_future = it->second;
return convert_to_concrete_proxy_future<T>(proxy_future);
}
Expand Down
2 changes: 1 addition & 1 deletion hazelcast/include/hazelcast/util/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class HAZELCAST_API ByteBuffer
{
size_t numBytesToCopy = std::min<size_t>(lim_ - pos_, len);
target.insert(
target.end(), buffer_ + pos_, buffer_ + pos_ + numBytesToCopy);
target.cend(), buffer_ + pos_, buffer_ + pos_ + numBytesToCopy);
pos_ += numBytesToCopy;
return numBytesToCopy;
}
Expand Down
14 changes: 7 additions & 7 deletions hazelcast/include/hazelcast/util/SynchronizedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SynchronizedMap
bool contains_key(const K& key) const
{
std::lock_guard<std::mutex> guard(map_lock_);
return internal_map_.find(key) != internal_map_.end();
return internal_map_.find(key) != internal_map_.cend();
}

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ class SynchronizedMap
std::lock_guard<std::mutex> lg(map_lock_);
std::shared_ptr<V> returnValue;
auto foundIter = internal_map_.find(key);
if (foundIter != internal_map_.end()) {
if (foundIter != internal_map_.cend()) {
returnValue = foundIter->second;
}
internal_map_[key] = value;
Expand All @@ -107,7 +107,7 @@ class SynchronizedMap
{
std::lock_guard<std::mutex> lg(map_lock_);
auto foundIter = internal_map_.find(key);
if (foundIter != internal_map_.end()) {
if (foundIter != internal_map_.cend()) {
return foundIter->second;
}

Expand All @@ -124,7 +124,7 @@ class SynchronizedMap
{
std::lock_guard<std::mutex> lg(map_lock_);
auto foundIter = internal_map_.find(key);
if (foundIter != internal_map_.end()) {
if (foundIter != internal_map_.cend()) {
std::shared_ptr<V> v = foundIter->second;
internal_map_.erase(foundIter);
return v;
Expand All @@ -137,7 +137,7 @@ class SynchronizedMap
{
std::lock_guard<std::mutex> lg(map_lock_);
auto foundIter = internal_map_.find(key);
if (foundIter != internal_map_.end()) {
if (foundIter != internal_map_.cend()) {
auto& foundValue = foundIter->second;
if (!value || !foundValue) {
if (value == foundValue) {
Expand Down Expand Up @@ -228,7 +228,7 @@ class SynchronizedMap
if (index >= internal_map_.size()) {
return std::unique_ptr<std::pair<K, std::shared_ptr<V>>>();
}
auto it = internal_map_.begin();
auto it = internal_map_.cbegin();
for (size_t i = 0; i < index; ++i) {
++it;
}
Expand All @@ -251,7 +251,7 @@ class SynchronizedMap
{
std::lock_guard<std::mutex> lg(map_lock_);

for (auto iter = internal_map_.begin(); iter != internal_map_.end();) {
for (auto iter = internal_map_.cbegin(); iter != internal_map_.cend();) {
if (iter->second != nullptr && comp(*(iter->second))) {
iter = internal_map_.erase(iter);
} else {
Expand Down
4 changes: 2 additions & 2 deletions hazelcast/include/hazelcast/util/SynchronizedQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class SynchronizedQueue
std::lock_guard<std::mutex> lg(m);
std::vector<std::shared_ptr<T>> values;
for (typename std::deque<std::shared_ptr<T>>::const_iterator it =
internalQueue.begin();
it != internalQueue.end();
internalQueue.cbegin();
it != internalQueue.cend();
++it) {
values.push_back(*it);
}
Expand Down
8 changes: 4 additions & 4 deletions hazelcast/src/hazelcast/client/client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ from_bytes(std::vector<int8_t> v)
if (is_negative) {
twos_complement(v);
}
import_bits(i, v.begin(), v.end(), 8);
import_bits(i, v.cbegin(), v.cend(), 8);
if (is_negative) {
return -i;
}
Expand All @@ -793,12 +793,12 @@ to_bytes(const boost::multiprecision::cpp_int& i)
twos_complement(v);
if (v[0] > 0) {
// add -1 as the most significant to have a negative sign bit
v.insert(v.begin(), -1);
v.insert(v.cbegin(), -1);
}
} else {
// add 0 as the most significant byte to have a positive sign bit
if (v[0] < 0) {
v.insert(v.begin(), 0);
v.insert(v.cbegin(), 0);
}
}
return v;
Expand Down Expand Up @@ -1156,7 +1156,7 @@ client_properties::get_string(const client_property& property) const
{
std::unordered_map<std::string, std::string>::const_iterator valueIt =
properties_map_.find(property.get_name());
if (valueIt != properties_map_.end()) {
if (valueIt != properties_map_.cend()) {
return valueIt->second;
}

Expand Down
4 changes: 2 additions & 2 deletions hazelcast/src/hazelcast/client/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ member::get_attribute(const std::string& key) const
{
std::unordered_map<std::string, std::string>::const_iterator it =
attributes_.find(key);
if (attributes_.end() != it) {
if (attributes_.cend() != it) {
return &(it->second);
} else {
return NULL;
Expand All @@ -145,7 +145,7 @@ member::get_version() const
bool
member::lookup_attribute(const std::string& key) const
{
return attributes_.find(key) != attributes_.end();
return attributes_.find(key) != attributes_.cend();
}

bool
Expand Down
8 changes: 4 additions & 4 deletions hazelcast/src/hazelcast/client/compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,7 @@ compact_reader::is_field_exists(const std::string& field_name,
{
const auto& fields = schema.fields();
const auto& field_descriptor = fields.find(field_name);
if (field_descriptor == fields.end()) {
if (field_descriptor == fields.cend()) {
return false;
}
return field_descriptor->second.kind == kind;
Expand All @@ -2427,7 +2427,7 @@ compact_reader::get_field_descriptor(const std::string& field_name) const
{
const auto& fields = schema.fields();
const auto& field_descriptor = fields.find(field_name);
if (field_descriptor == fields.end()) {
if (field_descriptor == fields.cend()) {
BOOST_THROW_EXCEPTION(unknown_field(field_name));
}
return field_descriptor->second;
Expand Down Expand Up @@ -3249,7 +3249,7 @@ default_compact_writer::check_field_definition(const std::string& field_name,
field_kind kind) const
{
auto iterator = schema_.fields().find(field_name);
if (iterator == schema_.fields().end()) {
if (iterator == schema_.fields().cend()) {
BOOST_THROW_EXCEPTION(exception::hazelcast_serialization(
"default_compact_writer",
(boost::format("Invalid field name %1% for %2%") % field_name %
Expand Down Expand Up @@ -3391,7 +3391,7 @@ schema::schema(
std::vector<field_descriptor*> variable_size_fields;

std::map<std::string, field_descriptor> sorted_fields(
field_definition_map_.begin(), field_definition_map_.end());
field_definition_map_.cbegin(), field_definition_map_.cend());
for (auto& item : sorted_fields) {
field_descriptor& descriptor = item.second;
field_kind kind = descriptor.kind;
Expand Down
10 changes: 5 additions & 5 deletions hazelcast/src/hazelcast/client/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ client_network_config&
client_network_config::add_addresses(const std::vector<address>& addresses)
{
address_list_.insert(
address_list_.end(), addresses.begin(), addresses.end());
address_list_.cend(), addresses.cbegin(), addresses.cend());
return *this;
}

Expand Down Expand Up @@ -1179,7 +1179,7 @@ const config::reliable_topic_config&
client_config::get_reliable_topic_config(const std::string& name)
{
auto it = reliable_topic_config_map_.find(name);
if (it != reliable_topic_config_map_.end()) {
if (it != reliable_topic_config_map_.cend()) {
return it->second;
}

Expand All @@ -1192,7 +1192,7 @@ const config::reliable_topic_config*
client_config::lookup_reliable_topic_config(const std::string& name) const
{
auto it = reliable_topic_config_map_.find(name);
if (it != reliable_topic_config_map_.end()) {
if (it != reliable_topic_config_map_.cend()) {
return &it->second;
}

Expand Down Expand Up @@ -1224,7 +1224,7 @@ client_config::get_near_cache_config(const std::string& name) const
}

auto config_it = near_cache_config_map_.find("default");
if (config_it != near_cache_config_map_.end()) {
if (config_it != near_cache_config_map_.cend()) {
return &near_cache_config_map_.find("default")->second;
}

Expand Down Expand Up @@ -1308,7 +1308,7 @@ client_config::get_flake_id_generator_config(const std::string& name)
return config;
}
auto defConfig = flake_id_generator_config_map_.find("default");
if (defConfig == flake_id_generator_config_map_.end()) {
if (defConfig == flake_id_generator_config_map_.cend()) {
flake_id_generator_config_map_.emplace(
"default", config::client_flake_id_generator_config("default"));
}
Expand Down
Loading
Loading