From 5bf401948a99e26b8113d59e3d1da5032d661f08 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 14 Mar 2016 09:56:08 +0000 Subject: [PATCH] Cleanup some code with C++14 features --- src/containers.hh | 19 ++++++++++--------- src/keys.cc | 4 ++-- src/option_types.hh | 4 ++-- src/selectors.cc | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/containers.hh b/src/containers.hh index c4fd379b..18098289 100644 --- a/src/containers.hh +++ b/src/containers.hh @@ -12,9 +12,11 @@ namespace Kakoune template struct ContainerView { Factory factory; }; +template +ContainerView make_view(Factory factory) { return {factory}; } + template -auto operator| (Container&& container, ContainerView view) -> - decltype(view.factory(std::forward(container))) +decltype(auto) operator| (Container&& container, ContainerView view) { return view.factory(std::forward(container)); } @@ -307,32 +309,31 @@ ConcatView 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 -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 -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 bool contains(Container&& container, const T& value) { + using std::end; return find(container, value) != end(container); } template bool contains_that(Container&& container, T op) { + using std::end; return find_if(container, op) != end(container); } diff --git a/src/keys.cc b/src/keys.cc index 1a1f1c06..3b2c7100 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -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; diff --git a/src/option_types.hh b/src/option_types.hh index ac1a5270..53b10ab6 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -108,9 +108,9 @@ template String option_to_string(const HashMap& 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), '=', '\\'); diff --git a/src/selectors.cc b/src/selectors.cc index 597619f8..417294ed 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -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); }