[libcxx-commits] [PATCH] D151274: [libc++] Optimize for_each for segmented iterators

Stephan Bergmann via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 5 04:39:25 PDT 2023


sberg added a comment.

this causes

  $ cat test.cc
  #include <algorithm>
  #include <deque>
  void f(std::deque<int> & v) {
      std::for_each(v.begin(), v.end(), [&](int) {});
  }

  $ clang++ -std=c++20 -fsyntax-only test.cc
  In file included from test.cc:1:
  In file included from ~/llvm/inst/bin/../include/c++/v1/algorithm:1758:
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:39:12: error: object of type '(lambda at test.cc:4:39)' cannot be assigned because its copy assignment operator is implicitly deleted
     39 |     __func = std::for_each(__lfirst, __llast, std::move(__func));
        |            ^
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each_segment.h:35:5: note: in instantiation of function template specialization 'std::for_each(std::__deque_iterator<int, int *, int &, int **, long>, std::__deque_iterator<int, int *, int &, int **, long>, (lambda at test.cc:4:39))::(anonymous class)::operator()<int *, int *>' requested here
     35 |     __func(_Traits::__local(__first), _Traits::__local(__last));
        |     ^
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:8: note: in instantiation of function template specialization 'std::__for_each_segment<std::__deque_iterator<int, int *, int &, int **, long>, (lambda at ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44)>' requested here
     38 |   std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
        |        ^
  test.cc:4:10: note: in instantiation of function template specialization 'std::for_each<std::__deque_iterator<int, int *, int &, int **, long>, (lambda at test.cc:4:39)>' requested here
      4 |     std::for_each(v.begin(), v.end(), [&](int) {});
        |          ^
  test.cc:4:39: note: lambda expression begins here
      4 |     std::for_each(v.begin(), v.end(), [&](int) {});
        |                                       ^
  In file included from test.cc:1:
  In file included from ~/llvm/inst/bin/../include/c++/v1/algorithm:1743:
  In file included from ~/llvm/inst/bin/../include/c++/v1/__algorithm/copy.h:13:
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each_segment.h:40:3: error: no matching function for call to object of type '(lambda at ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44)'
     40 |   __func(_Traits::__local(__first), _Traits::__end(__sfirst));
        |   ^~~~~~
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:8: note: in instantiation of function template specialization 'std::__for_each_segment<std::__deque_iterator<int, int *, int &, int **, long>, (lambda at ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44)>' requested here
     38 |   std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
        |        ^
  test.cc:4:10: note: in instantiation of function template specialization 'std::for_each<std::__deque_iterator<int, int *, int &, int **, long>, (lambda at test.cc:4:39)>' requested here
      4 |     std::for_each(v.begin(), v.end(), [&](int) {});
        |          ^
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44: note: candidate template ignored: substitution failure [with __lfirst:auto = __local_iterator, __llast:auto = __local_iterator]
     38 |   std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
        |                                            ^
  In file included from test.cc:1:
  In file included from ~/llvm/inst/bin/../include/c++/v1/algorithm:1743:
  In file included from ~/llvm/inst/bin/../include/c++/v1/__algorithm/copy.h:13:
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each_segment.h:44:5: error: no matching function for call to object of type '(lambda at ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44)'
     44 |     __func(_Traits::__begin(__sfirst), _Traits::__end(__sfirst));
        |     ^~~~~~
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44: note: candidate template ignored: substitution failure [with __lfirst:auto = __local_iterator, __llast:auto = __local_iterator]
     38 |   std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
        |                                            ^
  In file included from test.cc:1:
  In file included from ~/llvm/inst/bin/../include/c++/v1/algorithm:1743:
  In file included from ~/llvm/inst/bin/../include/c++/v1/__algorithm/copy.h:13:
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each_segment.h:48:3: error: no matching function for call to object of type '(lambda at ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44)'
     48 |   __func(_Traits::__begin(__sfirst), _Traits::__local(__last));
        |   ^~~~~~
  ~/llvm/inst/bin/../include/c++/v1/__algorithm/for_each.h:38:44: note: candidate template ignored: substitution failure [with __lfirst:auto = __local_iterator, __llast:auto = __local_iterator]
     38 |   std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
        |                                            ^
  4 errors generated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151274/new/

https://reviews.llvm.org/D151274



More information about the libcxx-commits mailing list