[libcxx-commits] [libcxx] [libcxx] Added segmented iterator for count_if (PR #105888)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 9 10:19:26 PDT 2024


adeel10x wrote:

> > > Benchmark compilation was failing due to this error:
> > > ```
> > > [1/2] /home/adeel/llvm-project/build/bin/clang++   -Wno-unused-command-line-argument -nostdinc++ -isystem /home/adeel/Desktop/llvm-project/build/include/c++/v1 -L/home/adeel/Desktop/llvm-project/build/lib -Wl,-rpath,/home/adeel/Desktop/llvm-project/build/lib  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Wold-style-cast  -Werror  -Wsuggest-override  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wthread-safety  -stdlib=libc++  -std=c++11 -MD -MT CMakeFiles/cmTC_8bf2e.dir/posix_regex.cpp.o -MF CMakeFiles/cmTC_8bf2e.dir/posix_regex.cpp.o.d -o CMakeFiles/cmTC_8bf2e.dir/posix_regex.cpp.o -c /home/adeel/Desktop/llvm-project/third-party/benchmark/cmake/posix_regex.cpp
> > > FAILED: CMakeFiles/cmTC_8bf2e.dir/posix_regex.cpp.o
> > > /home/adeel/llvm-project/build/bin/clang++   -Wno-unused-command-line-argument -nostdinc++ -isystem /home/adeel/Desktop/llvm-project/build/include/c++/v1 -L/home/adeel/Desktop/llvm-project/build/lib -Wl,-rpath,/home/adeel/Desktop/llvm-project/build/lib  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Wold-style-cast  -Werror  -Wsuggest-override  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wthread-safety  -stdlib=libc++  -std=c++11 -MD -MT CMakeFiles/cmTC_8bf2e.dir/posix_regex.cpp.o -MF CMakeFiles/cmTC_8bf2e.dir/posix_regex.cpp.o.d -o CMakeFiles/cmTC_8bf2e.dir/posix_regex.cpp.o -c /home/adeel/Desktop/llvm-project/third-party/benchmark/cmake/posix_regex.cpp
> > > In file included from /home/adeel/Desktop/llvm-project/third-party/benchmark/cmake/posix_regex.cpp:2:
> > > In file included from /home/adeel/Desktop/llvm-project/build/include/c++/v1/string:647:
> > > In file included from /home/adeel/Desktop/llvm-project/build/include/c++/v1/string_view:958:
> > > In file included from /home/adeel/Desktop/llvm-project/build/include/c++/v1/algorithm:1832:
> > > /home/adeel/Desktop/llvm-project/build/include/c++/v1/__algorithm/count_if.h:28:56: error: 'auto' not allowed in lambda parameter before C++14
> > >    28 |   std::for_each(__first, __last, [&__r, &__pred](const auto& __val) mutable {
> > >       |                                                        ^~~~
> > > 1 error generated.
> > > ninja: build stopped: subcommand failed.
> > > ```
> > > 
> > > 
> > >     
> > >       
> > >     
> > > 
> > >       
> > >     
> > > 
> > >     
> > >   
> > > So, I guess I can't use `auto` for lambda parameter type here.
> > > ```
> > > * For segmented iterators, the lambda argument type would be:`const iterator_traits<Traits::__local_iterator>::value_type&` where Traits is `__segmented_iterator_traits<_SegmentedIterator>`,
> > > 
> > > * For others, it would be: `const iterator_traits<_InputIterator>::value_type&`
> > >   Should I create separate template functions for segmented and non-segmented iterators to implement this? Just like I had earlier...
> > > ```
> > 
> > 
> > You should be able to use `[]<class _Tp>(const _Tp&) mutable {...}`.
> 
> Can we use the template parameter with lambda expressions before C++20? Many files are being compiled with `-std=c++11`. I am getting a different error again.

This is the command that causes clang crash:
```Program arguments: /home/adeel/llvm-project/build/bin/clang++ -DBENCHMARK_HAS_PTHREAD_AFFINITY -DBENCHMARK_STATIC_DEFINE -DHAVE_POSIX_REGEX -DHAVE_PTHREAD_AFFINITY -DHAVE_STD_REGEX -DHAVE_STEADY_CLOCK -DHAVE_THREAD_SAFETY_ATTRIBUTES -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/home/adeel/llvm-project/third-party/benchmark/include -I/home/adeel/llvm-project/third-party/benchmark/src -Wno-unused-command-line-argument -nostdinc++ -isystem /home/adeel/llvm-project/build2/include/c++/v1 -L/home/adeel/llvm-project/build2/lib -Wl,-rpath,/home/adeel/llvm-project/build2/lib -Wall -Wextra -Wshadow -Wfloat-equal -Wold-style-cast -Werror -Wsuggest-override -pedantic -pedantic-errors -Wshorten-64-to-32 -fstrict-aliasing -Wno-deprecated-declarations -Wno-deprecated -Wstrict-aliasing -Wthread-safety -stdlib=libc++ -O3 -DNDEBUG -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT src/CMakeFiles/benchmark.dir/statistics.cc.o -MF src/CMakeFiles/benchmark.dir/statistics.cc.o.d -o src/CMakeFiles/benchmark.dir/statistics.cc.o -c /home/adeel/llvm-project/third-party/benchmark/src/statistics.cc
```


https://github.com/llvm/llvm-project/pull/105888


More information about the libcxx-commits mailing list