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
Loading
Please register or sign in to comment