flags: Make all operations constexpr compatible
We should be able to build flagsets at compile time as they are usually
known in advance.
Change-Id: Id5c2cda9da5ecf93aa382979a1b05c3020d09eab
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include-dl/stdplus/dl.hpp b/include-dl/stdplus/dl.hpp
index 4c653da..223af24 100644
--- a/include-dl/stdplus/dl.hpp
+++ b/include-dl/stdplus/dl.hpp
@@ -26,11 +26,11 @@
class DlOpenFlags : public stdplus::BitFlags<DlOpenFlag>
{
public:
- inline DlOpenFlags(DlOpenType type) :
+ constexpr DlOpenFlags(DlOpenType type) :
BitFlags<DlOpenFlag>(std::to_underlying(type))
{}
- inline DlOpenFlags(BitFlags<DlOpenFlag> flags) :
+ constexpr DlOpenFlags(BitFlags<DlOpenFlag> flags) :
BitFlags<DlOpenFlag>(flags)
{}
};
diff --git a/include-fd/stdplus/fd/create.hpp b/include-fd/stdplus/fd/create.hpp
index 81ebfde..9cdeba4 100644
--- a/include-fd/stdplus/fd/create.hpp
+++ b/include-fd/stdplus/fd/create.hpp
@@ -44,11 +44,11 @@
class OpenFlags : public BitFlags<OpenFlag>
{
public:
- inline OpenFlags(OpenAccess access) :
+ constexpr OpenFlags(OpenAccess access) :
BitFlags<OpenFlag>(std::to_underlying(access))
{}
- inline OpenFlags(BitFlags<OpenFlag> flags) : BitFlags<OpenFlag>(flags) {}
+ constexpr OpenFlags(BitFlags<OpenFlag> flags) : BitFlags<OpenFlag>(flags) {}
};
DupableFd open(const_zstring pathname, OpenFlags flags, mode_t mode = 0);
diff --git a/include-fd/stdplus/fd/intf.hpp b/include-fd/stdplus/fd/intf.hpp
index 7f448c8..ced525b 100644
--- a/include-fd/stdplus/fd/intf.hpp
+++ b/include-fd/stdplus/fd/intf.hpp
@@ -104,11 +104,11 @@
class MMapFlags : public BitFlags<MMapFlag>
{
public:
- inline MMapFlags(MMapAccess access) :
+ constexpr MMapFlags(MMapAccess access) :
BitFlags<MMapFlag>(std::to_underlying(access))
{}
- inline MMapFlags(BitFlags<MMapFlag> flags) : BitFlags<MMapFlag>(flags) {}
+ constexpr MMapFlags(BitFlags<MMapFlag> flags) : BitFlags<MMapFlag>(flags) {}
};
class MMap;
diff --git a/include/stdplus/flags.hpp b/include/stdplus/flags.hpp
index 4fdd511..faa3a2f 100644
--- a/include/stdplus/flags.hpp
+++ b/include/stdplus/flags.hpp
@@ -15,32 +15,32 @@
using type = T;
using underlying = I;
- inline BitFlags() noexcept : val(0) {}
- explicit inline BitFlags(underlying val) noexcept : val(val) {}
+ constexpr BitFlags() noexcept : val(0) {}
+ explicit constexpr BitFlags(underlying val) noexcept : val(val) {}
- inline BitFlags& set(type flag) & noexcept
+ constexpr BitFlags& set(type flag) & noexcept
{
val |= std::to_underlying(flag);
return *this;
}
- inline BitFlags&& set(type flag) && noexcept
+ constexpr BitFlags&& set(type flag) && noexcept
{
val |= std::to_underlying(flag);
return std::move(*this);
}
- inline BitFlags& unset(type flag) & noexcept
+ constexpr BitFlags& unset(type flag) & noexcept
{
val &= ~std::to_underlying(flag);
return *this;
}
- inline BitFlags&& unset(type flag) && noexcept
+ constexpr BitFlags&& unset(type flag) && noexcept
{
val &= ~std::to_underlying(flag);
return std::move(*this);
}
- explicit inline operator underlying() const noexcept
+ explicit constexpr operator underlying() const noexcept
{
return val;
}