aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/c_global
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-03-09 15:42:02 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2017-03-09 15:42:02 +0000
commite0472d7e8cefd8f4eed658424b8283fcd8ca4b15 (patch)
treebd1fef6b0530b3691d23d9b68d125ad7f1405b70 /libstdc++-v3/include/c_global
parent1f1fd3e2721cf68b2fe8b9516f260aee89872f60 (diff)
downloadgcc-e0472d7e8cefd8f4eed658424b8283fcd8ca4b15.zip
gcc-e0472d7e8cefd8f4eed658424b8283fcd8ca4b15.tar.gz
gcc-e0472d7e8cefd8f4eed658424b8283fcd8ca4b15.tar.bz2
Define std::byte for C++17 (P0298R3)
* doc/xml/manual/status_cxx2017.xml: Document std::byte support. * include/c_global/cstddef (std::byte): Define for C++17. * testsuite/18_support/byte/global_neg.cc: New test. * testsuite/18_support/byte/ops.cc: New test. * testsuite/18_support/byte/requirements.cc: New test. From-SVN: r246005
Diffstat (limited to 'libstdc++-v3/include/c_global')
-rw-r--r--libstdc++-v3/include/c_global/cstddef129
1 files changed, 129 insertions, 0 deletions
diff --git a/libstdc++-v3/include/c_global/cstddef b/libstdc++-v3/include/c_global/cstddef
index a571e80..09754ee 100644
--- a/libstdc++-v3/include/c_global/cstddef
+++ b/libstdc++-v3/include/c_global/cstddef
@@ -57,4 +57,133 @@ namespace std
}
#endif
+#if __cplusplus > 201402L
+namespace std
+{
+ /// std::byte
+ enum class byte : unsigned char {};
+
+ template<typename _IntegerType> struct __byte_operand;
+ template<> struct __byte_operand<bool> { using __type = byte; };
+ template<> struct __byte_operand<char> { using __type = byte; };
+ template<> struct __byte_operand<signed char> { using __type = byte; };
+ template<> struct __byte_operand<unsigned char> { using __type = byte; };
+#ifdef _GLIBCXX_USE_WCHAR_T
+ template<> struct __byte_operand<wchar_t> { using __type = byte; };
+#endif
+ template<> struct __byte_operand<char16_t> { using __type = byte; };
+ template<> struct __byte_operand<char32_t> { using __type = byte; };
+ template<> struct __byte_operand<short> { using __type = byte; };
+ template<> struct __byte_operand<unsigned short> { using __type = byte; };
+ template<> struct __byte_operand<int> { using __type = byte; };
+ template<> struct __byte_operand<unsigned int> { using __type = byte; };
+ template<> struct __byte_operand<long> { using __type = byte; };
+ template<> struct __byte_operand<unsigned long> { using __type = byte; };
+ template<> struct __byte_operand<long long> { using __type = byte; };
+ template<> struct __byte_operand<unsigned long long> { using __type = byte; };
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+ template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_0>
+ { using __type = byte; };
+ template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_0>
+ { using __type = byte; };
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+ template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_1>
+ { using __type = byte; };
+ template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_1>
+ { using __type = byte; };
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+ template<> struct __byte_operand<__GLIBCXX_TYPE_INT_N_2>
+ { using __type = byte; };
+ template<> struct __byte_operand<unsigned __GLIBCXX_TYPE_INT_N_2>
+ { using __type = byte; };
+#endif
+ template<typename _IntegerType>
+ struct __byte_operand<const _IntegerType>
+ : __byte_operand<_IntegerType> { };
+ template<typename _IntegerType>
+ struct __byte_operand<volatile _IntegerType>
+ : __byte_operand<_IntegerType> { };
+ template<typename _IntegerType>
+ struct __byte_operand<const volatile _IntegerType>
+ : __byte_operand<_IntegerType> { };
+
+ template<typename _IntegerType>
+ using __byte_op_t = typename __byte_operand<_IntegerType>::__type;
+
+ template<typename _IntegerType>
+ constexpr __byte_op_t<_IntegerType>&
+ operator<<=(byte& __b, _IntegerType __shift) noexcept
+ { return __b = byte(static_cast<unsigned char>(__b) << __shift); }
+
+ template<typename _IntegerType>
+ constexpr __byte_op_t<_IntegerType>
+ operator<<(byte __b, _IntegerType __shift) noexcept
+ { return byte(static_cast<unsigned char>(__b) << __shift); }
+
+ template<typename _IntegerType>
+ constexpr __byte_op_t<_IntegerType>&
+ operator>>=(byte& __b, _IntegerType __shift) noexcept
+ { return __b = byte(static_cast<unsigned char>(__b) >> __shift); }
+
+ template<typename _IntegerType>
+ constexpr __byte_op_t<_IntegerType>
+ operator>>(byte __b, _IntegerType __shift) noexcept
+ { return byte(static_cast<unsigned char>(__b) >> __shift); }
+
+ constexpr byte&
+ operator|=(byte& __l, byte __r) noexcept
+ {
+ return __l =
+ byte(static_cast<unsigned char>(__l) | static_cast<unsigned char>(__r));
+ }
+
+ constexpr byte
+ operator|(byte __l, byte __r) noexcept
+ {
+ return
+ byte(static_cast<unsigned char>(__l) | static_cast<unsigned char>(__r));
+ }
+
+ constexpr byte&
+ operator&=(byte& __l, byte __r) noexcept
+ {
+ return __l =
+ byte(static_cast<unsigned char>(__l) & static_cast<unsigned char>(__r));
+ }
+
+ constexpr byte
+ operator&(byte __l, byte __r) noexcept
+ {
+ return
+ byte(static_cast<unsigned char>(__l) & static_cast<unsigned char>(__r));
+ }
+
+ constexpr byte&
+ operator^=(byte& __l, byte __r) noexcept
+ {
+ return __l =
+ byte(static_cast<unsigned char>(__l) ^ static_cast<unsigned char>(__r));
+ }
+
+ constexpr byte
+ operator^(byte __l, byte __r) noexcept
+ {
+ return
+ byte(static_cast<unsigned char>(__l) ^ static_cast<unsigned char>(__r));
+ }
+
+ constexpr byte
+ operator~(byte __b) noexcept
+ { return byte(~static_cast<unsigned char>(__b)); }
+
+ template<typename _IntegerType>
+ constexpr _IntegerType
+ to_integer(__byte_op_t<_IntegerType> __b) noexcept
+ { return _IntegerType(__b); }
+
+} // namespace std
+#endif
+
#endif // _GLIBCXX_CSTDDEF