Retreat ! go back to C++11 only code

This reverts commit b42de85031.
This commit is contained in:
Maxime Coste 2015-05-26 18:42:09 +01:00
parent 499bde10bd
commit 993e842fdf
11 changed files with 55 additions and 23 deletions

View File

@ -9,7 +9,7 @@ bindir := $(DESTDIR)$(PREFIX)/bin
sharedir := $(DESTDIR)$(PREFIX)/share/kak sharedir := $(DESTDIR)$(PREFIX)/share/kak
docdir := $(DESTDIR)$(PREFIX)/share/doc/kak docdir := $(DESTDIR)$(PREFIX)/share/doc/kak
CXXFLAGS += -std=gnu++1y -g -Wall -Wno-reorder -Wno-sign-compare -pedantic CXXFLAGS += -std=gnu++11 -g -Wall -Wno-reorder -Wno-sign-compare -pedantic
ifneq (,$(findstring CYGWIN,$(os))) ifneq (,$(findstring CYGWIN,$(os)))
LDFLAGS += -rdynamic LDFLAGS += -rdynamic
endif endif

View File

@ -84,7 +84,7 @@ WindowAndSelections ClientManager::get_free_window(Buffer& buffer)
{ return &ws.window->buffer() == &buffer; }); { return &ws.window->buffer() == &buffer; });
if (it == m_free_windows.rend()) if (it == m_free_windows.rend())
return { std::make_unique<Window>(buffer), { buffer, Selection{} } }; return { make_unique<Window>(buffer), { buffer, Selection{} } };
it->window->forget_timestamp(); it->window->forget_timestamp();
WindowAndSelections res = std::move(*it); WindowAndSelections res = std::move(*it);

View File

@ -91,7 +91,7 @@ using TransformedResult = decltype(std::declval<T>()(*std::declval<I>()));
template<typename Iterator, typename Transform> template<typename Iterator, typename Transform>
struct TransformedIterator : std::iterator<std::forward_iterator_tag, struct TransformedIterator : std::iterator<std::forward_iterator_tag,
std::remove_reference_t<TransformedResult<Iterator, Transform>>> typename std::remove_reference<TransformedResult<Iterator, Transform>>::type>
{ {
TransformedIterator(Transform transform, Iterator it) TransformedIterator(Transform transform, Iterator it)
: m_it(std::move(it)), m_transform(std::move(transform)) {} : m_it(std::move(it)), m_transform(std::move(transform)) {}

View File

@ -10,18 +10,21 @@ template<typename Flags>
struct WithBitOps : std::false_type {}; struct WithBitOps : std::false_type {};
template<typename Flags> template<typename Flags>
using EnableIfWithBitOps = std::enable_if_t<WithBitOps<Flags>::value>; using UnderlyingType = typename std::underlying_type<Flags>::type;
template<typename Flags>
using EnableIfWithBitOps = typename std::enable_if<WithBitOps<Flags>::value>::type;
template<typename Flags, typename = EnableIfWithBitOps<Flags>> template<typename Flags, typename = EnableIfWithBitOps<Flags>>
constexpr Flags operator|(Flags lhs, Flags rhs) constexpr Flags operator|(Flags lhs, Flags rhs)
{ {
return (Flags)((std::underlying_type_t<Flags>) lhs | (std::underlying_type_t<Flags>) rhs); return (Flags)((UnderlyingType<Flags>) lhs | (UnderlyingType<Flags>) rhs);
} }
template<typename Flags, typename = EnableIfWithBitOps<Flags>> template<typename Flags, typename = EnableIfWithBitOps<Flags>>
Flags& operator|=(Flags& lhs, Flags rhs) Flags& operator|=(Flags& lhs, Flags rhs)
{ {
(std::underlying_type_t<Flags>&) lhs |= (std::underlying_type_t<Flags>) rhs; (UnderlyingType<Flags>&) lhs |= (UnderlyingType<Flags>) rhs;
return lhs; return lhs;
} }
@ -29,27 +32,27 @@ template<typename Flags>
struct TestableFlags struct TestableFlags
{ {
Flags value; Flags value;
constexpr operator bool() const { return (std::underlying_type_t<Flags>)value; } constexpr operator bool() const { return (UnderlyingType<Flags>)value; }
constexpr operator Flags() const { return value; } constexpr operator Flags() const { return value; }
}; };
template<typename Flags, typename = EnableIfWithBitOps<Flags>> template<typename Flags, typename = EnableIfWithBitOps<Flags>>
constexpr TestableFlags<Flags> operator&(Flags lhs, Flags rhs) constexpr TestableFlags<Flags> operator&(Flags lhs, Flags rhs)
{ {
return { (Flags)((std::underlying_type_t<Flags>) lhs & (std::underlying_type_t<Flags>) rhs) }; return { (Flags)((UnderlyingType<Flags>) lhs & (UnderlyingType<Flags>) rhs) };
} }
template<typename Flags, typename = EnableIfWithBitOps<Flags>> template<typename Flags, typename = EnableIfWithBitOps<Flags>>
Flags& operator&=(Flags& lhs, Flags rhs) Flags& operator&=(Flags& lhs, Flags rhs)
{ {
(std::underlying_type_t<Flags>&) lhs &= (std::underlying_type_t<Flags>) rhs; (UnderlyingType<Flags>&) lhs &= (UnderlyingType<Flags>) rhs;
return lhs; return lhs;
} }
template<typename Flags, typename = EnableIfWithBitOps<Flags>> template<typename Flags, typename = EnableIfWithBitOps<Flags>>
constexpr Flags operator~(Flags lhs) constexpr Flags operator~(Flags lhs)
{ {
return (Flags)(~(std::underlying_type_t<Flags>)lhs); return (Flags)(~(UnderlyingType<Flags>)lhs);
} }
} }

