From 7a79cbbc811a643ef193de0790609cd7bfea61fc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 12 Mar 2016 15:27:54 +0000 Subject: [PATCH] Migrate code to c++14 --- src/Makefile | 2 +- src/client_manager.cc | 2 +- src/containers.hh | 2 +- src/flags.hh | 6 +++--- src/hash.hh | 4 ++-- src/highlighters.cc | 26 +++++++++++++------------- src/main.cc | 12 ++++++------ src/option_manager.hh | 2 +- src/register_manager.hh | 4 ++-- src/string.hh | 12 +++++++----- src/utils.hh | 6 ------ src/value.hh | 4 ++-- 12 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/Makefile b/src/Makefile index 5c0ec05e..c69dad7b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -59,7 +59,7 @@ ifeq ($(static),yes) LDFLAGS += -static -pthread endif -CXXFLAGS += -pedantic -std=gnu++11 -g -Wall -Wextra -Wno-unused-parameter -Wno-reorder -Wno-sign-compare -Wno-address -Wno-noexcept-type -Wno-unknown-attributes -Wno-unknown-warning-option +CXXFLAGS += -pedantic -std=gnu++14 -g -Wall -Wextra -Wno-unused-parameter -Wno-reorder -Wno-sign-compare -Wno-address -Wno-noexcept-type -Wno-unknown-attributes -Wno-unknown-warning-option all : kak diff --git a/src/client_manager.cc b/src/client_manager.cc index bd04b82a..4eeb4f60 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -110,7 +110,7 @@ WindowAndSelections ClientManager::get_free_window(Buffer& buffer) { return &ws.window->buffer() == &buffer; }); if (it == m_free_windows.rend()) - return { make_unique(buffer), { buffer, Selection{} } }; + return { std::make_unique(buffer), { buffer, Selection{} } }; it->window->force_redraw(); WindowAndSelections res = std::move(*it); diff --git a/src/containers.hh b/src/containers.hh index e91f29a0..c4fd379b 100644 --- a/src/containers.hh +++ b/src/containers.hh @@ -129,7 +129,7 @@ struct TransformView using ContainerIt = IteratorOf; struct Iterator : std::iterator>::type> + std::remove_reference_t>> { Iterator(const TransformView& view, ContainerIt it) : m_it{std::move(it)}, m_view{view} {} diff --git a/src/flags.hh b/src/flags.hh index 74a7188f..7b05b5a5 100644 --- a/src/flags.hh +++ b/src/flags.hh @@ -12,13 +12,13 @@ template constexpr bool with_bit_ops(Meta::Type) { return false; } template -using UnderlyingType = typename std::underlying_type::type; +using UnderlyingType = std::underlying_type_t; template -using EnableIfWithBitOps = typename std::enable_if{}), T>::type; +using EnableIfWithBitOps = std::enable_if_t{}), T>; template -using EnableIfWithoutBitOps = typename std::enable_if{}), T>::type; +using EnableIfWithoutBitOps = std::enable_if_t{}), T>; template> constexpr Flags operator|(Flags lhs, Flags rhs) diff --git a/src/hash.hh b/src/hash.hh index ddce1cff..a79bbf3c 100644 --- a/src/hash.hh +++ b/src/hash.hh @@ -19,10 +19,10 @@ size_t hash_value(const Type&... val) } template -typename std::enable_if::value, size_t>::type +std::enable_if_t::value, size_t> hash_value(const Type& val) { - return hash_value((typename std::underlying_type::type)val); + return hash_value((std::underlying_type_t)val); } template diff --git a/src/highlighters.cc b/src/highlighters.cc index 27782911..71d0abb9 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -40,7 +40,7 @@ std::unique_ptr make_highlighter(Func func, HighlightPass pass = Hi } Func m_func; }; - return make_unique(std::move(func), pass); + return std::make_unique(std::move(func), pass); } template @@ -325,8 +325,8 @@ public: Regex ex{params[0], Regex::optimize}; - return {id, make_unique(std::move(ex), - std::move(faces))}; + return {id, std::make_unique(std::move(ex), + std::move(faces))}; } private: @@ -488,7 +488,7 @@ template std::unique_ptr> make_dynamic_regex_highlighter(RegexGetter regex_getter, FaceGetter face_getter) { - return make_unique>( + return std::make_unique>( std::move(regex_getter), std::move(face_getter)); } @@ -858,7 +858,7 @@ struct WrapHighlighter : Highlighter if (auto width = parser.get_switch("width")) max_width = str_to_int(*width); - return {"wrap", make_unique(max_width, (bool)parser.get_switch("word"))}; + return {"wrap", std::make_unique(max_width, (bool)parser.get_switch("word"))}; } const bool m_word_wrap; @@ -1021,7 +1021,7 @@ struct LineNumbersHighlighter : Highlighter if (separator.length() > 10) throw runtime_error("Separator length is limited to 10 bytes"); - return {"number_lines", make_unique((bool)parser.get_switch("relative"), (bool)parser.get_switch("hlcursor"), separator.str())}; + return {"number_lines", std::make_unique((bool)parser.get_switch("relative"), (bool)parser.get_switch("hlcursor"), separator.str())}; } private: @@ -1253,7 +1253,7 @@ struct FlagLinesHighlighter : Highlighter // throw if wrong option type GlobalScope::instance().options()[option_name].get(); - return {"hlflags_" + params[1], make_unique(option_name, default_face) }; + return {"hlflags_" + params[1], std::make_unique(option_name, default_face) }; } private: @@ -1412,7 +1412,7 @@ struct RangesHighlighter : Highlighter // throw if wrong option type GlobalScope::instance().options()[option_name].get(); - return {"hlranges_" + params[0], make_unique(option_name)}; + return {"hlranges_" + params[0], std::make_unique(option_name)}; } private: @@ -1454,7 +1454,7 @@ struct ReplaceRangesHighlighter : Highlighter // throw if wrong option type GlobalScope::instance().options()[option_name].get(); - return {"replace_ranges_" + params[0], make_unique(option_name)}; + return {"replace_ranges_" + params[0], std::make_unique(option_name)}; } private: @@ -1517,7 +1517,7 @@ HighlighterAndId create_highlighter_group(HighlighterParameters params) ParametersParser parser{params, param_desc}; HighlightPass passes = parse_passes(parser.get_switch("passes").value_or("colorize")); - return HighlighterAndId(parser[0], make_unique(passes)); + return HighlighterAndId(parser[0], std::make_unique(passes)); } struct ReferenceHighlighter : Highlighter @@ -1533,7 +1533,7 @@ struct ReferenceHighlighter : Highlighter }; ParametersParser parser{params, param_desc}; HighlightPass passes = parse_passes(parser.get_switch("passes").value_or("colorize")); - return {parser[0], make_unique(passes, parser[0])}; + return {parser[0], std::make_unique(passes, parser[0])}; } private: @@ -1849,7 +1849,7 @@ public: } auto default_group = parser.get_switch("default").value_or(StringView{}).str(); - return {parser[0], make_unique(std::move(regions), default_group)}; + return {parser[0], std::make_unique(std::move(regions), default_group)}; } private: @@ -1963,7 +1963,7 @@ private: void setup_builtin_highlighters(HighlighterGroup& group) { - group.add_child({"tabulations"_str, make_unique()}); + group.add_child({"tabulations"_str, std::make_unique()}); group.add_child({"unprintable"_str, make_highlighter(expand_unprintable)}); group.add_child({"selections"_str, make_highlighter(highlight_selections)}); } diff --git a/src/main.cc b/src/main.cc index 4b5ceade..c2d41dfe 100644 --- a/src/main.cc +++ b/src/main.cc @@ -182,7 +182,7 @@ void register_registers() RegisterManager& register_manager = RegisterManager::instance(); for (auto c : "abcdefghijklmnopqrstuvwxyz/\"|^@:") - register_manager.add_register(c, make_unique()); + register_manager.add_register(c, std::make_unique()); using StringList = Vector; @@ -228,7 +228,7 @@ void register_registers() })); } - register_manager.add_register('_', make_unique()); + register_manager.add_register('_', std::make_unique()); } static void check_tabstop(const int& val) @@ -376,9 +376,9 @@ std::unique_ptr make_ui(UIType ui_type) switch (ui_type) { - case UIType::NCurses: return make_unique(); - case UIType::Json: return make_unique(); - case UIType::Dummy: return make_unique(); + case UIType::NCurses: return std::make_unique(); + case UIType::Json: return std::make_unique(); + case UIType::Dummy: return std::make_unique(); } throw logic_error{}; } @@ -470,7 +470,7 @@ std::unique_ptr create_local_ui(UIType ui_type) create_fifo_buffer("*stdin*", fd, Buffer::Flags::None); } - return make_unique(); + return std::make_unique(); } int run_client(StringView session, StringView client_init, diff --git a/src/option_manager.hh b/src/option_manager.hh index 190fdd9c..08bb0aa6 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -223,7 +223,7 @@ public: : format("[{}] - {}", option_type_name(Meta::Type{}), docstring); m_descs.emplace_back(new OptionDesc{name.str(), std::move(doc), flags}); return *opts.insert({m_descs.back()->name(), - make_unique>(m_global_manager, *m_descs.back(), value)}); + std::make_unique>(m_global_manager, *m_descs.back(), value)}); } const OptionDesc* option_desc(StringView name) const diff --git a/src/register_manager.hh b/src/register_manager.hh index 9ee9d9f8..a2a1e253 100644 --- a/src/register_manager.hh +++ b/src/register_manager.hh @@ -75,13 +75,13 @@ std::unique_ptr make_dyn_reg(Func func) { throw runtime_error("this register is not assignable"); }; - return make_unique>(std::move(func), setter); + return std::make_unique>(std::move(func), setter); } template std::unique_ptr make_dyn_reg(Getter getter, Setter setter) { - return make_unique>(std::move(getter), std::move(setter)); + return std::make_unique>(std::move(getter), std::move(setter)); } class NullRegister : public Register diff --git a/src/string.hh b/src/string.hh index 70a95374..606a9986 100644 --- a/src/string.hh +++ b/src/string.hh @@ -93,10 +93,12 @@ private: const Type& type() const { return *static_cast(this); } }; -[[gnu::optimize(3)]] // this is recursive for constexpr reason constexpr ByteCount strlen(const char* s) { - return *s == 0 ? 0 : strlen(s+1) + 1; + int i = 0; + while (*s++ != 0) + ++i; + return {i}; } class String : public StringOps @@ -406,12 +408,12 @@ to_string(const StronglyTypedNumber& val) namespace detail { -template using IsString = std::is_convertible; +template constexpr bool is_string = std::is_convertible::value; -template::value>::type> +template>> auto format_param(const T& val) -> decltype(to_string(val)) { return to_string(val); } -template::value>::type> +template>> StringView format_param(const T& val) { return val; } } diff --git a/src/utils.hh b/src/utils.hh index 06df21a1..9eced1c2 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -113,12 +113,6 @@ private: // *** Misc helper functions *** -template -std::unique_ptr make_unique(Args&&... args) -{ - return std::unique_ptr(new T(std::forward(args)...)); -} - template bool operator== (const std::unique_ptr& lhs, T* rhs) { diff --git a/src/value.hh b/src/value.hh index df952434..1e39ac65 100644 --- a/src/value.hh +++ b/src/value.hh @@ -17,9 +17,9 @@ struct Value Value() = default; template::value>::type> + typename = std::enable_if_t::value>> Value(T&& val) - : m_value{new Model::type>{std::forward(val)}} {} + : m_value{new Model>{std::forward(val)}} {} Value(const Value& val) = delete; Value(Value&&) = default;