mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::util: Add enum-flag accumulator util.
This commit is contained in:
parent
dae391a578
commit
34be7b1d77
1 changed files with 22 additions and 0 deletions
|
@ -557,6 +557,28 @@ operator^=(Enum &a, const Enum &b)
|
|||
return (a = (a ^ b));
|
||||
}
|
||||
|
||||
template<class Enum,
|
||||
class it>
|
||||
typename std::enable_if<std::is_enum<Enum>::value, typename std::underlying_type<Enum>::type>::type
|
||||
combine_flags(const it &begin,
|
||||
const it &end)
|
||||
{
|
||||
using type = typename std::underlying_type<Enum>::type;
|
||||
|
||||
return std::accumulate(begin, end, type(0), []
|
||||
(auto ret, const auto &val)
|
||||
{
|
||||
return ret |= type(val);
|
||||
});
|
||||
}
|
||||
|
||||
template<class Enum>
|
||||
typename std::enable_if<std::is_enum<Enum>::value, typename std::underlying_type<Enum>::type>::type
|
||||
combine_flags(const std::initializer_list<Enum> &list)
|
||||
{
|
||||
return combine_flags<Enum>(begin(list), end(list));
|
||||
}
|
||||
|
||||
|
||||
inline size_t
|
||||
size(std::ostream &s)
|
||||
|
|
Loading…
Reference in a new issue