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.
This commit is contained in:
Maxime Coste 2017-03-15 17:55:34 +00:00
parent a49e175727
commit db9b863222
22 changed files with 29 additions and 32 deletions

View File

@ -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"

View File

@ -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; };

View File

@ -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)>;

View File

@ -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
{

View File

@ -1,6 +1,7 @@
#include "event_manager.hh"
#include "containers.hh"
#include "flags.hh"
#include <unistd.h>

View File

@ -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
{

View File

@ -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
{

View File

@ -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,

View File

@ -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)

View File

@ -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>)
{

View File

@ -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>;

View File

@ -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,

View File

@ -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)

View File

@ -1,6 +1,7 @@
#include "option_manager.hh"
#include "assert.hh"
#include "flags.hh"
namespace Kakoune
{

View File

@ -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
{

View File

@ -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>)
{

View File

@ -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)

View File

@ -9,8 +9,6 @@
namespace Kakoune
{
template<> struct WithBitOps<RankedMatch::Flags> : std::true_type {};
UsedLetters used_letters(StringView str)
{
UsedLetters res = 0;

View File

@ -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;

View File

@ -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>

View File

@ -7,6 +7,7 @@
#include "event_manager.hh"
#include "face_registry.hh"
#include "file.hh"
#include "flags.hh"
#include "regex.hh"
#include <cstring>

View File

@ -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