Skip to main content
Filter by
Sorted by
Tagged with
4 votes
2 answers
160 views

I am implementing type-erased iterators for code that uses std::views and have found a problem while trying to compare values that wrap sentinels. Basically, it seems that for some composition of ...
Krzysiek Karbowiak's user avatar
21 votes
4 answers
2k views

I have three std::vectors, std::vector<std::string> vec1{ "one", "two", "three" }; std::vector<std::string> vec2{ "1", "2", "3" }...
RocketSearcher's user avatar
4 votes
1 answer
129 views

Consider this C++23 example: #include <ranges> #include <print> #include <vector> namespace r = std::ranges; namespace rv = std::ranges::views; std::vector<int> ...
jwezorek's user avatar
  • 10k
-3 votes
1 answer
209 views

I'm trying to iterate through a text file's lines using ranges: auto iter_lines(std::ifstream& file) { auto lines = std::ranges::istream_view<char>(file) | std::views::lazy_split(...
aviad1's user avatar
  • 376
2 votes
2 answers
141 views

I'm trying to do something like this: const std::map<char, int> histogram{ {'A', 2}, {'D', 1}, {'M', 1}, }; for (const auto& [index, key, value] : std::views::enumerate(...
Adam Badura's user avatar
  • 5,533
5 votes
1 answer
181 views

This works, but is it legal/safe? (i.e.: Is it okay to pass projection as predicate argument to std::ranges::any_of/all_of/none_of?) #include <ranges> #include <iostream> #include <...
Garux's user avatar
  • 83
1 vote
1 answer
134 views

The following code does not compile. #include <iostream> #include <memory> #include <ranges> #include <vector> class Base { public: virtual ~Base() = default; ...
Krzysiek Karbowiak's user avatar
1 vote
0 answers
57 views

What is the category of std::views::transform based on a std::vector? What is the category of the view's iterator in the following code? #include <iterator> #include <memory> #include <...
Krzysiek Karbowiak's user avatar
5 votes
1 answer
167 views

The libstdc++ implementation of std::ranges::ref_view, following the C++ standard, includes the following code: template<range _Range> requires is_object_v<_Range> class ref_view : ...
Fei Du's user avatar
  • 80
6 votes
1 answer
292 views

C++20 adds numerous std::views::... range adaptors. When applied to a range, do they store a copy of the range, or a reference to it? In other words: std::vector<A> v; for (const auto &elem :...
HolyBlackCat's user avatar
1 vote
1 answer
125 views

I want to transform std::vector<A> to std::vector<B> using std::ranges::transform(R&& r, O result, F op, Proj proj = {}), but I have no post-transform functor op. It seems to work ...
janp's user avatar
  • 255
0 votes
0 answers
91 views

tl;dr Given this code: #include <functional> #include <optional> #include <range/v3/range/conversion.hpp> #include <range/v3/range/primitives.hpp> #include <range/v3/view/...
Enlico's user avatar
  • 30.3k
2 votes
1 answer
283 views

Here's the minimal example: #include <vector> #include <ranges> #include <range/v3/range/conversion.hpp> #include <range/v3/view/enumerate.hpp> int main() { std::vector&...
Enlico's user avatar
  • 30.3k
4 votes
2 answers
183 views

In the C++26-adopted proposal p2542, i.e. std::views::concat, there is a confusing statement: The member typedef-name iterator_category is defined if and only if all-forward<Const, Views...> is ...
xmllmx's user avatar
  • 44.6k
-1 votes
1 answer
164 views

Consider the following code snippet (full code: https://godbolt.org/z/PMM4z9KvM): int main() { { std::cout << "begin std::views::as_rvalue\n"; auto iss = std::...
xmllmx's user avatar
  • 44.6k
8 votes
2 answers
264 views

In C++23, std::views::adjacent<N> provides a sliding window of N elements over a range. Its iterator typically stores N iterators to the underlying range. When implementing this iterator's ...
zwhconst's user avatar
  • 1,647
3 votes
2 answers
153 views

Consider the following snippet: // included, for exposition only SomeData buzz(std::string_view); constexpr auto foo(std::string_view v) { using namespace std::string_view_literals; return v ...
Sergey Kolesnik's user avatar
4 votes
1 answer
131 views

I am trying to bind a std::generator<T> to a Python generator through pybind11, I am using the following currently: #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include ...
Holt's user avatar
  • 38.1k
4 votes
2 answers
193 views

In the code below std::ranges::minmax_element return iterators on a temporary view. In the next line the iterator is dereferenced. Copilot claims that the code is safe because the lifetime of the ...
Joseph Perez's user avatar
2 votes
1 answer
190 views

I have the following code, and I can not flatten the nested range using std::views::join template<typename T> consteval auto get_names() { using get_fn = decltype( [] { auto ...
NoSenseEtAl's user avatar
  • 30.9k
3 votes
1 answer
178 views

The following code compiles: #if 0 /* g++ -std=c++23 $0 -o exe \ -Wall -Werror -Wextra -Wsign-conversion -pedantic-errors \ && ./exe $@ RET=$? rm -f exe exit $RET */ #endif #include <...
Adam Barnes's user avatar
  • 3,283
0 votes
0 answers
97 views

I'm trying to provide different searching ranges for my searching function : //In a function that returns a view of std::vector ... if(mode == 0) // filter some elements return my_vector | std::...
hu4nghe's user avatar
1 vote
2 answers
105 views

The code: #include <algorithm> #include <ranges> #include <vector> #include <tuple> #include <generator> #include <cstdio> #include <iostream> using ...
Ludovic Aubert's user avatar
1 vote
1 answer
144 views

I'm writing a C++23 program and trying to create a recursive data structure with help from std::ranges::transform_view. However, it seems like the requires clauses on the std::ranges::transform_view ...
LB--'s user avatar
  • 3,228
2 votes
2 answers
118 views

Is it possible to have a range of generators and if yes, is it possible to join them ? #include <algorithm> #include <ranges> #include <vector> #include <cstdio> #include <...
Ludovic Aubert's user avatar
3 votes
1 answer
119 views

I want a view of the characters from an input stream: auto input = std::stringstream{"abcd"}; using Iter = std::istreambuf_iterator<char>; auto s = std::ranges::subrange{...
Toby Speight's user avatar
  • 32.3k
4 votes
1 answer
199 views

The code below breaks at last line as joined view v isn't a random access range. vector<string> v0 = {"word","good","best","good"}; auto it = v0.begin() + ...
ephemerr's user avatar
  • 2,087
5 votes
1 answer
304 views

I need to port some code from C++ 23 which uses std::views::zip/keys to C++ 20 (porting to CUDA) (which doesn’t have std::views::zip) having only one specific use case of this code. I have data in one ...
Damir Tenishev's user avatar
8 votes
2 answers
205 views

I was experimenting with std::iterator_traits and std::views::iota. And suddenly I found out that std::iterator_traits returns unexpected type for an iterator category. libc++: #include <ranges> ...
Георгий Гуминов's user avatar
9 votes
1 answer
239 views

I have been playing around with std::ranges::views and have noticed that every chained view gets bigger. For view iterators this pattern is simple, each is always 8 byte bigger than the one before. ...
Dominik Kaszewski's user avatar
2 votes
0 answers
160 views

given the following MWE #include <iostream> #include <vector> #include <ranges> #include <algorithm> #include <numeric> namespace{ auto doSomething(const bool b) { ...
RocketSearcher's user avatar
1 vote
2 answers
201 views

I have the need to map some elements to certain ids, elementId's to starting node ids in a graph. I need to store just ids of the elements so generally we could work with just sets or vectors of ...
Carlos's user avatar
  • 307
21 votes
2 answers
1k views

I decided to use std::views stuff because of their bound-safety and readability. It looks like std::views::take_while invokes too many function calls and recomputes the same thing over and over again. ...
Ali's user avatar
  • 319
2 votes
1 answer
418 views

I would like to have this code with std::vector replaced with std::array, but I presume it can not be done since std::array is not a container std::ranges::to understands. constexpr auto dice = std::...
NoSenseEtAl's user avatar
  • 30.9k
0 votes
1 answer
134 views

This is a follow-up to Debug assertion while iterating over composed views. I replaced problematic transform_view with a loop and the debug assertion was gone. Then I added a filter and the problem is ...
Krzysiek Karbowiak's user avatar
6 votes
1 answer
125 views

I know that modifying the target of filter_­view​::​iterator is allowed, but if the resulting value does no longer satisfy the filter predicate this results in undefined behaviour. What about the ...
Krzysiek Karbowiak's user avatar
5 votes
0 answers
45 views

The range-v3 library complains if I try to feed an r-value to the pipe operator: #include <iostream> #include <range/v3/view/transform.hpp> #include <vector> std::vector<int> ...
antonio's user avatar
  • 483
2 votes
2 answers
111 views

I have two maps. One (A) is maps unique identifiers to allocated resources. The other (B) maps unique identifiers to resource prototypes. I would like to take the two maps and find the items that are ...
Steven's user avatar
  • 720
4 votes
3 answers
169 views

I need sometimes to filter some types from a given parameter pack and get the result as a std::tuple. For instance, it can be a filter based on the index of the types in the pack. As an example, here ...
abcdefg's user avatar
  • 4,637
1 vote
2 answers
150 views

We want to implement a tree of items: +----------------------+ | Item (interface) | +----------------------+ | + getName(): string |-----------+ +---------------...
Amir Kirsh's user avatar
  • 14.4k
3 votes
1 answer
99 views

I have a simple SequencesRange class that can iterate random genomic sequences of fixed size. When I try to join the characters of all sequences with std::views::join, it works well, but as soon I try ...
abcdefg's user avatar
  • 4,637
4 votes
1 answer
130 views

For zipping ranges together, we have std::views::zip and friends. Is there a way to "unzip" a range, i.e. write the following "index filter" function as a range expression? auto ...
rubenvb's user avatar
  • 77.2k
2 votes
0 answers
132 views

I want to pass a std::ranges::view to a function which is an implementation of an interface, without creating a new vector and allocating more memory. virtual void doSomethingWithInts(std::ranges::...
A-_-S's user avatar
  • 878
4 votes
1 answer
240 views

C++23 gives us the long-missing std::views::zip (and friendly helpers like std::views::zip_transform) which gives a handy way to take values from multiple ranges and do something with those sets of ...
rubenvb's user avatar
  • 77.2k
14 votes
1 answer
414 views

My colleague ports a C++ program with ranges on macOS, and observes an unexpected compilation error. After maximum simplification, the example program looks like this: #include <optional> #...
Fedor's user avatar
  • 24.7k
0 votes
2 answers
176 views

I am going through 'Functional Programming in C++' (yes, it is getting a bit long in the tooth, but it is what I have right now), and I am trying to convert some of the examples in it to C++20 (g++ 13....
melston's user avatar
  • 2,374
0 votes
1 answer
103 views

Why can't I (re)assign the value for a view with the same type of the view? Demo: https://godbolt.org/z/aqdh7ohva #include <iostream> #include <ranges> #include <vector> int main() {...
Damir Tenishev's user avatar
2 votes
2 answers
104 views

I have a filter which should be conditionally applied to some range and the condition is known at execution time only. I can do this easy, putting the condition in the filter, but this leads to high ...
Damir Tenishev's user avatar
1 vote
2 answers
113 views

I am working with the ranges library and pipelines to read CSV files. My code works okay except when I add ranges::to<std::vector> at the end of the pipeline. With the 'to' added, the last line ...
Rud48's user avatar
  • 1,120
4 votes
1 answer
159 views

I have the following test program: #include <vector> #include <print> #include <ranges> int main() { const std::vector<int> input = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; ...
Tomas Andrle's user avatar
  • 13.4k

1
2 3 4 5
13