15,026 questions
3
votes
2
answers
232
views
Is it ok to write `&*string.end()`?
I see many places in public repositories, where the first and last iterators of std::vector/std::string/std::string_view are converted into pointers using the combination of &* operators. In ...
0
votes
2
answers
130
views
How can I force iterator blocks to validate parameters before packing up and returning as a continuation?
Situation: A method that validates its arguments and returns an iterator;
public static IEnumerable<double> Range(double startingValue, double step, int count)
{
// I would really like this ...
2
votes
1
answer
154
views
Are the iterators of `map<key, value, greater<>>` and `map<key, value, less<>>` guaranteed to be the same type?
I have 2 maps
using BidBook = std::map<float, int, std::greater<>>; // price -> qty
using AskBook = std::map<float, int, std::less<>>;
I have a struct that contain iterator ...
2
votes
1
answer
101
views
OpenMP in C | How to keep private iterable after loop
So i'm working on some homework related to fixing som buggy code when i ran into an interesting problem. I don't think it was one of the indended bugs because the lecturer was confused by it as well. ...
0
votes
0
answers
37
views
How do I use str::split and str::split_whitespace in the arms of a match expression in Rust [duplicate]
I have some code that splits a string and then does some processing on each part of the string, before returning Vec of values based on each segment. By default, the code should split the string by ...
1
vote
1
answer
80
views
Shallow copying enumeration iterator behavior in Python
I am trying to understand the behavior of iterators in Python, particularly when using the copy.copy() and copy.deepcopy() functions. I have the following script:
import copy
my_list = ["a",...
4
votes
2
answers
220
views
Can the back() iterator of a vector be safely assumed to be the end() iterator after a pop_back()?
My problem is the following :
std::vector<struct pollfd> vec = { ... }; // Actually a member variable on a Server object
for (auto iter = vec.begin(); iter != vec.end(); ) {
if (...
1
vote
1
answer
130
views
Why does passing a Map.entries() iterator as child to a Collaspsible from shadcn render nothing unless I wrap it with Array.from()?
I’m using shadcn/ui with Radix UI’s Collapsible to make a collapsible filter section.
Wrapper component:
import { ReactNode, useEffect, useState } from "react";
import { Collapsible, ...
4
votes
2
answers
183
views
Why is `iterator_category` deleted in `std::views::concat::iterator` if it's a pure input iterator?
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 ...
0
votes
3
answers
211
views
Confusion about invalidated iterators
If vectors are stored contiguously, as long as they are not made smaller or reallocated, any iterator pointing to an element within it should be valid. The following code would be defined:
#include &...
0
votes
2
answers
82
views
How to write a fold method for an iterator in a language without mutability?
Suppose you had a programming language in which all variables are immutable. Modifying iterables could be accomplished by providing a magic variable that is immutable during an iteration step, but ...
1
vote
1
answer
78
views
Check if all elements in vector fall within specified range
I have x_min and x_max, both i16 and x_coordinates, which is a Vec<i16>.
Now, I want to check whether every x_coordinate lies between x_min and x_max.
I came up with the following solution, ...
2
votes
1
answer
194
views
Is performance of std::rotate hampered by the iterator interface?
While standard algorithms should be as optimized as possible based on the iterator category, it seems to me like a lot of performance is left on the table by not being able to consider the underlying ...
2
votes
2
answers
70
views
Is there a way to release and recapture references in closures while iterating?
I have code analogous to:
struct L {
length: usize,
count: usize,
}
impl L {
fn iter(&self, ns: impl Iterator<Item=usize>) -> impl Iterator<Item=usize> {
ns....
-3
votes
1
answer
109
views
iterator and iterable classes in python
Why do we return self in the iter method when we define the next method in the iterable and iterator classes?
This topic was taught in the course, but it was hard to understand and I didn't understand ...
4
votes
2
answers
153
views
Why doesn't range-based for loop match rvalue-reference modifier of this?
#include <vector>
class MyContainer {
public:
std::vector<int> data;
// begin() only defined for rvalues
auto begin() && { return data.begin(); }
auto end() &&...
-2
votes
2
answers
92
views
Iterate over an object that is not an iterator
I'm not sure why I can iterate over an object that is not an iterator?
>>> import spacy
>>> nlp = spacy.load("en_core_web_sm") ...
0
votes
2
answers
58
views
Iterating over a reference multiple times over an arbitrary iterator
The following code works:
fn do_it_fun<I>(words: Vec<&str>, inputs: I)
where I: AsRef<[&'static str]>
{
for word in words {
if inputs.as_ref().into_iter()...
4
votes
2
answers
135
views
C++ function parameter that only accepts iterator to a specific type
I know I can use a template to make a constructor which accepts any type of iterator like this:
struct Thing
{
std::vector<int> integers;
std::list<std::string> strings;
template &...
2
votes
2
answers
186
views
Does the standard require `operator->()` to be defined for past-the-end non-contiguous iterators?
Does the standard require that operator->() is defined for non-contiguous past-the-end iterators?
Background:
Regardless of the iterator category, it is allowed for operator*() to exhibit ...
0
votes
2
answers
184
views
Is there an idiomatic way to partition a Rust iterator into multiple iterators by Enum variant?
I am struggling to find a clean/idiomatic approach to partition an iterator into a fixed number of sub parts based on Enum variants.
Example
enum State {
A(A),
B(B),
C(C),
}
let states = vec!...
4
votes
1
answer
103
views
Java iterator of regex matches from large source
The basic problem is that I need to output all matches of a regex within a file, but there's a few properties that make a solution tricky:
The file could be very large, so the whole file cannot be ...
-2
votes
1
answer
79
views
Java Iterator Views
I frequently would like to iterate over a view of some underlying data structure, e.g. a backwards iteration or only a slice of a list. The Java standard library has some support for multiple iterator ...
1
vote
1
answer
152
views
Can `std::unordered_map::iterator` be implemented without reference to underlying map?
A while back I ported some of the C++ stdlib containers to environment where stdlib was not available. While iterators for contiguous and node-based containers were easy, I was stumped how to ...
2
votes
1
answer
101
views
Why is STL common_iterator's `operator*()` method not always const qualified?
In libstdc++ there is the following code:
class common_iterator
{
...
[[nodiscard]]
constexpr decltype(auto)
operator*()
{
__glibcxx_assert(_M_index == 0);
return *...