Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
273 views

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 ...
Fedor's user avatar
  • 24.7k
0 votes
0 answers
166 views

it -> a random valid vector iterator const int kLookAheadIndex -> a random number auto it_ahead = std::max(it - kLookAheadIndex, path.cbegin()); // get a look-ahead point to look at I know ...
Bill Kotsias's user avatar
  • 3,420
0 votes
2 answers
135 views

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 ...
Joachim J's user avatar
  • 204
Best practices
0 votes
4 replies
94 views

I have to implement an Iterator<E> that needs to internally iterate through multiple private iterators at different levels. For example, an Iterator<A>, an Iterator<B>, and an ...
Matthew McPeak's user avatar
2 votes
1 answer
181 views

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 ...
Huy Le's user avatar
  • 1,989
Best practices
1 vote
7 replies
117 views

Our program reads results of an SQL query and turns each row into a task for a worker to perform. Something like: for row in query.results(): cluster.submit(row) However, most of the tasks are so ...
Mikhail T.'s user avatar
  • 4,266
2 votes
1 answer
108 views

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. ...
Tuned Rockets's user avatar
4 votes
2 answers
127 views

I am trying to implement a display driver wrapper in (no_std) Rust, that is responsible to write an sequence of pixels into a frame buffer. The pixel data is coming from the C world, and representing ...
Holger's user avatar
  • 31
0 votes
0 answers
37 views

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 ...
Elliot Hatch's user avatar
  • 1,220
0 votes
0 answers
59 views

I have a piece of text with delimiters in it. I need to extract words from it and convert them to lower case. My approach is to use regular expressions to split the text and use transform to convert ...
flashburn's user avatar
  • 4,698
1 vote
1 answer
80 views

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",...
shannu_boi's user avatar
-5 votes
1 answer
143 views

