From 49c52b025f2cb5bd66f729f873d2e690b613fb39 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 25 Mar 2018 16:47:19 +1100 Subject: [PATCH] Remove contains_that and use any_of to be closer to the c++ stdlib --- src/buffer_manager.cc | 6 ++---- src/client_manager.cc | 2 +- src/insert_completer.cc | 3 +-- src/main.cc | 4 ++-- src/normal.cc | 4 ++-- src/ranges.hh | 7 ------- src/shell_manager.cc | 6 +++--- 7 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index b0c01cff..f9030b0a 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -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& 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& 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(); diff --git a/src/client_manager.cc b/src/client_manager.cc index 6d4ef641..8fe19ece 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -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) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 8db65556..fbc463f4 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -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) diff --git a/src/main.cc b/src/main.cc index c9ea0d5b..b7c62aec 100644 --- a/src/main.cc +++ b/src/main.cc @@ -280,7 +280,7 @@ static void check_timeout(const int& timeout) static void check_extra_word_chars(const Vector& 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& { 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"}; } diff --git a/src/normal.cc b/src/normal.cc index 1845c708..78c4d4df 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -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>(); @@ -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; diff --git a/src/ranges.hh b/src/ranges.hh index a762dd2f..a8dc4487 100644 --- a/src/ranges.hh +++ b/src/ranges.hh @@ -331,13 +331,6 @@ bool contains(Range&& range, const T& value) return find(range, value) != end(range); } -template -bool contains_that(Range&& range, T op) -{ - using std::end; - return find_if(range, op) != end(range); -} - template bool all_of(Range&& range, T op) { diff --git a/src/shell_manager.cc b/src/shell_manager.cc index c0ae5b10..11d2b0cc 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -126,10 +126,10 @@ Vector 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);