1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-28 17:13:00 +03:00

Remove contains_that and use any_of to be closer to the c++ stdlib

This commit is contained in:
Maxime Coste 2018-03-25 16:47:19 +11:00
parent 435b5b7ff9
commit 49c52b025f
7 changed files with 11 additions and 21 deletions

View File

@ -49,8 +49,7 @@ Buffer* BufferManager::create_buffer(String name, Buffer::Flags flags,
void BufferManager::delete_buffer(Buffer& buffer)
{
auto it = find_if(m_buffers, [&](const std::unique_ptr<Buffer>& p)
{ return p.get() == &buffer; });
auto it = find_if(m_buffers, [&](auto& p) { return p.get() == &buffer; });
kak_assert(it != m_buffers.end());
m_buffer_trash.emplace_back(std::move(*it));
@ -84,8 +83,7 @@ Buffer& BufferManager::get_buffer(StringView name)
Buffer& BufferManager::get_first_buffer()
{
if (not contains_that(m_buffers, [](const std::unique_ptr<Buffer>& p)
{ return not (p->flags() & Buffer::Flags::Debug); }))
if (all_of(m_buffers, [](auto& b) { return (b->flags() & Buffer::Flags::Debug); }))
create_buffer("*scratch*", Buffer::Flags::None);
return *m_buffers.front();

View File

@ -93,7 +93,7 @@ void ClientManager::process_pending_inputs() const
bool ClientManager::has_pending_inputs() const
{
return contains_that(m_clients, [](auto&& c) { return c->has_pending_inputs(); });
return any_of(m_clients, [](auto&& c) { return c->has_pending_inputs(); });
}
void ClientManager::remove_client(Client& client, bool graceful, int status)

View File

@ -294,8 +294,7 @@ InsertCompletion complete_option(const SelectionList& sels,
}
size_t timestamp = (size_t)str_to_int({match[4].first, match[4].second});
auto changes = buffer.changes_since(timestamp);
if (contains_that(changes, [&](const Buffer::Change& change)
{ return change.begin < coord; }))
if (any_of(changes, [&](auto&& change) { return change.begin < coord; }))
return {};
if (cursor_pos.line == coord.line and cursor_pos.column >= coord.column)

View File

@ -280,7 +280,7 @@ static void check_timeout(const int& timeout)
static void check_extra_word_chars(const Vector<Codepoint, MemoryDomain::Options>& extra_chars)
{
if (contains_that(extra_chars, is_blank))
if (any_of(extra_chars, is_blank))
throw runtime_error{"blanks are not accepted for extra completion characters"};
}
@ -288,7 +288,7 @@ static void check_matching_pairs(const Vector<Codepoint, MemoryDomain::Options>&
{
if ((pairs.size() % 2) != 0)
throw runtime_error{"matching pairs should have a pair number of element"};
if (contains_that(pairs, [](Codepoint c) { return not is_punctuation(c); }))
if (not all_of(pairs, is_punctuation))
throw runtime_error{"matching pairs can only be punctuation"};
}

View File

@ -274,7 +274,7 @@ void goto_commands(Context& context, NormalParams params)
{
auto filename = content(buffer, context.selections().main());
static constexpr char forbidden[] = { '\'', '\\', '\0' };
if (contains_that(filename, [](char c){ return contains(forbidden, c); }))
if (any_of(filename, [](char c){ return contains(forbidden, c); }))
return;
auto paths = context.options()["path"].get<Vector<String, MemoryDomain::Options>>();
@ -670,7 +670,7 @@ void paste(Context& context, NormalParams params)
{
const char reg = params.reg ? params.reg : '"';
auto strings = RegisterManager::instance()[reg].get(context);
const bool linewise = contains_that(strings, [](StringView str) {
const bool linewise = any_of(strings, [](StringView str) {
return not str.empty() and str.back() == '\n';
});
const auto effective_mode = linewise ? adapt_for_linewise(mode) : mode;

View File

@ -331,13 +331,6 @@ bool contains(Range&& range, const T& value)
return find(range, value) != end(range);
}
template<typename Range, typename T>
bool contains_that(Range&& range, T op)
{
using std::end;
return find_if(range, op) != end(range);
}
template<typename Range, typename T>
bool all_of(Range&& range, T op)
{

View File

@ -126,10 +126,10 @@ Vector<String> generate_env(StringView cmdline, const Context& context, const Sh
StringView name{(*it)[1].first, (*it)[1].second};
auto match_name = [&](const String& s) {
return s.length() > name.length() and
prefix_match(s, name) and s[name.length()] == '=';
return s.substr(0_byte, name.length()) == name and
s.substr(name.length(), 1_byte) == "=";
};
if (contains_that(kak_env, match_name))
if (any_of(kak_env, match_name))
continue;
auto var_it = shell_context.env_vars.find(name);