[libcxx] r185265 - 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
Howard Hinnant
hhinnant at apple.com
Sat Jun 29 11:38:17 PDT 2013
Author: hhinnant
Date: Sat Jun 29 13:38:17 2013
New Revision: 185265
URL: http://llvm.org/viewvc/llvm-project?rev=185265&view=rev
Log:
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
Modified:
libcxx/trunk/include/future
libcxx/trunk/test/thread/futures/futures.overview/launch.pass.cpp
Modified: libcxx/trunk/include/future
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/future?rev=185265&r1=185264&r2=185265&view=diff
==============================================================================
--- libcxx/trunk/include/future (original)
+++ libcxx/trunk/include/future Sat Jun 29 13:38:17 2013
@@ -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<launch>::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<launch>(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<launch>(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<launch>(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<launch>(~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)
{
Modified: libcxx/trunk/test/thread/futures/futures.overview/launch.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/thread/futures/futures.overview/launch.pass.cpp?rev=185265&r1=185264&r2=185265&view=diff
==============================================================================
--- libcxx/trunk/test/thread/futures/futures.overview/launch.pass.cpp (original)
+++ libcxx/trunk/test/thread/futures/futures.overview/launch.pass.cpp Sat Jun 29 13:38:17 2013
@@ -17,11 +17,27 @@
// };
#include <future>
+#include <cassert>
int main()
{
+#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
static_assert(static_cast<int>(std::launch::any) ==
(static_cast<int>(std::launch::async) | static_cast<int>(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<int>(std::launch::async) == 1, "");
static_assert(static_cast<int>(std::launch::deferred) == 2, "");
}
More information about the cfe-commits
mailing list