Skip to main content
Filter by
Sorted by
Tagged with
4 votes
5 answers
358 views

I want to implement the java.util.Iterator interface for iterating over data retrieved through an external system's API. The data may appear in the external system over time. Is it correct to return ...
nik0x1's user avatar
  • 1,798
5 votes
1 answer
123 views

I couldn't find any wording in the Standard that iterators to list elements continue to be valid when a new list is move-constructed from it, like this: #include <list> #include <print> #...
Toby Speight's user avatar
  • 32.9k
2 votes
1 answer
170 views

Question: Is it a don't do it that delete a element of map in a loop? //std::set<Battle::BattleBuf *> m_bufs; for (auto& pBuf : m_bufs) { pBuf->doEffect(pDef, param); // It can a ...
Searcher's user avatar
  • 177
Advice
1 vote
13 replies
93 views

I do things with maps (could be std::map or another map from the standard library, a boost map, a custom map from another library, etc): template<class T> void do_map_stuff(T const& t) { ...
jaymmer - Reinstate Monica's user avatar
0 votes
1 answer
105 views

I have a custom collection type that can be somewhat cheaply altered (think of shifting all values by some offset, creating a new collection) can do some calculations with respect to some other ...
ti-sch's user avatar
  • 1
Best practices
1 vote
7 replies
136 views

Working on an assignment for a Data Structures course I started thinking about some implementation differences for iterators. Working in C. Let's say my iterator looks like this: struct list_iter { ...
maverickar's user avatar
1 vote
1 answer
113 views

I'm tweaking a garbage collector class whose job is to iterate through a disk cache of files in subdirs, find any that are "out of date" and remove them. Further, if it finds any empty ...
Stef Dawson's user avatar
Best practices
0 votes
4 replies
81 views

I can't help thinking this is not an uncommon idiom and I'm just being an idiot but I've spent ages searching SO and reading the docs for std::iter and for the itertools crate and have got nowhere. ...
Halzephron's user avatar
1 vote
1 answer
106 views

I wanted to quickly make an alias type iterable in rust. Here's what I have: #[derive(Debug, Clone)] struct SSHDomains { hostname: String, path: String, } #[derive(Iter, IntoIter)] pub struct ...
glades's user avatar
  • 5,472
3 votes
1 answer
83 views

The Rust compiler gives me a lifetime error with the following code (which is a minimal working example of some real code): pub trait TElement: Copy { // Details irrelevant } pub trait TSet<'a,...
KloppyToppy's user avatar
3 votes
2 answers
393 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
  • 25.7k
0 votes
0 answers
181 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
152 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
102 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
232 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
  • 2,009
Best practices
1 vote
7 replies
187 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,362
1 vote
1 answer
127 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
135 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
38 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
1 vote
1 answer
85 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
151 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
229 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
  • 150
2 votes
1 answer
98 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
138 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
270 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
195 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.8k
4 votes
1 answer
165 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,413
0 votes
3 answers
230 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
288 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,799
0 votes
2 answers
106 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
78 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
83 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
122 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
218 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
2 votes
2 answers
80 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
228 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,648
-3 votes
1 answer
116 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
  • 35
-2 votes
1 answer
99 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
171 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
110 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
93 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
100 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
95 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
121 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,481
4 votes
2 answers
148 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
87 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
202 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
691 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
322 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
148 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
  • 608

1
2 3 4 5
301