[libcxx-commits] [libcxx] 71a16e4 - [libcxx] ostream{, buf}_iterator::difference_type changes in C++20

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 14 08:08:37 PDT 2020


Author: Louis Dionne
Date: 2020-09-14T11:08:09-04:00
New Revision: 71a16e40f78adee12663816edf6635b96dca09dc

URL: https://github.com/llvm/llvm-project/commit/71a16e40f78adee12663816edf6635b96dca09dc
DIFF: https://github.com/llvm/llvm-project/commit/71a16e40f78adee12663816edf6635b96dca09dc.diff

LOG: [libcxx] ostream{,buf}_iterator::difference_type changes in C++20

In C++20, since P0896R4, std::ostream_iterator and std::ostreambuf_iterator
must have std::ptrdiff_t instead of void as a difference_type.

Tests by Casey Carter (thanks!).

Differential Revision: https://reviews.llvm.org/D87459

Added: 
    

Modified: 
    libcxx/include/iterator
    libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
    libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/iterator b/libcxx/include/iterator
index a13214fca5e4..36571a50b8bc 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -1052,9 +1052,19 @@ class _LIBCPP_TEMPLATE_VIS ostream_iterator
     : public iterator<output_iterator_tag, void, void, void, void>
 {
 public:
-    typedef _CharT char_type;
-    typedef _Traits traits_type;
-    typedef basic_ostream<_CharT,_Traits> ostream_type;
+    typedef output_iterator_tag             iterator_category;
+    typedef void                            value_type;
+#if _LIBCPP_STD_VER > 17
+    typedef std::ptr
diff _t                  
diff erence_type;
+#else
+    typedef void                            
diff erence_type;
+#endif
+    typedef void                            pointer;
+    typedef void                            reference;
+    typedef _CharT                          char_type;
+    typedef _Traits                         traits_type;
+    typedef basic_ostream<_CharT, _Traits>  ostream_type;
+
 private:
     ostream_type* __out_stream_;
     const char_type* __delim_;
@@ -1151,10 +1161,20 @@ class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
     : public iterator<output_iterator_tag, void, void, void, void>
 {
 public:
-    typedef _CharT                          char_type;
-    typedef _Traits                         traits_type;
-    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
-    typedef basic_ostream<_CharT,_Traits>   ostream_type;
+    typedef output_iterator_tag                 iterator_category;
+    typedef void                                value_type;
+#if _LIBCPP_STD_VER > 17
+    typedef std::ptr
diff _t                      
diff erence_type;
+#else
+    typedef void                                
diff erence_type;
+#endif
+    typedef void                                pointer;
+    typedef void                                reference;
+    typedef _CharT                              char_type;
+    typedef _Traits                             traits_type;
+    typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
+    typedef basic_ostream<_CharT, _Traits>      ostream_type;
+
 private:
     streambuf_type* __sbuf_;
 public:

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
index 950c7dfe8c0b..739e39d62b78 100644
--- a/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
@@ -19,6 +19,7 @@
 //     typedef basic_istream<charT,traits> istream_type;
 //     ...
 
+#include <cstddef>
 #include <iterator>
 #include <type_traits>
 
@@ -33,7 +34,11 @@ int main(int, char**)
 #else
     static_assert((std::is_same<I1::iterator_category, std::output_iterator_tag>::value), "");
     static_assert((std::is_same<I1::value_type, void>::value), "");
+#if TEST_STD_VER <= 17
     static_assert((std::is_same<I1::
diff erence_type, void>::value), "");
+#else
+    static_assert((std::is_same<I1::
diff erence_type, std::ptr
diff _t>::value), "");
+#endif
     static_assert((std::is_same<I1::pointer, void>::value), "");
     static_assert((std::is_same<I1::reference, void>::value), "");
 #endif
@@ -47,7 +52,11 @@ int main(int, char**)
 #else
     static_assert((std::is_same<I2::iterator_category, std::output_iterator_tag>::value), "");
     static_assert((std::is_same<I2::value_type, void>::value), "");
+#if TEST_STD_VER <= 17
     static_assert((std::is_same<I2::
diff erence_type, void>::value), "");
+#else
+    static_assert((std::is_same<I2::
diff erence_type, std::ptr
diff _t>::value), "");
+#endif
     static_assert((std::is_same<I2::pointer, void>::value), "");
     static_assert((std::is_same<I2::reference, void>::value), "");
 #endif

diff  --git a/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
index 671a09bb7a3f..2a4e6ffa5e6b 100644
--- a/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
@@ -19,6 +19,7 @@
 //   typedef basic_ostream<charT, traits>   ostream_type;
 //   ...
 
+#include <cstddef>
 #include <iterator>
 #include <string>
 #include <type_traits>
@@ -34,7 +35,11 @@ int main(int, char**)
 #else
     static_assert((std::is_same<I1::iterator_category, std::output_iterator_tag>::value), "");
     static_assert((std::is_same<I1::value_type, void>::value), "");
+#if TEST_STD_VER <= 17
     static_assert((std::is_same<I1::
diff erence_type, void>::value), "");
+#else
+    static_assert((std::is_same<I1::
diff erence_type, std::ptr
diff _t>::value), "");
+#endif
     static_assert((std::is_same<I1::pointer, void>::value), "");
     static_assert((std::is_same<I1::reference, void>::value), "");
 #endif
@@ -50,7 +55,11 @@ int main(int, char**)
 #else
     static_assert((std::is_same<I2::iterator_category, std::output_iterator_tag>::value), "");
     static_assert((std::is_same<I2::value_type, void>::value), "");
+#if TEST_STD_VER <= 17
     static_assert((std::is_same<I2::
diff erence_type, void>::value), "");
+#else
+    static_assert((std::is_same<I2::
diff erence_type, std::ptr
diff _t>::value), "");
+#endif
     static_assert((std::is_same<I2::pointer, void>::value), "");
     static_assert((std::is_same<I2::reference, void>::value), "");
 #endif


        


More information about the libcxx-commits mailing list