Skip to content

Commit

Permalink
refs #79, constexpr on non-assigning bitmask operations
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed Nov 17, 2020
1 parent 1edf4a3 commit 10e0da4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,28 +1352,28 @@ using EnableBitmask = typename std::enable_if<std::is_same<Enum, perms>::value |
} // namespace detail

template <typename Enum>
detail::EnableBitmask<Enum> operator&(Enum X, Enum Y)
constexpr detail::EnableBitmask<Enum> operator&(Enum X, Enum Y)
{
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(static_cast<underlying>(X) & static_cast<underlying>(Y));
}

template <typename Enum>
detail::EnableBitmask<Enum> operator|(Enum X, Enum Y)
constexpr detail::EnableBitmask<Enum> operator|(Enum X, Enum Y)
{
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(static_cast<underlying>(X) | static_cast<underlying>(Y));
}

template <typename Enum>
detail::EnableBitmask<Enum> operator^(Enum X, Enum Y)
constexpr detail::EnableBitmask<Enum> operator^(Enum X, Enum Y)
{
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(static_cast<underlying>(X) ^ static_cast<underlying>(Y));
}

template <typename Enum>
detail::EnableBitmask<Enum> operator~(Enum X)
constexpr detail::EnableBitmask<Enum> operator~(Enum X)
{
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(~static_cast<underlying>(X));
Expand Down
6 changes: 6 additions & 0 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,14 @@ TEST_CASE("30.10.9 class filesystem_error", "[filesystem][filesystem_error][fs.c
CHECK(fse.path2() == "some/other");
}

constexpr fs::perms constExprOwnerAll()
{
return fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec;
}

TEST_CASE("30.10.10.4 enum class perms", "[filesystem][enum][fs.enum]")
{
static_assert(constExprOwnerAll() == fs::perms::owner_all, "constexpr didn't result in owner_all");
CHECK((fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec) == fs::perms::owner_all);
CHECK((fs::perms::group_read | fs::perms::group_write | fs::perms::group_exec) == fs::perms::group_all);
CHECK((fs::perms::others_read | fs::perms::others_write | fs::perms::others_exec) == fs::perms::others_all);
Expand Down

0 comments on commit 10e0da4

Please sign in to comment.