Return pair<iterator,bool> from flat_set::emplace.

This commit is contained in:
John Preston 2019-02-26 12:01:44 +04:00
parent ccd04b98b9
commit f133dd396c
3 changed files with 17 additions and 13 deletions

View File

@ -602,36 +602,38 @@ public:
using parent::contains;
using parent::erase;
iterator insert(const Type &value) {
std::pair<iterator, bool> 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<iterator, bool> 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 <typename... Args>
iterator emplace(Args&&... args) {
std::pair<iterator, bool> emplace(Args&&... args) {
return this->insert(Type(std::forward<Args>(args)...));
}

View File

@ -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();

View File

@ -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());