View File

@ -19,10 +19,10 @@ size_t hash_value(const Type&... val)
} }
template<typename Type> template<typename Type>
std::enable_if_t<std::is_enum<Type>::value, size_t> typename std::enable_if<std::is_enum<Type>::value, size_t>::type
hash_value(const Type& val) hash_value(const Type& val)
{ {
return hash_value((std::underlying_type_t<Type>)val); return hash_value((typename std::underlying_type<Type>::type)val);
} }
template<typename Type> template<typename Type>

View File

@ -61,7 +61,7 @@ private:
template<typename T> template<typename T>
std::unique_ptr<SimpleHighlighter<T>> make_simple_highlighter(T func) std::unique_ptr<SimpleHighlighter<T>> make_simple_highlighter(T func)
{ {
return std::make_unique<SimpleHighlighter<T>>(std::move(func)); return make_unique<SimpleHighlighter<T>>(std::move(func));
} }
using HighlighterParameters = ConstArrayView<String>; using HighlighterParameters = ConstArrayView<String>;

View File

@ -272,7 +272,7 @@ public:
Regex ex{params[0].begin(), params[0].end(), Regex::optimize}; Regex ex{params[0].begin(), params[0].end(), Regex::optimize};
return {id, std::make_unique<RegexHighlighter>(std::move(ex), return {id, make_unique<RegexHighlighter>(std::move(ex),
std::move(faces))}; std::move(faces))};
} }
catch (RegexError& err) catch (RegexError& err)
@ -447,7 +447,7 @@ template<typename RegexGetter, typename FaceGetter>
std::unique_ptr<DynamicRegexHighlighter<RegexGetter, FaceGetter>> std::unique_ptr<DynamicRegexHighlighter<RegexGetter, FaceGetter>>
make_dynamic_regex_highlighter(RegexGetter regex_getter, FaceGetter face_getter) make_dynamic_regex_highlighter(RegexGetter regex_getter, FaceGetter face_getter)
{ {
return std::make_unique<DynamicRegexHighlighter<RegexGetter, FaceGetter>>( return make_unique<DynamicRegexHighlighter<RegexGetter, FaceGetter>>(
std::move(regex_getter), std::move(face_getter)); std::move(regex_getter), std::move(face_getter));
} }
@ -896,7 +896,7 @@ HighlighterAndId create_highlighter_group(HighlighterParameters params)
if (params.size() != 1) if (params.size() != 1)
throw runtime_error("wrong parameter count"); throw runtime_error("wrong parameter count");
return HighlighterAndId(params[0], std::make_unique<HighlighterGroup>()); return HighlighterAndId(params[0], make_unique<HighlighterGroup>());
} }
HighlighterAndId create_reference_highlighter(HighlighterParameters params) HighlighterAndId create_reference_highlighter(HighlighterParameters params)
@ -1200,7 +1200,7 @@ public:
} }
auto default_group = parser.get_switch("default").value_or(StringView{}).str(); auto default_group = parser.get_switch("default").value_or(StringView{}).str();
return {parser[0], std::make_unique<RegionsHighlighter>(std::move(regions), default_group)}; return {parser[0], make_unique<RegionsHighlighter>(std::move(regions), default_group)};
} }
catch (RegexError& err) catch (RegexError& err)
{ {

View File

@ -261,7 +261,7 @@ void create_local_client(StringView init_command)
} }
static Client* client = ClientManager::instance().create_client( static Client* client = ClientManager::instance().create_client(
std::make_unique<LocalUI>(), get_env_vars(), init_command); make_unique<LocalUI>(), get_env_vars(), init_command);
signal(SIGHUP, [](int) { signal(SIGHUP, [](int) {
if (client) if (client)
ClientManager::instance().remove_client(*client); ClientManager::instance().remove_client(*client);
@ -299,7 +299,7 @@ int run_client(StringView session, StringView init_command)
try try
{ {
EventManager event_manager; EventManager event_manager;
RemoteClient client{session, std::make_unique<NCursesUI>(), RemoteClient client{session, make_unique<NCursesUI>(),
get_env_vars(), init_command}; get_env_vars(), init_command};
while (true) while (true)
event_manager.handle_next_events(EventMode::Normal); event_manager.handle_next_events(EventMode::Normal);

View File

@ -94,7 +94,8 @@ private:
}; };
template<typename T> using SafePtr = template<typename T> using SafePtr =
RefPtr<T, std::conditional_t<std::is_const<T>::value, const SafeCountable, SafeCountable>>; RefPtr<T, typename std::conditional<std::is_const<T>::value,
const SafeCountable, SafeCountable>::type>;
} }

View File

@ -297,10 +297,10 @@ namespace detail
template<typename T> using IsString = std::is_convertible<T, StringView>; template<typename T> using IsString = std::is_convertible<T, StringView>;
template<typename T, class = std::enable_if_t<!IsString<T>::value>> template<typename T, class = typename std::enable_if<!IsString<T>::value>::type>
auto format_param(const T& val) -> decltype(to_string(val)) { return to_string(val); } auto format_param(const T& val) -> decltype(to_string(val)) { return to_string(val); }
template<typename T, class = std::enable_if_t<IsString<T>::value>> template<typename T, class = typename std::enable_if<IsString<T>::value>::type>
StringView format_param(const T& val) { return val; } StringView format_param(const T& val) { return val; }
} }

View File

@ -8,6 +8,34 @@
namespace Kakoune namespace Kakoune
{ {
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<size_t... I>
struct IndexSequence
{
using Next = IndexSequence<I..., sizeof...(I)>;
};
template<size_t N>
struct MakeIndexSequence
{
using Type = typename MakeIndexSequence<N-1>::Type::Next;
};
template<>
struct MakeIndexSequence<0>
{
using Type = IndexSequence<>;
};
template<size_t N>
constexpr typename MakeIndexSequence<N>::Type
make_index_sequence() { return typename MakeIndexSequence<N>::Type{}; }
// *** Singleton *** // *** Singleton ***
// //
// Singleton helper class, every singleton type T should inherit // Singleton helper class, every singleton type T should inherit