[PATCH] Add std::__is_byte<std::byte> specialization

Jonathan Wakely jwakely@redhat.com
Wed Jun 27 10:30:00 GMT 2018


	* include/bits/cpp_type_traits.h [__cplusplus >= 201703]
	(__is_byte<byte>): Define specialization for std::byte.

This is used in <algorithm> to decide whether to optimize fills to
memset, so we want to enable it for std::byte.

It could also be used to simplify __is_byte_like in <functional>,
which I might do at a later date.

Tested x86_64-linux, committed to trunk.

-------------- next part --------------
commit 4f1f2fba9a43e5f63cb771f7c9c358734bbbd92a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jun 27 01:14:33 2018 +0100

    Add std::__is_byte<std::byte> specialization
    
            * include/bits/cpp_type_traits.h [__cplusplus >= 201703]
            (__is_byte<byte>): Define specialization for std::byte.

diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index ed6de4696c7..960d469f412 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -391,6 +391,17 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
       typedef __true_type __type;
     };
 
+#if __cplusplus >= 201703L
+  enum class byte : unsigned char;
+
+  template<>
+    struct __is_byte<byte>
+    {
+      enum { __value = 1 };
+      typedef __true_type __type;
+    };
+#endif // C++17
+
   //
   // Move iterator type
   //


More information about the Libstdc++ mailing list