summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-03-15 17:55:34 +0000
committerMaxime Coste <mawww@kakoune.org>2017-03-15 18:00:58 +0000
commitdb9b863222dbd51154c422cf85bc8fafacd5b25b (patch)
treec64d4a42ff62372736d747a1ab25568954ba6e32 /src
parenta49e175727928b8b45c0c2ccdb01f143ea6d18c2 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.hh3
-rw-r--r--src/command_manager.hh2
-rw-r--r--src/completion.hh2
-rw-r--r--src/context.hh3
-rw-r--r--src/event_manager.cc1
-rw-r--r--src/event_manager.hh4
-rw-r--r--src/face.hh2
-rw-r--r--src/file.hh2
-rw-r--r--src/flags.hh8
-rw-r--r--src/input_handler.hh5
-rw-r--r--src/keys.hh2
-rw-r--r--src/main.cc2
-rw-r--r--src/normal.cc2
-rw-r--r--src/option_manager.cc1
-rw-r--r--src/option_manager.hh3
-rw-r--r--src/option_types.hh5
-rw-r--r--src/parameters_parser.hh3
-rw-r--r--src/ranked_match.cc2
-rw-r--r--src/ranked_match.hh2
-rw-r--r--src/selectors.hh2
-rw-r--r--src/shell_manager.cc1
-rw-r--r--src/shell_manager.hh4
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<Flags>) { 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<Buffer::Flags> : 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<CommandFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<CommandFlags>) { 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<CompletionFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<CompletionFlags>) { return true; }
using Completer = std::function<Completions (const Context&, CompletionFlags,
StringView, ByteCount)>;
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<Context::Flags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<Context::Flags>) { 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 <unistd.h>
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 <functional>
@@ -28,7 +28,7 @@ enum class FdEvents
Except = 1 << 2,
};
-template<> struct WithBitOps<FdEvents> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<FdEvents>) { 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<Attribute> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<Attribute>) { 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<FilenameFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<FilenameFlags>) { 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 <type_traits>
+#include "meta.hh"
+
namespace Kakoune
{
template<typename Flags>
-struct WithBitOps : std::false_type {};
+constexpr bool with_bit_ops(Meta::Type<Flags>) { return false; }
template<typename Flags>
using UnderlyingType = typename std::underlying_type<Flags>::type;
template<typename Flags, typename T = void>
-using EnableIfWithBitOps = typename std::enable_if<WithBitOps<Flags>::value, T>::type;
+using EnableIfWithBitOps = typename std::enable_if<with_bit_ops(Meta::Type<Flags>{}), T>::type;
template<typename Flags, typename T = void>
-using EnableIfWithoutBitOps = typename std::enable_if<not WithBitOps<Flags>::value, T>::type;
+using EnableIfWithoutBitOps = typename std::enable_if<not with_bit_ops(Meta::Type<Flags>{}), T>::type;
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
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<PromptFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<PromptFlags>) { return true; }
using KeyCallback = std::function<void (Key, Context&)>;
@@ -131,8 +131,7 @@ enum class AutoInfo
Normal = 1 << 2
};
-template<>
-struct WithBitOps<AutoInfo> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<AutoInfo>) { return true; }
constexpr Array<EnumDesc<AutoInfo>, 3> enum_desc(Meta::Type<AutoInfo>)
{
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> codepoint() const;
};
-template<> struct WithBitOps<Key::Modifiers> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<Key::Modifiers>) { return true; }
using KeyList = Vector<Key, MemoryDomain::Mapping>;
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<ServerFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<ServerFlags>) { return true; }
int run_server(StringView session,
StringView init_cmds, Optional<BufferCoord> 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<SelectFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<SelectFlags>) { return true; }
template<SelectFlags flags>
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<OptionFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<OptionFlags>) { 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 Enum>
typename std::enable_if<std::is_enum<Enum>::value, String>::type
option_type_name(Meta::Type<Enum>)
{
- constexpr StringView type = WithBitOps<Enum>::value ? "flags" : "enum";
+ constexpr StringView type = with_bit_ops(Meta::Type<Enum>{}) ? "flags" : "enum";
auto name = enum_desc(Meta::Type<Enum>{});
return type + "(" + join(name | transform(std::mem_fn(&EnumDesc<Enum>::name)), '|') + ")";
}
@@ -244,8 +244,7 @@ enum class DebugFlags
Keys = 1 << 3,
};
-template<>
-struct WithBitOps<DebugFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
constexpr Array<EnumDesc<DebugFlags>, 4> enum_desc(Meta::Type<DebugFlags>)
{
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<Flags>) { 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<ParameterDesc::Flags> : 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<RankedMatch::Flags> : 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<Flags>) { 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<ObjectFlags> : std::true_type {};
+constexpr bool with_bit_ops(Meta::Type<ObjectFlags>) { return true; }
template<WordType word_type>
Optional<Selection>
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 <cstring>
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<Flags>) { return true; }
std::pair<String, int> eval(StringView cmdline, const Context& context,
StringView input = {},
@@ -49,8 +49,6 @@ private:
Vector<EnvVarDesc, MemoryDomain::EnvVars> m_env_vars;
};
-template<> struct WithBitOps<ShellManager::Flags> : std::true_type {};
-
}
#endif // shell_manager_hh_INCLUDED