From f133dd396cd56d152bc18601cd1a58bb2cc1769d Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 26 Feb 2019 12:01:44 +0400 Subject: [PATCH] Return pair from flat_set::emplace. --- Telegram/SourceFiles/base/flat_set.h | 24 ++++++++++--------- Telegram/SourceFiles/data/data_messages.cpp | 3 ++- .../storage/storage_sparse_ids_list.cpp | 3 ++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/base/flat_set.h b/Telegram/SourceFiles/base/flat_set.h index 2edaa9d3cf..b72814c2e9 100644 --- a/Telegram/SourceFiles/base/flat_set.h +++ b/Telegram/SourceFiles/base/flat_set.h @@ -602,36 +602,38 @@ public: using parent::contains; using parent::erase; - iterator insert(const Type &value) { + std::pair insert(const Type &value) { if (this->empty() || this->compare()(value, this->front())) { this->impl().push_front(value); - return this->begin(); + return std::make_pair(this->begin(), true); } else if (this->compare()(this->back(), value)) { this->impl().push_back(value); - return (this->end() - 1); + return std::make_pair(this->end() - 1, true); } auto where = this->getLowerBound(value); if (this->compare()(value, *where)) { - return this->impl().insert(where, value); + return std::make_pair(this->impl().insert(where, value), true); } - return this->end(); + return std::make_pair(where, false); } - iterator insert(Type &&value) { + std::pair insert(Type &&value) { if (this->empty() || this->compare()(value, this->front())) { this->impl().push_front(std::move(value)); - return this->begin(); + return std::make_pair(this->begin(), true); } else if (this->compare()(this->back(), value)) { this->impl().push_back(std::move(value)); - return (this->end() - 1); + return std::make_pair(this->end() - 1, true); } auto where = this->getLowerBound(value); if (this->compare()(value, *where)) { - return this->impl().insert(where, std::move(value)); + return std::make_pair( + this->impl().insert(where, std::move(value)), + true); } - return this->end(); + return std::make_pair(where, false); } template - iterator emplace(Args&&... args) { + std::pair emplace(Args&&... args) { return this->insert(Type(std::forward(args)...)); } diff --git a/Telegram/SourceFiles/data/data_messages.cpp b/Telegram/SourceFiles/data/data_messages.cpp index e8837a7317..4ace5265cc 100644 --- a/Telegram/SourceFiles/data/data_messages.cpp +++ b/Telegram/SourceFiles/data/data_messages.cpp @@ -83,7 +83,8 @@ int MessagesList::addRangeItemsAndCountNew( std::end(messages) }; auto slice = _slices.emplace( std::move(sliceMessages), - noSkipRange); + noSkipRange + ).first; update.messages = &slice->messages; update.range = slice->range; return slice->messages.size(); diff --git a/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp b/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp index b8bd2b7ed4..dce3846e50 100644 --- a/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp +++ b/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp @@ -84,7 +84,8 @@ SparseIdsList::AddResult SparseIdsList::addRangeItemsAndCountNew( std::end(messages) }; auto slice = _slices.emplace( std::move(sliceMessages), - noSkipRange); + noSkipRange + ).first; update.messages = &slice->messages; update.range = slice->range; const auto count = int(slice->messages.size());