iterator Questions
1
Solved
Consider the toy example code below. It has a too-large-to-copy data structure MyDataStructure and a little iterator class MyDataIterator that the caller can instantiate to iterate over the data in...
3
Solved
This works because Iterator implements rev() where self is a DoubleEndedIterator:
let vec: Vec<i32> = Vec::new();
for x in vec.iter().rev() {
//Do stuff
}
However, if I change vec.iter()....
4
Solved
Say I have an std::list<int> lst and some std::list<int>::iterator it for iterating through the list. And depended to value of the it I want to use it + 1 or it - 1 in my code. Is there...
2
Solved
I'm looking for a why to convert a regular iterator into one that supports pushing items back into it. E.g.
item = next(my_iterator)
if went_too_far(item):
my_iterator.pushback(item)
break;
Th...
4
Solved
Does it works correctly (does nothing) when I use
vector<T> v;
v.erase(v.end());
I want to use something like
v.erase(std::find(...));
Should I if is it v.end() or not?
There is no info ...
Paley asked 6/3, 2012 at 19:1
3
Solved
I'm writing different sort functions, which take two iterators and sort sequence. I would like to implement them for any kind of vector and make them typesafe, like this:
template <typename T&g...
5
How to check if a template argument is a std::vector<T>::iterator?
For void type, we have std::is_void. Is there something like that for std::vector<T>::iterator?
7
Solved
If I have these two lists:
la = [1, 2, 3]
lb = [4, 5, 6]
I can iterate over them as follows:
for i in range(min(len(la), len(lb))):
print la[i], lb[i]
Or more pythonically
for a, b in zip(l...
Carangid asked 9/5, 2013 at 9:18
5
I am writing a function that iterates over the entries in a map. I want to be able to deal cleanly with items which are added or deleted from the map while iterating, like for k, v := range myMap {...
Pointer asked 4/4, 2017 at 16:46
13
Solved
One option is to use channels. Channels are like iterators in a way and you can iterate over them using range keyword. But when you find out you can't break out of this loop without leaking gorouti...
9
Solved
I have a problem that I would like to merge a large number of images using ImageMagick's convert.exe, but under Windows I have a 8192 byte long command line limit.
My solution to this is to split...
Ummersen asked 28/7, 2011 at 14:57
3
$iterator = new ArrayIterator([1, 2]);
array_walk($iterator, function($item) {echo $item . PHP_EOL;});
This piece of php code outputs the items (1 and 2) in php 7.3 but it outputs nothing in php 7...
Puttier asked 30/9, 2020 at 9:57
3
Solved
So I need to call an async function for all items in a list. This could be a list of URLs and an async function using aiohttp that gets a response back from every URL. Now obviously I cannot do the...
Incertitude asked 1/1, 2018 at 18:32
7
Solved
I'm trying to zip two iterators of unequal length, it only returns when when there is value in both and ignores the rest in the longest iterator.
fn main() {
let num1 = vec![1, 2];
let num2 = ve...
2
Solved
I need to iterate a Vec including the position for each iterated element. I'm sure this is already in the API but I cannot see it.
I need something like this:
fn main() {
let v = vec![1; 10];
...
6
Solved
I have a vector that stores pointers to many objects instantiated dynamically, and I'm trying to iterate through the vector and remove certain elements (remove from vector and destroy object), but ...
Runyan asked 13/6, 2009 at 19:27
11
Solved
This is rather the inverse of What can you use Python generator functions for?: python generators, generator expressions, and the itertools module are some of my favorite features of python these d...
Sauterne asked 29/10, 2008 at 4:25
12
Solved
I am looking for a concise way to convert an Iterator to a Stream or more specifically to "view" the iterator as a stream.
For performance reason, I would like to avoid a copy of the iterator in a...
7
Solved
Suppose I've got a method that accepts an array and processes each element in it using Java's built in for-each loop, like this:
public static void myFun(SomeClass[] arr) {
for (SomeClass sc : ar...
2
Solved
I am simultaneously iterating over multiple lists and want my generator to yield both the element and its index. If I had two lists, I would use a nested for loop:
for i_idx, i_val in enumerate(lis...
5
Solved
In ES6, is there any possible to clone an iterator states?
var ma=[1,2,3,4];
var it=ma[Symbol.iterator]();
it.next();
if I want to remember here the it states how should I do in javascritp?
wha...
Marilyn asked 26/9, 2017 at 0:57
5
Recently i have been using the 'yield' in python. And I find generator functions very useful. My query is that, is there something which could decrement the imaginative cursor in the generator obje...
10
Solved
I have a custom container class for which I'd like to write the iterator and const_iterator classes.
I never did this before and I failed to find an appropriate how-to. What are the guidelines reg...
Floriated asked 27/8, 2010 at 8:50
6
Solved
I am doing the Rust by Example tutorial, which has this code snippet:
// Vec example
let vec1 = vec![1, 2, 3];
let vec2 = vec![4, 5, 6];
// `iter()` for vecs yields `&i32`. Destructure to `i32...
9
Solved
I have two iterables, and I want to go over them in pairs:
foo = [1, 2, 3]
bar = [4, 5, 6]
for (f, b) in iterate_together(foo, bar):
print("f:", f, " | b:", b)
That should re...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.