Convert some uses of lambda to more concise std::mem_fn

This commit is contained in:
Maxime Coste 2016-10-10 23:44:18 +01:00
parent bc9d1b4dac
commit 025b91baca
8 changed files with 13 additions and 16 deletions

View File

@ -57,7 +57,7 @@ Vector<std::pair<StringView, StringView>> AliasRegistry::flatten_aliases() const
res = m_parent->flatten_aliases();
for (auto& alias : m_aliases)
{
if (not contains(res | transform([](const AliasDesc& val) { return val.first; }), alias.key))
if (not contains(res | transform(std::mem_fn(&AliasDesc::first)), alias.key))
res.emplace_back(alias.key, alias.value);
}
return res;

View File

@ -54,7 +54,6 @@ void BufferManager::delete_buffer(Buffer& buffer)
{ return p.get() == &buffer; });
kak_assert(it != m_buffers.end());
ClientManager::instance().ensure_no_client_uses_buffer(buffer);
m_buffer_trash.emplace_back(std::move(*it));

View File

@ -531,16 +531,15 @@ Completions CommandManager::complete_command_name(const Context& context,
{
auto commands = m_commands
| filter([](const CommandMap::value_type& cmd) { return not (cmd.second.flags & CommandFlags::Hidden); })
| transform([](const CommandMap::value_type& cmd) { return StringView{cmd.first}; });
| transform(std::mem_fn(&CommandMap::value_type::first));
if (not with_aliases)
return {0, query.length(), Kakoune::complete(query, query.length(), commands)};
auto candidates = Kakoune::complete(query, query.length(),
concatenated(commands,
context.aliases().flatten_aliases()
| transform([](AliasRegistry::AliasDesc alias)
{ return alias.first; })));
context.aliases().flatten_aliases() |
transform(std::mem_fn(&AliasRegistry::AliasDesc::first))));
return {0, query.length(), std::move(candidates)};
}

View File

@ -25,6 +25,8 @@
#include "string.hh"
#include "window.hh"
#include <functional>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -1508,8 +1510,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
// copy buffer list as we might be mutating the buffer list
// in the loop.
auto ptrs = BufferManager::instance() |
transform([](const std::unique_ptr<Buffer>& ptr)
{ return ptr.get(); });
transform(std::mem_fn(&std::unique_ptr<Buffer>::get));
Vector<SafePtr<Buffer>> buffers{ptrs.begin(), ptrs.end()};
for (auto buffer : buffers)
context_wrap_for_buffer(*buffer);

View File

@ -254,7 +254,7 @@ struct ConcatView
{
using ContainerIt1 = decltype(begin(std::declval<Container1>()));
using ContainerIt2 = decltype(begin(std::declval<Container2>()));
using ValueType = typename ContainerIt1::value_type;
using ValueType = typename std::common_type<typename ContainerIt1::value_type, typename ContainerIt2::value_type>::type;
struct Iterator : std::iterator<std::forward_iterator_tag, ValueType>
{
@ -265,7 +265,7 @@ struct ConcatView
: m_it1(std::move(it1)), m_end1(std::move(end1)),
m_it2(std::move(it2)) {}
decltype(*std::declval<ContainerIt1>()) operator*() { return is2() ? *m_it2 : *m_it1; }
ValueType operator*() { return is2() ? *m_it2 : *m_it1; }
Iterator& operator++() { if (is2()) ++m_it2; else ++m_it1; return *this; }
Iterator operator++(int) { auto copy = *this; ++*this; return copy; }

View File

@ -95,8 +95,7 @@ CandidateList FaceRegistry::complete_alias_name(StringView prefix,
ByteCount cursor_pos) const
{
return complete(prefix, cursor_pos,
m_aliases | transform([](const AliasMap::value_type& v) -> const String&
{ return v.first; }));
m_aliases | transform(std::mem_fn(&AliasMap::value_type::first)));
}
FaceRegistry::FaceRegistry()

View File

@ -32,7 +32,7 @@ struct option_type_name<Enum, typename std::enable_if<std::is_enum<Enum>::value>
{
constexpr StringView type = WithBitOps<Enum>::value ? "flags" : "enum";
auto name = enum_desc(Enum{});
return type + "(" + join(name | transform([](const EnumDesc<Enum>& d) { return d.name; }), '|') + ")";
return type + "(" + join(name | transform(std::mem_fn(&EnumDesc<Enum>::name)), '|') + ")";
}
};

View File

@ -235,9 +235,8 @@ String ShellManager::get_val(StringView name, const Context& context) const
CandidateList ShellManager::complete_env_var(StringView prefix,
ByteCount cursor_pos) const
{
return complete(prefix, cursor_pos, m_env_vars |
transform([](const EnvVarDesc& desc) -> const String&
{ return desc.str; }));
return complete(prefix, cursor_pos,
m_env_vars | transform(std::mem_fn(&EnvVarDesc::str)));
}
}