Add Arch::operator| and operator|=

The OR operator for Arch stacks bitness information.

Test: libvintf_test
Test: lshal --init-vintf

Bug: 62675393
Change-Id: I3fc56b3a39e48c8a2d452f2796123fca3fc1d4a4
Merged-In: I3fc56b3a39e48c8a2d452f2796123fca3fc1d4a4
diff --git a/include/vintf/Arch.h b/include/vintf/Arch.h
index d49661a..77d1c37 100644
--- a/include/vintf/Arch.h
+++ b/include/vintf/Arch.h
@@ -49,6 +49,15 @@
     return arch == Arch::ARCH_64 || arch == Arch::ARCH_32_64;
 }
 
+inline constexpr Arch operator|(Arch lft, Arch rgt) {
+    return static_cast<Arch>(static_cast<size_t>(lft) | static_cast<size_t>(rgt));
+}
+static_assert((Arch::ARCH_32 | Arch::ARCH_64) == Arch::ARCH_32_64, "bad Arch::operator|");
+
+inline Arch& operator|=(Arch& lft, Arch rgt) {
+    return (lft = lft | rgt);
+}
+
 } // namespace vintf
 } // namespace android
 
diff --git a/test/main.cpp b/test/main.cpp
index 5f06a8b..6ce1e23 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -163,6 +163,18 @@
     }
 };
 
+TEST_F(LibVintfTest, ArchOperatorOr) {
+    Arch a = Arch::ARCH_EMPTY;
+    a |= Arch::ARCH_32;
+    EXPECT_EQ(Arch::ARCH_32, a);
+
+    a |= Arch::ARCH_64;
+    EXPECT_EQ(Arch::ARCH_32_64, a);
+
+    a = Arch::ARCH_EMPTY;
+    a |= Arch::ARCH_64;
+    EXPECT_EQ(Arch::ARCH_64, a);
+}
 
 TEST_F(LibVintfTest, Stringify) {
     HalManifest vm = testDeviceManifest();