Add and use td::any_of.
This commit is contained in:
parent
687c6c40c2
commit
605a3af4b2
@ -996,8 +996,7 @@ void SessionConnection::flush_packet() {
|
|||||||
auto to_ack = cut_tail(to_ack_message_ids_, 8192, "ack");
|
auto to_ack = cut_tail(to_ack_message_ids_, 8192, "ack");
|
||||||
MessageId ping_message_id;
|
MessageId ping_message_id;
|
||||||
|
|
||||||
bool use_quick_ack =
|
bool use_quick_ack = any_of(queries, [](const auto &query) { return query.use_quick_ack; });
|
||||||
std::any_of(queries.begin(), queries.end(), [](const auto &query) { return query.use_quick_ack; });
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// LOG(ERROR) << (auth_data_->get_header().empty() ? '-' : '+');
|
// LOG(ERROR) << (auth_data_->get_header().empty() ? '-' : '+');
|
||||||
|
@ -9311,8 +9311,7 @@ void ContactsManager::get_created_public_dialogs(PublicDialogType type,
|
|||||||
}
|
}
|
||||||
return channel_id;
|
return channel_id;
|
||||||
});
|
});
|
||||||
if (std::any_of(r_channel_ids.begin(), r_channel_ids.end(),
|
if (any_of(r_channel_ids, [](const auto &r_channel_id) { return r_channel_id.is_error(); })) {
|
||||||
[](auto &r_channel_id) { return r_channel_id.is_error(); })) {
|
|
||||||
LOG(ERROR) << "Can't parse " << str;
|
LOG(ERROR) << "Can't parse " << str;
|
||||||
G()->td_db()->get_binlog_pmc()->erase(pmc_key);
|
G()->td_db()->get_binlog_pmc()->erase(pmc_key);
|
||||||
} else {
|
} else {
|
||||||
|
@ -13553,8 +13553,7 @@ void MessagesManager::init() {
|
|||||||
}
|
}
|
||||||
return dialog_id;
|
return dialog_id;
|
||||||
});
|
});
|
||||||
if (std::any_of(r_dialog_ids.begin(), r_dialog_ids.end(),
|
if (any_of(r_dialog_ids, [](const auto &r_dialog_id) { return r_dialog_id.is_error(); })) {
|
||||||
[](auto &r_dialog_id) { return r_dialog_id.is_error(); })) {
|
|
||||||
LOG(ERROR) << "Can't parse " << it.second;
|
LOG(ERROR) << "Can't parse " << it.second;
|
||||||
reload_pinned_dialogs(DialogListId(folder_id), Auto());
|
reload_pinned_dialogs(DialogListId(folder_id), Auto());
|
||||||
} else {
|
} else {
|
||||||
@ -13617,8 +13616,7 @@ void MessagesManager::init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto counts = transform(full_split(Slice(it.second)), [](Slice str) { return to_integer_safe<int32>(str); });
|
auto counts = transform(full_split(Slice(it.second)), [](Slice str) { return to_integer_safe<int32>(str); });
|
||||||
if ((counts.size() != 4 && counts.size() != 6) ||
|
if ((counts.size() != 4 && counts.size() != 6) || any_of(counts, [](const auto &c) { return c.is_error(); })) {
|
||||||
std::any_of(counts.begin(), counts.end(), [](auto &c) { return c.is_error(); })) {
|
|
||||||
LOG(ERROR) << "Can't parse " << it.second;
|
LOG(ERROR) << "Can't parse " << it.second;
|
||||||
} else {
|
} else {
|
||||||
DialogListId dialog_list_id(r_dialog_list_id.ok());
|
DialogListId dialog_list_id(r_dialog_list_id.ok());
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
#include "td/utils/Time.h"
|
#include "td/utils/Time.h"
|
||||||
#include "td/utils/tl_helpers.h"
|
#include "td/utils/tl_helpers.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -2691,8 +2690,7 @@ bool StoryManager::has_suggested_reaction(const Story *story, const ReactionType
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CHECK(story != nullptr);
|
CHECK(story != nullptr);
|
||||||
return std::any_of(story->areas_.begin(), story->areas_.end(),
|
return any_of(story->areas_, [&reaction_type](const auto &area) { return area.has_reaction_type(reaction_type); });
|
||||||
[&reaction_type](const MediaArea &area) { return area.has_reaction_type(reaction_type); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StoryManager::can_use_story_reaction(const Story *story, const ReactionType &reaction_type) const {
|
bool StoryManager::can_use_story_reaction(const Story *story, const ReactionType &reaction_type) const {
|
||||||
@ -4664,8 +4662,7 @@ void StoryManager::get_dialogs_to_send_stories(Promise<td_api::object_ptr<td_api
|
|||||||
}
|
}
|
||||||
return channel_id;
|
return channel_id;
|
||||||
});
|
});
|
||||||
if (std::any_of(r_channel_ids.begin(), r_channel_ids.end(),
|
if (any_of(r_channel_ids, [](const auto &r_channel_id) { return r_channel_id.is_error(); })) {
|
||||||
[](auto &r_channel_id) { return r_channel_id.is_error(); })) {
|
|
||||||
LOG(ERROR) << "Can't parse " << str;
|
LOG(ERROR) << "Can't parse " << str;
|
||||||
G()->td_db()->get_binlog_pmc()->erase(pmc_key);
|
G()->td_db()->get_binlog_pmc()->erase(pmc_key);
|
||||||
} else {
|
} else {
|
||||||
|
@ -110,7 +110,7 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
|
|||||||
if (!static_options.empty()) {
|
if (!static_options.empty()) {
|
||||||
options = std::move(static_options);
|
options = std::move(static_options);
|
||||||
} else {
|
} else {
|
||||||
bool have_ipv4 = std::any_of(options.begin(), options.end(), [](auto &v) { return !v.option->is_ipv6(); });
|
bool have_ipv4 = td::any_of(options, [](const auto &v) { return !v.option->is_ipv6(); });
|
||||||
if (have_ipv4) {
|
if (have_ipv4) {
|
||||||
td::remove_if(options, [](auto &v) { return v.option->is_ipv6(); });
|
td::remove_if(options, [](auto &v) { return v.option->is_ipv6(); });
|
||||||
}
|
}
|
||||||
@ -122,13 +122,13 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (prefer_ipv6) {
|
if (prefer_ipv6) {
|
||||||
bool have_ipv6 = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_ipv6(); });
|
bool have_ipv6 = td::any_of(options, [](const auto &v) { return v.option->is_ipv6(); });
|
||||||
if (have_ipv6) {
|
if (have_ipv6) {
|
||||||
td::remove_if(options, [](auto &v) { return !v.option->is_ipv6(); });
|
td::remove_if(options, [](auto &v) { return !v.option->is_ipv6(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool have_media_only = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_media_only(); });
|
bool have_media_only = td::any_of(options, [](const auto &v) { return v.option->is_media_only(); });
|
||||||
if (have_media_only) {
|
if (have_media_only) {
|
||||||
td::remove_if(options, [](auto &v) { return !v.option->is_media_only(); });
|
td::remove_if(options, [](auto &v) { return !v.option->is_media_only(); });
|
||||||
}
|
}
|
||||||
|
@ -166,6 +166,16 @@ bool contains(const V &v, const T &value) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class V, class F>
|
||||||
|
bool any_of(const V &v, F &&f) {
|
||||||
|
for (const auto &x : v) {
|
||||||
|
if (f(x)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
template <class V, class F>
|
template <class V, class F>
|
||||||
bool all_of(const V &v, F &&f) {
|
bool all_of(const V &v, F &&f) {
|
||||||
for (const auto &x : v) {
|
for (const auto &x : v) {
|
||||||
|
@ -151,7 +151,7 @@ TEST(ChainScheduler, Stress) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto check_parents_ok = [&](const QueryWithParents &query_with_parents) -> bool {
|
auto check_parents_ok = [&](const QueryWithParents &query_with_parents) -> bool {
|
||||||
return td::all_of(query_with_parents.parents, [](auto &parent) { return parent->is_ok; });
|
return td::all_of(query_with_parents.parents, [](const auto &parent) { return parent->is_ok; });
|
||||||
};
|
};
|
||||||
|
|
||||||
auto to_query_ptr = [&](TaskId task_id) {
|
auto to_query_ptr = [&](TaskId task_id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user