I made the next class obj = MyClass() fds=['a','b','c'] for i in fds: attribute_name = f"{i}" setattr(obj, attribute_name, [f"{i}"]) print(obj.i) I know that obj.i is ...
Javier Olivares's user avatar
4 votes
2 answers
220 views

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 (...
Azyrod's user avatar
  • 151
2 votes
1 answer
88 views

I have the following Rust function fn query_list_or_empty<'a, P, R>( conn: &'a mut SimpleConnection, sql: &'a str, params: P, ) -> Peekable<Box<dyn Iterator<Item =...
Roeya's user avatar
  • 91
1 vote
1 answer
130 views

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, ...
musketeerdt's user avatar
1 vote
1 answer
159 views

I found this question here but that one doesn't really answer my question due to it having an answer centered around unwrap_or_else. Here is the code I am trying to use, simplified: let x = loop { ...
theKMan747's user avatar
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
4 votes
1 answer
156 views

✔ 1. This, with iterator object, works: let m = n => n * 2; let it1 = [1, 2, 3].values (); let [a1] = it1.map (m), [...b1] = it1.map (m); console.log (a1 + '', b1 + ''); // '2', '4,6' ✘ 2. ...
Venkata Raju's user avatar
  • 5,391
0 votes
3 answers
213 views

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 &...
BadUsername's user avatar
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
0 votes
2 answers
84 views

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 ...
Armin Repsold's user avatar
1 vote
1 answer
69 views

I'm working on a C++ project where I have an abstract base class Store that represents a container of Bin objects. Each subclass of Store (e.g., DenseStore, SparseStore) uses a different internal data ...
Andrea Novellini's user avatar
1 vote
1 answer
79 views

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, ...
Naitik Mundra's user avatar
0 votes
1 answer
111 views

My teammate asked if we can traverse stack in FIFO (First In First Out) order. I say stack itself maintain LIFO order in it but we can traverse it in FIFO manner by using another stack or list. Then ...
Vishal Goel's user avatar
2 votes
1 answer
196 views

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 ...
Dominik Kaszewski's user avatar
0 votes
0 answers
73 views

Context I'm trying to write a data block with interior mutability, that allows simultaneous access to disjoint areas of memory from the same owner. To do this I have a reservation table that checks if ...
gjh33's user avatar
  • 121
2 votes
2 answers
76 views

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....
aleferna's user avatar
  • 141
2 votes
1 answer
189 views

While working on a learning task involving overlapping n-wise windows from an input iterable - similar to what itertools.pairwise does - I came across code like this: def f(seq): it = iter(seq) ...
Vitalizzare's user avatar
  • 7,636
-3 votes
1 answer
109 views

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 ...
Samyar's user avatar
  • 25
-2 votes
1 answer
97 views

Given struct pt{int x,y;}; auto cmpSet = [](pt a, pt b) { return a.x<b.x;}; std::set<pt, decltype(cmpSet)> s(cmpSet); Are if(upper==s.begin()) continue; auto it= std::prev(upper); while(it!=...
chubakueno's user avatar
4 votes
2 answers
154 views

#include <vector> class MyContainer { public: std::vector<int> data; // begin() only defined for rvalues auto begin() && { return data.begin(); } auto end() &&...
Ashcoll Ash's user avatar
0 votes
1 answer
103 views

I need to process a vector of items. For each item, I need to apply a transform. For some of the items, I also need to insert a new item. I've looked through the standard Rust iterator transforms ...
David Hankins's user avatar
-2 votes
2 answers
92 views

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") ...
robertspierre's user avatar
2 votes
2 answers
96 views

Edit I'm realizing that since Entrys own mutable borrows on their parent HashSets, it is impossible for multiple Entrys in a single HashSet to exist simultaneously. Therefore, Entrys will probably not ...
Kaya Arro's user avatar
  • 123
0 votes
2 answers
62 views

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()...
gust's user avatar
  • 965
0 votes
0 answers
101 views

I'm looking to write an iterator Item = u8 to a file. The iterator has a large len so collecting the iterator and then writing the resulting vector isn't very efficient. I'm thinking of collecting ...
Pioneer_11's user avatar
  • 1,441
4 votes
2 answers
135 views

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 &...
catlover2's user avatar
  • 295
0 votes
1 answer
60 views

I'm trying to implement an array where items can occupy multiple slots (details not relevant to question). I have created a method that allows me to iterate over a range of items: pub fn get(&self,...
Fred's user avatar
  • 497
2 votes
2 answers
188 views

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 ...
Sven Sandberg's user avatar
17 votes
2 answers
658 views

Is the comparison of begin() and end() iterators of two std::spans that point to the same memory well defined? #include <span> #include <cassert> int main() { int arr[5]{1,2,3,4,5}; ...
Ahmed AEK's user avatar
  • 23.2k
0 votes
2 answers
193 views

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!...
rhalameddine's user avatar
2 votes
3 answers
141 views

The C++ reference has this example for printing the intersection of two sets (or sorted containers): #include <algorithm> #include <iostream> #include <iterator> #include <vector&...
Michaël's user avatar
  • 579
4 votes
1 answer
103 views

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 ...
EarthTurtle's user avatar
6 votes
1 answer
204 views

There is a footnote in the [iterator.requirements] section of the C++ standard which states the following: The effect of dereferencing an iterator that has been invalidated is undefined. This ...
Kaiyakha's user avatar
  • 2,075
-2 votes
1 answer
83 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 ...
Taren's user avatar
  • 32
6 votes
2 answers
88 views

Demo code using version rustc 1.86.0 (05f9846f8 2025-03-31) fn main() { let mut source = 1..3; test(&mut source); // This is good. which means &mut Range<T> is Iterator. ...
Yanni Wang's user avatar
1 vote
1 answer
153 views

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 ...
Dominik Kaszewski's user avatar
3 votes
1 answer
151 views

I have two version of the same function using std::any_of and std::find_if for checking whether an int exist in a vector (returned from g.getEdges()). However when I repeatedly run the std::any_of the ...
Yat Fung's user avatar
2 votes
1 answer
102 views

In libstdc++ there is the following code: class common_iterator { ... [[nodiscard]] constexpr decltype(auto) operator*() { __glibcxx_assert(_M_index == 0); return *...
phinz's user avatar
  • 1,647
3 votes
1 answer
99 views

Let's say I have an std::vector<int> arr of 5 elements { 1, 2, 3, 4, 5 }. Is it safe to get a subrange from it like sub = std::span{ arr.begin() + 2, arr.end() } and dereference element at -1 ...
hopeless-programmer's user avatar

1
2 3 4 5
301