diff options
| author | Maxime Coste <mawww@kakoune.org> | 2016-12-27 21:52:53 +0000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2016-12-27 21:52:53 +0000 |
| commit | 243bcf6a6d678fbf6a5d13935e6f77e571836f3e (patch) | |
| tree | 59300ff0dd55b07e6e9dfc137b4ca68022d4a88a | |
| parent | 6d3842af5b5d58cd1644bbc5ecde8dfa81a7d7e0 (diff) | |
Support set -add on flag types
Fixes #1082
| -rw-r--r-- | src/enum.hh | 9 | ||||
| -rw-r--r-- | src/option_types.hh | 3 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/enum.hh b/src/enum.hh index 6f4a4bdb..01f89b32 100644 --- a/src/enum.hh +++ b/src/enum.hh @@ -73,6 +73,15 @@ EnableIfWithoutBitOps<Enum> option_from_string(StringView str, Enum& e) e = it->value; } +template<typename Flags, typename = decltype(enum_desc(Flags{}))> +EnableIfWithBitOps<Flags, bool> option_add(Flags& opt, StringView str) +{ + Flags res = Flags{}; + option_from_string(str, res); + opt |= res; + return res != (Flags)0; +} + } #endif // enum_hh_INCLUDED diff --git a/src/option_types.hh b/src/option_types.hh index b0d9b054..3b5799dd 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -214,8 +214,7 @@ inline bool option_add(StronglyTypedNumber<RealType, ValueType>& opt, return val != 0; } -template<typename T> -bool option_add(T&, StringView str) +inline bool option_add(...) { throw runtime_error("no add operation supported for this option type"); } |
