A library for C++20 that introduced std::ranges namespace, which consists of rangified algorithms from
Questions tagged [std-ranges]
379 questions
0
votes
1 answer
std::ranges::take_while_view cannot pipe
auto int_v10 = std::vector{8,7,3};
//fail auto rng2 = int_v10 | std::ranges::take_while_view([](int x) {return x> 5;} ) | std::ranges::views::common;
auto rng2 = int_v10 | std::ranges::views::take_while([](int x) {return x> 5;} ) |…

jian
- 4,119
- 1
- 17
- 32
0
votes
1 answer
Generic ranges-compatible functions
I have a function that operates on standard iterators of a common type:
template
bool next_combination(const I first, I k, const I last)
I'm trying to use it with std::ranges::views, but I'm not able to pass its iterators as input…

Jonas Hjulstad
- 395
- 1
- 8
0
votes
0 answers
Split json like string with C++20 ranges/views
I have the following string:
std::string ob = R"({ "U" : 972448093270,"u" : 972448098626,"pu" : 972448093117,"b" :…

Eduard Rostomyan
- 7,050
- 2
- 37
- 76
0
votes
1 answer
Why does ITER_CONCEPT befog iterator_traits::iterator_concept/category?
According to the [iterator.concepts.general]:
Otherwise, if iterator_traits names a specialization generated from the primary template, then
ITER_CONCEPT(I) denotes random_access_iterator_tag.
ITER_CONCEPT(I) may be…

a.tana
- 41
- 7
0
votes
1 answer
How can I transform int to string then join with std::ranges::views?
#include
#include
#include
#include
#include
#include
int main() {
auto str = (
std::views::iota(1)
| std::ranges::views::take(5)
|…

lunuy lunuy
- 429
- 3
- 7
0
votes
1 answer
C++20 ranges custom view: Error when trying to pipe into another view
I am trying to implement a custom view but getting compile time errors when trying to pipe another view into my custom view.
The code I implemented is an aggregation of this talk from CppCon2019 by Chris Di Bella and this blog post by Marius…

serkan.tuerker
- 1,681
- 10
- 20
0
votes
1 answer
Flatten nested for loops with C++20 ranges
Sometimes I need to "double for loop" and since I do nothing in outer for loop for first loop variable beside passing it to inner for loop I wonder if it can be done elegantly with C++20 ranges.
Example of nested for loops I would like to…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
0
votes
1 answer
Why does basic_istream_view inherit view_interface?
basic_istream_view is a simple input_range in C++20 and has only one begin() and end() function:
template
requires default_initializable &&
stream-extractable
class…

康桓瑋
- 33,481
- 5
- 40
- 90
0
votes
1 answer
How to join range of ranges?
How to join range of ranges?
auto points() const
{
auto ranges = children() | std::views::transform([](auto child) { return child->points(); });
return std::views::join(ranges);
}
Can`t use points at
for(auto& pt:…

Jevs
- 25
- 5
0
votes
1 answer
Using filter on vector of variant
I am trying to iterate over filtered (by type) std::vector>.
Problem I hit is that the std::get is overloaded function(and has many implicit template args I need to type out) so I would need to cast it to something specific.
This…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
0
votes
1 answer
Range-v3, how to access a range of a range value individually (group_by function)
I'm using range-v3 by Eric Niebler and using the ranges::views::group_by function.
In the documentation for group_by it says: "Given a source range and a binary predicate, return a range of ranges where each range contains contiguous elements from…

Andrew
- 626
- 6
- 16
0
votes
1 answer
C++ 20 ranges custom sortable container error : candidate template ignored: constraints not satisfied [with _Range = ...] operator()(..) const
I wrote a simple class template wrapping around a raw array just to play with the C++ 20 ranges library and wanted it to support random access iterators and make it work with std::ranges::sort.
#ifndef BOX_CONTAINER_H
#define…

musimbate
- 347
- 6
- 25
0
votes
1 answer
Ranges-v3 combination producing errors when using ranges::views::counted(1)
I'm using the ranges library (eric niebler ranges) and I'm trying to write a ranges combination but the ranges::views::counted(1) option I'm using doesn't work.
I'm trying to ignore from the right, to the target time minus 1 further period (5mins).…

Andrew
- 626
- 6
- 16
0
votes
2 answers
Why can't compile std::views::take(std::uint64_t{})?
#include
#include
int main()
{
auto const il = {1, 2, 3, 4, 5, 6};
auto const n1 = std::int32_t{3};
auto const n2 = std::uint32_t{3};
auto const n3 = std::int64_t{3};
auto const n4 = std::uint64_t{3};
il…

xmllmx
- 39,765
- 26
- 162
- 323
0
votes
1 answer
Why C++20 filter_view has a .size member function?
I found this on cppreference:
Following types are derived from std::ranges::view_interface and do
not declare their own size member function, but they cannot use the
default implementation, because their iterator and sentinel types
never satisfy…

NoSenseEtAl
- 28,205
- 28
- 128
- 277