diff options
| author | 2024-11-20 18:06:07 -0800 | |
|---|---|---|
| committer | 2024-11-20 18:33:39 -0800 | |
| commit | 83c6f9eed4bd2a10a7d73a3a0ab92766dfd8867b (patch) | |
| tree | 67b5c6c720c7d95212b96a047a6a8423edfa1408 /libs/gui/ConsumerBase.cpp | |
| parent | 1a824fd33a5308b68d69cf5ea20184b5c690d8e9 (diff) | |
Easier ftl::Flags construction
As demonstrated by the existing test, while it is possible to construct
a ftl::Flags<E> from multiple values, it requires an extra
`using namespace ftl::flag_operators` or alternatively a
`using ftl::flag_operators::operator|` to implicitly construct a
`ftl::Flags<E>` type.
But there is an easier way -- allow implicit construction from a
`std::initializer_list<E>`.
This means as an alternative to:
    using namespace ftl::flag_operators;
    ftl::Flags<E> x = E::A | E::B;
... one can instead write:
    ftl::Flags<E> x = {E::A, E::B};
... and achieve the same initial value.
This change adds the new constructor overload.
Assignment from an initializer list automatically works, without having
to define a explicit `operator=(std::initializer_list<E>)`. Instead the
copy constuctor is used.
As a useful side effect, you can now also clear the flags by assigning
an empty initializer list:
    ftl::Flags<E> x;
    x = {};  // Clears x to zero
Bug: 185536303
Flag: EXEMPT New library code
Test: atest ftl_test
Change-Id: I1de7857c93ebef4fc5e6157aac9cf162b49943e1
Diffstat (limited to 'libs/gui/ConsumerBase.cpp')
0 files changed, 0 insertions, 0 deletions