diff --git a/src/command_manager.cc b/src/command_manager.cc index 45200e11..ac6ef56a 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -538,10 +538,10 @@ Completions CommandManager::complete_command_name(const Context& context, String { auto commands = m_commands | filter([](const CommandMap::Item& cmd) { return not (cmd.value.flags & CommandFlags::Hidden); }) - | transform(std::mem_fn(&CommandMap::Item::key)); + | transform(&CommandMap::Item::key); auto aliases = context.aliases().flatten_aliases() - | transform(std::mem_fn(&HashItem::key)) + | transform(&HashItem::key) | filter([](auto& alias) { return alias.length() > 3; }); return {0, query.length(), Kakoune::complete(query, query.length(), concatenated(commands, aliases))}; diff --git a/src/commands.cc b/src/commands.cc index 8eb5acbb..b6ba6b36 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -669,7 +669,7 @@ Completions highlighter_cmd_completer( else if (add and token_to_complete == 1) { StringView name = params[1]; - return { 0_byte, name.length(), complete(name, pos_in_token, HighlighterRegistry::instance() | transform(std::mem_fn(&HighlighterRegistry::Item::key))) }; + return { 0_byte, name.length(), complete(name, pos_in_token, HighlighterRegistry::instance() | transform(&HighlighterRegistry::Item::key)) }; } else return {}; @@ -1593,7 +1593,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) if (*bufnames == "*") { for (auto&& buffer : BufferManager::instance() - | transform(std::mem_fn(&std::unique_ptr::get)) + | transform(&std::unique_ptr::get) | filter([](Buffer* buf) { return not (buf->flags() & Buffer::Flags::Debug); }) | gather>>()) // gather as we might be mutating the buffer list in the loop. context_wrap_for_buffer(*buffer); diff --git a/src/face_registry.cc b/src/face_registry.cc index 4ee2f557..cfae6cb8 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -123,7 +123,7 @@ CandidateList FaceRegistry::complete_alias_name(StringView prefix, ByteCount cursor_pos) const { return complete(prefix, cursor_pos, - m_aliases | transform(std::mem_fn(&AliasMap::Item::key))); + m_aliases | transform(&AliasMap::Item::key)); } FaceRegistry::FaceRegistry() diff --git a/src/highlighters.cc b/src/highlighters.cc index 864c7449..315dda5a 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1869,7 +1869,7 @@ public: return offset_pos(hl.complete_child(path.substr(offset), cursor_pos - offset, group), offset); } - auto container = m_groups | transform(std::mem_fn(&decltype(m_groups)::Item::key)); + auto container = m_groups | transform(&decltype(m_groups)::Item::key); return { 0, 0, complete(path, cursor_pos, container) }; } diff --git a/src/main.cc b/src/main.cc index a92bc0d5..2dc794be 100644 --- a/src/main.cc +++ b/src/main.cc @@ -90,7 +90,7 @@ static const EnvVarDesc builtin_env_vars[] = { { "buflist", false, [](StringView name, const Context& context) { return join(BufferManager::instance() | - transform(std::mem_fn(&Buffer::display_name)), ':'); } + transform(&Buffer::display_name), ':'); } }, { "buf_line_count", false, [](StringView name, const Context& context) -> String diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 91ccdc41..1e1cd822 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -731,7 +731,7 @@ void NCursesUI::menu_show(ConstArrayView items, const int item_count = items.size(); m_menu.items.clear(); // make sure it is empty m_menu.items.reserve(item_count); - const auto longest = accumulate(items | transform(std::mem_fn(&DisplayLine::length)), + const auto longest = accumulate(items | transform(&DisplayLine::length), 1_col, [](auto&& lhs, auto&& rhs) { return std::max(lhs, rhs); }); const bool is_prompt = style == MenuStyle::Prompt; @@ -945,7 +945,7 @@ void NCursesUI::info_show(StringView title, StringView content, } const DisplayCoord size{(int)info_box.size(), - accumulate(info_box | transform(std::mem_fn(&String::column_length)), 0_col, + accumulate(info_box | transform(&String::column_length), 0_col, [](auto&& lhs, auto&& rhs){ return std::max(lhs, rhs); })}; const Rect rect = {m_status_on_top ? 1_line : 0_line, m_dimensions}; DisplayCoord pos; diff --git a/src/normal.cc b/src/normal.cc index aef3f79a..05a5246e 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1200,7 +1200,7 @@ void select_object(Context& context, NormalParams params) { 'n', select_number }, { 'u', select_argument }, }; - auto obj_it = find(selectors | transform(std::mem_fn(&ObjectType::key)), key).base(); + auto obj_it = find(selectors | transform(&ObjectType::key), key).base(); if (obj_it != std::end(selectors)) return select_and_set_last( context, std::bind(obj_it->func, _1, _2, count, flags)); diff --git a/src/option_manager.cc b/src/option_manager.cc index dfcafc5c..efbcf1db 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -109,7 +109,7 @@ CandidateList OptionsRegistry::complete_option_name(StringView prefix, return complete(prefix, cursor_pos, m_descs | filter([](const OptionPtr& desc) { return not (desc->flags() & OptionFlags::Hidden); }) | - transform(std::mem_fn(&OptionDesc::name))); + transform(&OptionDesc::name)); } } diff --git a/src/option_manager.hh b/src/option_manager.hh index 05b9641f..674cf6da 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -100,7 +100,7 @@ public: static const OptionMap empty; auto& parent = m_parent ? m_parent->m_options : empty; auto& grand_parent = (m_parent and m_parent->m_parent) ? m_parent->m_parent->m_options : empty; - return merge(merge(grand_parent, parent), m_options) | transform(std::mem_fn(&OptionMap::Item::value)); + return merge(merge(grand_parent, parent), m_options) | transform(&OptionMap::Item::value); } void register_watcher(OptionManagerWatcher& watcher) const; diff --git a/src/option_types.hh b/src/option_types.hh index 1e736436..aae25dde 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -30,7 +30,7 @@ option_type_name(Meta::Type) { return format("{}({})", with_bit_ops(Meta::Type{}) ? "flags" : "enum", join(enum_desc(Meta::Type{}) | - transform(std::mem_fn(&EnumDesc::name)), '|')); + transform(&EnumDesc::name), '|')); } inline String option_to_string(int opt) { return to_string(opt); } diff --git a/src/ranges.hh b/src/ranges.hh index d39715c0..58f14db4 100644 --- a/src/ranges.hh +++ b/src/ranges.hh @@ -5,6 +5,7 @@ #include #include #include +#include #include "constexpr_utils.hh" @@ -161,6 +162,12 @@ inline auto transform(Transform t) }); } +template +inline auto transform(M T::*m) +{ + return transform(std::mem_fn(std::forward(m))); +} + template, typename ValueTypeParam = void> diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 97103fc1..c0ae5b10 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -310,7 +310,7 @@ CandidateList ShellManager::complete_env_var(StringView prefix, ByteCount cursor_pos) const { return complete(prefix, cursor_pos, - m_env_vars | transform(std::mem_fn(&EnvVarDesc::str))); + m_env_vars | transform(&EnvVarDesc::str)); } }