From db9b863222dbd51154c422cf85bc8fafacd5b25b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 15 Mar 2017 17:55:34 +0000 Subject: [PATCH] Migrate WithBitOps template specialization to with_bit_ops function This way we dont depend on knowing the base template to enable bit ops on an enum type. --- src/buffer.hh | 3 +-- src/command_manager.hh | 2 +- src/completion.hh | 2 +- src/context.hh | 3 +-- src/event_manager.cc | 1 + src/event_manager.hh | 4 ++-- src/face.hh | 2 +- src/file.hh | 2 +- src/flags.hh | 8 +++++--- src/input_handler.hh | 5 ++--- src/keys.hh | 2 +- src/main.cc | 2 +- src/normal.cc | 2 +- src/option_manager.cc | 1 + src/option_manager.hh | 3 +-- src/option_types.hh | 5 ++--- src/parameters_parser.hh | 3 +-- src/ranked_match.cc | 2 -- src/ranked_match.hh | 2 ++ src/selectors.hh | 2 +- src/shell_manager.cc | 1 + src/shell_manager.hh | 4 +--- 22 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/buffer.hh b/src/buffer.hh index bc960b20..f535c387 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -115,6 +115,7 @@ public: Debug = 1 << 5, ReadOnly = 1 << 6, }; + friend constexpr bool with_bit_ops(Meta::Type) { return true; } Buffer(String name, Flags flags, StringView data = {}, timespec fs_timestamp = InvalidTime); @@ -283,8 +284,6 @@ private: mutable ValueMap m_values; }; -template<> struct WithBitOps : std::true_type {}; - } #include "buffer.inl.hh" diff --git a/src/command_manager.hh b/src/command_manager.hh index 5269ca39..36cfe423 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -37,7 +37,7 @@ enum class CommandFlags Hidden = 1, }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } struct CommandInfo { String name, info; }; diff --git a/src/completion.hh b/src/completion.hh index 95dc7deb..281c120f 100644 --- a/src/completion.hh +++ b/src/completion.hh @@ -40,7 +40,7 @@ enum class CompletionFlags Start = 1 << 2, }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } using Completer = std::function; diff --git a/src/context.hh b/src/context.hh index a50eb87f..ba981f69 100644 --- a/src/context.hh +++ b/src/context.hh @@ -183,8 +183,7 @@ private: NestedBool m_history_disabled; }; -template<> -struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } struct ScopedEdition { diff --git a/src/event_manager.cc b/src/event_manager.cc index 11fb5c44..7a0614dc 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -1,6 +1,7 @@ #include "event_manager.hh" #include "containers.hh" +#include "flags.hh" #include diff --git a/src/event_manager.hh b/src/event_manager.hh index f4fa503e..e83672b9 100644 --- a/src/event_manager.hh +++ b/src/event_manager.hh @@ -2,8 +2,8 @@ #define event_manager_hh_INCLUDED #include "clock.hh" +#include "meta.hh" #include "utils.hh" -#include "flags.hh" #include "vector.hh" #include @@ -28,7 +28,7 @@ enum class FdEvents Except = 1 << 2, }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } class FDWatcher { diff --git a/src/face.hh b/src/face.hh index 806089a9..dc38192c 100644 --- a/src/face.hh +++ b/src/face.hh @@ -19,7 +19,7 @@ enum class Attribute : int Italic = 1 << 7, }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } struct Face { diff --git a/src/file.hh b/src/file.hh index a103d61f..1ecb1090 100644 --- a/src/file.hh +++ b/src/file.hh @@ -79,7 +79,7 @@ enum class FilenameFlags Expand = 1 << 1 }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } CandidateList complete_filename(StringView prefix, const Regex& ignore_regex, ByteCount cursor_pos = -1, diff --git a/src/flags.hh b/src/flags.hh index d9755efa..74a7188f 100644 --- a/src/flags.hh +++ b/src/flags.hh @@ -3,20 +3,22 @@ #include +#include "meta.hh" + namespace Kakoune { template -struct WithBitOps : std::false_type {}; +constexpr bool with_bit_ops(Meta::Type) { return false; } template using UnderlyingType = typename std::underlying_type::type; template -using EnableIfWithBitOps = typename std::enable_if::value, T>::type; +using EnableIfWithBitOps = typename std::enable_if{}), T>::type; template -using EnableIfWithoutBitOps = typename std::enable_if::value, T>::type; +using EnableIfWithoutBitOps = typename std::enable_if{}), T>::type; template> constexpr Flags operator|(Flags lhs, Flags rhs) diff --git a/src/input_handler.hh b/src/input_handler.hh index fd13a5a0..2962ac12 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -35,7 +35,7 @@ enum class PromptFlags Password = 1 << 0, DropHistoryEntriesWithBlankPrefix = 1 << 1 }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } using KeyCallback = std::function; @@ -131,8 +131,7 @@ enum class AutoInfo Normal = 1 << 2 }; -template<> -struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } constexpr Array, 3> enum_desc(Meta::Type) { diff --git a/src/keys.hh b/src/keys.hh index 39378c22..02df20a6 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -84,7 +84,7 @@ struct Key Optional codepoint() const; }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } using KeyList = Vector; diff --git a/src/main.cc b/src/main.cc index f7cbdd54..426e7809 100644 --- a/src/main.cc +++ b/src/main.cc @@ -493,7 +493,7 @@ enum class ServerFlags ReadOnly = 1 << 2, StartupInfo = 1 << 3, }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } int run_server(StringView session, StringView init_cmds, Optional init_coord, diff --git a/src/normal.cc b/src/normal.cc index 0ee22f59..03826487 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1261,7 +1261,7 @@ enum class SelectFlags Extend = 4 }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } template void select_to_next_char(Context& context, NormalParams params) diff --git a/src/option_manager.cc b/src/option_manager.cc index eb50bfcb..d842a254 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -1,6 +1,7 @@ #include "option_manager.hh" #include "assert.hh" +#include "flags.hh" namespace Kakoune { diff --git a/src/option_manager.hh b/src/option_manager.hh index e794a3c9..b20303b0 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -4,7 +4,6 @@ #include "completion.hh" #include "containers.hh" #include "exception.hh" -#include "flags.hh" #include "option_types.hh" #include "vector.hh" @@ -22,7 +21,7 @@ enum class OptionFlags Hidden = 1, }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } class OptionDesc { diff --git a/src/option_types.hh b/src/option_types.hh index ab2c35fa..1a55fb17 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -28,7 +28,7 @@ template typename std::enable_if::value, String>::type option_type_name(Meta::Type) { - constexpr StringView type = WithBitOps::value ? "flags" : "enum"; + constexpr StringView type = with_bit_ops(Meta::Type{}) ? "flags" : "enum"; auto name = enum_desc(Meta::Type{}); return type + "(" + join(name | transform(std::mem_fn(&EnumDesc::name)), '|') + ")"; } @@ -244,8 +244,7 @@ enum class DebugFlags Keys = 1 << 3, }; -template<> -struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } constexpr Array, 4> enum_desc(Meta::Type) { diff --git a/src/parameters_parser.hh b/src/parameters_parser.hh index f45c0410..a790aa6e 100644 --- a/src/parameters_parser.hh +++ b/src/parameters_parser.hh @@ -53,6 +53,7 @@ struct ParameterDesc SwitchesOnlyAtStart = 1, SwitchesAsPositional = 2, }; + friend constexpr bool with_bit_ops(Meta::Type) { return true; } ParameterDesc() = default; ParameterDesc(SwitchMap switches, Flags flags = Flags::None, @@ -66,8 +67,6 @@ struct ParameterDesc size_t max_positionals = -1; }; -template<> struct WithBitOps : std::true_type {}; - // ParametersParser provides tools to parse command parameters. // There are 3 types of parameters: // * unnamed options, which are accessed by position (ignoring named ones) diff --git a/src/ranked_match.cc b/src/ranked_match.cc index 1de8713e..3b1d9645 100644 --- a/src/ranked_match.cc +++ b/src/ranked_match.cc @@ -9,8 +9,6 @@ namespace Kakoune { -template<> struct WithBitOps : std::true_type {}; - UsedLetters used_letters(StringView str) { UsedLetters res = 0; diff --git a/src/ranked_match.hh b/src/ranked_match.hh index bac6bc39..9d0e3b73 100644 --- a/src/ranked_match.hh +++ b/src/ranked_match.hh @@ -2,6 +2,7 @@ #define ranked_match_hh_INCLUDED #include "string.hh" +#include "meta.hh" namespace Kakoune { @@ -43,6 +44,7 @@ private: Prefix = 1 << 4, FullMatch = 1 << 5, }; + friend constexpr bool with_bit_ops(Meta::Type) { return true; } StringView m_candidate{}; Flags m_flags = Flags::None; diff --git a/src/selectors.hh b/src/selectors.hh index e0bbb5b5..e873d9ab 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -60,7 +60,7 @@ enum class ObjectFlags Inner = 4 }; -template<> struct WithBitOps : std::true_type {}; +constexpr bool with_bit_ops(Meta::Type) { return true; } template Optional diff --git a/src/shell_manager.cc b/src/shell_manager.cc index a663c59f..78147d76 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -7,6 +7,7 @@ #include "event_manager.hh" #include "face_registry.hh" #include "file.hh" +#include "flags.hh" #include "regex.hh" #include diff --git a/src/shell_manager.hh b/src/shell_manager.hh index 1336ca9b..df2429d6 100644 --- a/src/shell_manager.hh +++ b/src/shell_manager.hh @@ -3,7 +3,6 @@ #include "array_view.hh" #include "env_vars.hh" -#include "flags.hh" #include "string.hh" #include "utils.hh" #include "completion.hh" @@ -31,6 +30,7 @@ public: None = 0, WaitForStdout = 1 }; + friend constexpr bool with_bit_ops(Meta::Type) { return true; } std::pair eval(StringView cmdline, const Context& context, StringView input = {}, @@ -49,8 +49,6 @@ private: Vector m_env_vars; }; -template<> struct WithBitOps : std::true_type {}; - } #endif // shell_manager_hh_INCLUDED