[libcxx-commits] [PATCH] D122074: [libc++] Allow an output_iterator in fill.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 19 10:56:31 PDT 2022


Mordante created this revision.
Mordante added a reviewer: ldionne.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

This isn't required by the Standard but is an QoI extension.

This extension isn't only benificial for users but avoids code
duplication libc++. The ouput iterator in std::format only needs to
satisfy the output_iterator concept and not the Cpp17OutputIterator
requirements. This means a conforming std::format implementation can't
use the available algorithms and needs to write their own.

Note: This is the first patch, there will be follow-up patches making
this change to other algorithms.

Depends on D122072 <https://reviews.llvm.org/D122072>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122074

Files:
  libcxx/docs/UsingLibcxx.rst
  libcxx/include/__algorithm/fill_n.h
  libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp


Index: libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
===================================================================
--- libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
+++ libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
@@ -148,12 +148,22 @@
 int main(int, char**)
 {
     test_char<cpp17_output_iterator<char*> >();
+#if _LIBCPP_VERSION
+	// The iterator statisfies the output_iterator concept but not the
+	// Cpp17OutputIterator allowing this in <algorithm> is a libc++ extension.
+    test_char<cpp20_output_iterator<char*> >();
+#endif
     test_char<forward_iterator<char*> >();
     test_char<bidirectional_iterator<char*> >();
     test_char<random_access_iterator<char*> >();
     test_char<char*>();
 
     test_int<cpp17_output_iterator<int*> >();
+#if _LIBCPP_VERSION
+	// The iterator statisfies the output_iterator concept but not the
+	// Cpp17OutputIterator allowing this in <algorithm> is a libc++ extension.
+    test_int<cpp20_output_iterator<int*> >();
+#endif
     test_int<forward_iterator<int*> >();
     test_int<bidirectional_iterator<int*> >();
     test_int<random_access_iterator<int*> >();
Index: libcxx/include/__algorithm/fill_n.h
===================================================================
--- libcxx/include/__algorithm/fill_n.h
+++ libcxx/include/__algorithm/fill_n.h
@@ -34,7 +34,7 @@
 _OutputIterator
 fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
 {
-   return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value_);
+   return std::__fill_n(std::move(__first), std::__convert_to_integral(__n), __value_);
 }
 
 _LIBCPP_END_NAMESPACE_STD
Index: libcxx/docs/UsingLibcxx.rst
===================================================================
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -345,3 +345,19 @@
 * ``identity::operator()``
 * ``to_integer``
 * ``to_underlying``
+
+
+Lowered requirements of ``OutputIterator`` in ``<algorithm>``
+-------------------------------------------------------------
+
+In C++20 the Standard changed the iterator requirements, but the requirements
+for the iterators in ``<algorithm>`` remained unchanged. As an extension
+several algorithms in ``<algorithm>`` now only require the ``OutputIterator``
+to satisfy the ``output_iterator`` concept instead of the
+``Cpp17OutputIterator`` requirement. From a user's perspective the main change
+is that a movable non-copyable ``OutputIterator`` is now allowed in all
+language versions.
+
+Theses changes have been applied to the following algorithms:
+
+* ``fill_n``


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122074.416710.patch
Type: text/x-patch
Size: 2642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220319/5ddbb00c/attachment.bin>


More information about the libcxx-commits mailing list