summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-03-12 15:27:54 +0000
committerMaxime Coste <mawww@kakoune.org>2017-07-19 08:47:14 +0200
commit7a79cbbc811a643ef193de0790609cd7bfea61fc (patch)
tree051748930a03aab4967ee94ebc50d5a3846f5934 /src
parentfbffd86f85445623a6a8981a93d8a9f763d98af7 (diff)
Migrate code to c++14
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/client_manager.cc2
-rw-r--r--src/containers.hh2
-rw-r--r--src/flags.hh6
-rw-r--r--src/hash.hh4
-rw-r--r--src/highlighters.cc26
-rw-r--r--src/main.cc12
-rw-r--r--src/option_manager.hh2
-rw-r--r--src/register_manager.hh4
-rw-r--r--src/string.hh12
-rw-r--r--src/utils.hh6
-rw-r--r--src/value.hh4
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<Window>(buffer), { buffer, Selection{} } };
+ return { std::make_unique<Window>(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<Container>;
struct Iterator : std::iterator<std::forward_iterator_tag,
- typename std::remove_reference<TransformedResult<ContainerIt, Transform>>::type>
+ std::remove_reference_t<TransformedResult<ContainerIt, Transform>>>
{
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<typename Flags>
constexpr bool with_bit_ops(Meta::Type<Flags>) { return false; }
template<typename Flags>
-using UnderlyingType = typename std::underlying_type<Flags>::type;
+using UnderlyingType = std::underlying_type_t<Flags>;
template<typename Flags, typename T = void>
-using EnableIfWithBitOps = typename std::enable_if<with_bit_ops(Meta::Type<Flags>{}), T>::type;
+using EnableIfWithBitOps = std::enable_if_t<with_bit_ops(Meta::Type<Flags>{}), T>;
template<typename Flags, typename T = void>
-using EnableIfWithoutBitOps = typename std::enable_if<not with_bit_ops(Meta::Type<Flags>{}), T>::type;
+using EnableIfWithoutBitOps = std::enable_if_t<not with_bit_ops(Meta::Type<Flags>{}), T>;
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
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 Type>
-typename std::enable_if<std::is_enum<Type>::value, size_t>::type
+std::enable_if_t<std::is_enum<Type>::value, size_t>
hash_value(const Type& val)
{
- return hash_value((typename std::underlying_type<Type>::type)val);
+ return hash_value((std::underlying_type_t<Type>)val);
}
template<typename Type>
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<Highlighter> make_highlighter(Func func, HighlightPass pass = Hi
}
Func m_func;
};
- return make_unique<SimpleHighlighter>(std::move(func), pass);
+ return std::make_unique<SimpleHighlighter>(std::move(func), pass);
}
template<typename T>
@@ -325,8 +325,8 @@ public:
Regex ex{params[0], Regex::optimize};
- return {id, make_unique<RegexHighlighter>(std::move(ex),
- std::move(faces))};
+ return {id, std::make_unique<RegexHighlighter>(std::move(ex),
+ std::move(faces))};
}
private:
@@ -488,7 +488,7 @@ template<typename RegexGetter, typename FaceGetter>
std::unique_ptr<DynamicRegexHighlighter<RegexGetter, FaceGetter>>
make_dynamic_regex_highlighter(RegexGetter regex_getter, FaceGetter face_getter)
{
- return make_unique<DynamicRegexHighlighter<RegexGetter, FaceGetter>>(
+ return std::make_unique<DynamicRegexHighlighter<RegexGetter, FaceGetter>>(
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<WrapHighlighter>(max_width, (bool)parser.get_switch("word"))};
+ return {"wrap", std::make_unique<WrapHighlighter>(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<LineNumbersHighlighter>((bool)parser.get_switch("relative"), (bool)parser.get_switch("hlcursor"), separator.str())};
+ return {"number_lines", std::make_unique<LineNumbersHighlighter>((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<LineAndSpecList>();
- return {"hlflags_" + params[1], make_unique<FlagLinesHighlighter>(option_name, default_face) };
+ return {"hlflags_" + params[1], std::make_unique<FlagLinesHighlighter>(option_name, default_face) };
}
private:
@@ -1412,7 +1412,7 @@ struct RangesHighlighter : Highlighter
// throw if wrong option type
GlobalScope::instance().options()[option_name].get<RangeAndStringList>();
- return {"hlranges_" + params[0], make_unique<RangesHighlighter>(option_name)};
+ return {"hlranges_" + params[0], std::make_unique<RangesHighlighter>(option_name)};
}
private:
@@ -1454,7 +1454,7 @@ struct ReplaceRangesHighlighter : Highlighter
// throw if wrong option type
GlobalScope::instance().options()[option_name].get<RangeAndStringList>();
- return {"replace_ranges_" + params[0], make_unique<ReplaceRangesHighlighter>(option_name)};
+ return {"replace_ranges_" + params[0], std::make_unique<ReplaceRangesHighlighter>(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<HighlighterGroup>(passes));
+ return HighlighterAndId(parser[0], std::make_unique<HighlighterGroup>(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<ReferenceHighlighter>(passes, parser[0])};
+ return {parser[0], std::make_unique<ReferenceHighlighter>(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<RegionsHighlighter>(std::move(regions), default_group)};
+ return {parser[0], std::make_unique<RegionsHighlighter>(std::move(regions), default_group)};
}
private:
@@ -1963,7 +1963,7 @@ private:
void setup_builtin_highlighters(HighlighterGroup& group)
{
- group.add_child({"tabulations"_str, make_unique<TabulationHighlighter>()});
+ group.add_child({"tabulations"_str, std::make_unique<TabulationHighlighter>()});
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<StaticRegister>());
+ register_manager.add_register(c, std::make_unique<StaticRegister>());
using StringList = Vector<String, MemoryDomain::Registers>;
@@ -228,7 +228,7 @@ void register_registers()
}));
}
- register_manager.add_register('_', make_unique<NullRegister>());
+ register_manager.add_register('_', std::make_unique<NullRegister>());
}
static void check_tabstop(const int& val)
@@ -376,9 +376,9 @@ std::unique_ptr<UserInterface> make_ui(UIType ui_type)
switch (ui_type)
{
- case UIType::NCurses: return make_unique<NCursesUI>();
- case UIType::Json: return make_unique<JsonUI>();
- case UIType::Dummy: return make_unique<DummyUI>();
+ case UIType::NCurses: return std::make_unique<NCursesUI>();
+ case UIType::Json: return std::make_unique<JsonUI>();
+ case UIType::Dummy: return std::make_unique<DummyUI>();
}
throw logic_error{};
}
@@ -470,7 +470,7 @@ std::unique_ptr<UserInterface> create_local_ui(UIType ui_type)
create_fifo_buffer("*stdin*", fd, Buffer::Flags::None);
}
- return make_unique<LocalUI>();
+ return std::make_unique<LocalUI>();
}
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<T>{}), docstring);
m_descs.emplace_back(new OptionDesc{name.str(), std::move(doc), flags});
return *opts.insert({m_descs.back()->name(),
- make_unique<TypedCheckedOption<T, validator>>(m_global_manager, *m_descs.back(), value)});
+ std::make_unique<TypedCheckedOption<T, validator>>(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<Register> make_dyn_reg(Func func)
{
throw runtime_error("this register is not assignable");
};
- return make_unique<DynamicRegister<Func, decltype(setter)>>(std::move(func), setter);
+ return std::make_unique<DynamicRegister<Func, decltype(setter)>>(std::move(func), setter);
}
template<typename Getter, typename Setter>
std::unique_ptr<Register> make_dyn_reg(Getter getter, Setter setter)
{
- return make_unique<DynamicRegister<Getter, Setter>>(std::move(getter), std::move(setter));
+ return std::make_unique<DynamicRegister<Getter, Setter>>(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<const Type*>(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<String, char>
@@ -406,12 +408,12 @@ to_string(const StronglyTypedNumber<RealType, ValueType>& val)
namespace detail
{
-template<typename T> using IsString = std::is_convertible<T, StringView>;
+template<typename T> constexpr bool is_string = std::is_convertible<T, StringView>::value;
-template<typename T, class = typename std::enable_if<not IsString<T>::value>::type>
+template<typename T, class = std::enable_if_t<not is_string<T>>>
auto format_param(const T& val) -> decltype(to_string(val)) { return to_string(val); }
-template<typename T, class = typename std::enable_if<IsString<T>::value>::type>
+template<typename T, class = std::enable_if_t<is_string<T>>>
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<typename T, typename... Args>
-std::unique_ptr<T> make_unique(Args&&... args)
-{
- return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-
template<typename T>
bool operator== (const std::unique_ptr<T>& 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<typename T,
- typename = typename std::enable_if<not std::is_same<Value, T>::value>::type>
+ typename = std::enable_if_t<not std::is_same<Value, T>::value>>
Value(T&& val)
- : m_value{new Model<typename std::remove_reference<T>::type>{std::forward<T>(val)}} {}
+ : m_value{new Model<std::remove_reference_t<T>>{std::forward<T>(val)}} {}
Value(const Value& val) = delete;
Value(Value&&) = default;