From f491e51ebd3ac15bea38b6a826628dd9c4d13e19 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sat, 29 Jun 2013 18:38:17 +0000 Subject: [PATCH] Add operators to make launch a bitmask type. Searched all of the standard, and libc++ to see if this error occurred elsewhere and didn't see any other place. This fixes http://llvm.org/bugs/show_bug.cgi?id=16207 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185265 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/future | 66 +++++++++++++++++++ .../futures/futures.overview/launch.pass.cpp | 16 +++++ 2 files changed, 82 insertions(+) diff --git a/include/future b/include/future index 3d7bb6c9..160114e5 100644 --- a/include/future +++ b/include/future @@ -403,6 +403,72 @@ _LIBCPP_DECLARE_STRONG_ENUM(launch) }; _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch) +#ifndef _LIBCPP_HAS_NO_STRONG_ENUMS + +#ifdef _LIBCXX_UNDERLYING_TYPE +typedef underlying_type::type __launch_underlying_type; +#else +typedef int __launch_underlying_type; +#endif + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator&(launch __x, launch __y) +{ + return static_cast(static_cast<__launch_underlying_type>(__x) & + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator|(launch __x, launch __y) +{ + return static_cast(static_cast<__launch_underlying_type>(__x) | + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator^(launch __x, launch __y) +{ + return static_cast(static_cast<__launch_underlying_type>(__x) ^ + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator~(launch __x) +{ + return static_cast(~static_cast<__launch_underlying_type>(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator&=(launch& __x, launch __y) +{ + __x = __x & __y; return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator|=(launch& __x, launch __y) +{ + __x = __x | __y; return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator^=(launch& __x, launch __y) +{ + __x = __x ^ __y; return __x; +} + +#endif // !_LIBCPP_HAS_NO_STRONG_ENUMS + //enum class future_status _LIBCPP_DECLARE_STRONG_ENUM(future_status) { diff --git a/test/thread/futures/futures.overview/launch.pass.cpp b/test/thread/futures/futures.overview/launch.pass.cpp index 75534f79..d634c8b5 100644 --- a/test/thread/futures/futures.overview/launch.pass.cpp +++ b/test/thread/futures/futures.overview/launch.pass.cpp @@ -17,11 +17,27 @@ // }; #include +#include int main() { +#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS static_assert(static_cast(std::launch::any) == (static_cast(std::launch::async) | static_cast(std::launch::deferred)), ""); +#else + static_assert(std::launch::any == (std::launch::async | std::launch::deferred), ""); + static_assert(std::launch(0) == (std::launch::async & std::launch::deferred), ""); + static_assert(std::launch::any == (std::launch::async ^ std::launch::deferred), ""); + static_assert(std::launch(~1) == ~std::launch::async, ""); + std::launch x = std::launch::async; + x &= std::launch::deferred; + assert(x == std::launch(0)); + x = std::launch::async; + x |= std::launch::deferred; + assert(x == std::launch::any); + x ^= std::launch::deferred; + assert(x == std::launch::async); +#endif static_assert(static_cast(std::launch::async) == 1, ""); static_assert(static_cast(std::launch::deferred) == 2, ""); }