From 243bcf6a6d678fbf6a5d13935e6f77e571836f3e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 27 Dec 2016 21:52:53 +0000 Subject: [PATCH] Support set -add on flag types Fixes #1082 --- src/enum.hh | 9 +++++++++ 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 option_from_string(StringView str, Enum& e) e = it->value; } +template +EnableIfWithBitOps 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& opt, return val != 0; } -template -bool option_add(T&, StringView str) +inline bool option_add(...) { throw runtime_error("no add operation supported for this option type"); }