Support set -add on flag types

Fixes #1082
This commit is contained in:
Maxime Coste 2016-12-27 21:52:53 +00:00
parent 6d3842af5b
commit 243bcf6a6d
2 changed files with 10 additions and 2 deletions

View File

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

View File

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