Cleanup some code with C++14 features

This commit is contained in:
Maxime Coste 2016-03-14 09:56:08 +00:00 committed by Maxime Coste
parent bbaa98c46d
commit 5bf401948a
4 changed files with 15 additions and 13 deletions

View File

@ -12,9 +12,11 @@ namespace Kakoune
template<typename Factory>
struct ContainerView { Factory factory; };
template<typename Factory>
ContainerView<Factory> make_view(Factory factory) { return {factory}; }
template<typename Container, typename Factory>
auto operator| (Container&& container, ContainerView<Factory> view) ->
decltype(view.factory(std::forward<Container>(container)))
decltype(auto) operator| (Container&& container, ContainerView<Factory> view)
{
return view.factory(std::forward<Container>(container));
}
@ -307,32 +309,31 @@ ConcatView<Container1, Container2> concatenated(Container1&& container1, Contain
return {container1, container2};
}
// Todo: move that into the following functions once we can remove the decltype
// return type.
using std::begin;
using std::end;
template<typename Container, typename T>
auto find(Container&& container, const T& value) -> decltype(begin(container))
auto find(Container&& container, const T& value)
{
using std::begin; using std::end;
return std::find(begin(container), end(container), value);
}
template<typename Container, typename T>
auto find_if(Container&& container, T op) -> decltype(begin(container))
auto find_if(Container&& container, T op)
{
using std::begin; using std::end;
return std::find_if(begin(container), end(container), op);
}
template<typename Container, typename T>
bool contains(Container&& container, const T& value)
{
using std::end;
return find(container, value) != end(container);
}
template<typename Container, typename T>
bool contains_that(Container&& container, T op)
{
using std::end;
return find_if(container, op) != end(container);
}

View File

@ -100,7 +100,7 @@ KeyList parse_keys(StringView str)
auto name_it = find_if(keynamemap, [&desc](const KeyAndName& item)
{ return item.name == desc; });
if (name_it != end(keynamemap))
if (name_it != std::end(keynamemap))
result.push_back(canonicalize_ifn({ modifier, name_it->key }));
else if (desc.char_length() == 1)
result.emplace_back(modifier, desc[0_char]);
@ -151,7 +151,7 @@ String key_to_str(Key key)
String res;
auto it = find_if(keynamemap, [&key](const KeyAndName& item)
{ return item.key == key.key; });
if (it != end(keynamemap))
if (it != std::end(keynamemap))
{
named = true;
res = it->name;

View File

@ -108,9 +108,9 @@ template<typename Key, typename Value, MemoryDomain domain>
String option_to_string(const HashMap<Key, Value, domain>& opt)
{
String res;
for (auto it = begin(opt); it != end(opt); ++it)
for (auto it = opt.begin(); it != opt.end(); ++it)
{
if (it != begin(opt))
if (it != opt.begin())
res += list_separator;
String elem = escape(option_to_string(it->key), '=', '\\') + "=" +
escape(option_to_string(it->value), '=', '\\');

View File

@ -365,6 +365,7 @@ find_surrounding(const Container& container, Iterator pos,
StringView opening, StringView closing,
ObjectFlags flags, int init_level)
{
using std::begin; using std::end;
return find_surrounding(begin(container), end(container), pos,
opening, closing, flags, init_level);
}