fd: Implement managed file descriptor support
Change-Id: I0c5c438aa2c31ae52e115951b3fb1e85df182fd1
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/stdplus/flags.hpp b/src/stdplus/flags.hpp
new file mode 100644
index 0000000..047c776
--- /dev/null
+++ b/src/stdplus/flags.hpp
@@ -0,0 +1,46 @@
+#pragma once
+#include <utility>
+
+namespace stdplus
+{
+
+template <typename Int, typename Flag = Int>
+class BitFlags
+{
+ public:
+ inline explicit BitFlags(Int val = 0) noexcept : val(val)
+ {
+ }
+
+ inline BitFlags& set(Flag flag) & noexcept
+ {
+ val |= static_cast<Int>(flag);
+ return *this;
+ }
+ inline BitFlags&& set(Flag flag) && noexcept
+ {
+ val |= static_cast<Int>(flag);
+ return std::move(*this);
+ }
+
+ inline BitFlags& unset(Flag flag) & noexcept
+ {
+ val &= ~static_cast<Int>(flag);
+ return *this;
+ }
+ inline BitFlags&& unset(Flag flag) && noexcept
+ {
+ val &= ~static_cast<Int>(flag);
+ return std::move(*this);
+ }
+
+ explicit inline operator Int() const noexcept
+ {
+ return val;
+ }
+
+ private:
+ Int val;
+};
+
+} // namespace stdplus