Skip to main content
-2 votes
0 answers
99 views

Why can't standard functions and methods work with structure in C++? [duplicate]

Overview Problem I have a struct ShipCell, a lot of these structures are stored in the Ships class. In this class, I have defined the removeDuplicates() method, which throws an error. removeDuplicates(...
Denis Kramarenko's user avatar
-6 votes
0 answers
95 views

How does an immutable iterator keep track of its state in Python? [closed]

I can create an "immutable" iterator object with the below code: @dataclass(frozen=True) class MyIterator1: def __iter__(self): return self def __next__(self): choice ...
Alex's user avatar
  • 41
2 votes
1 answer
86 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. ...
Tuned Rockets's user avatar
3 votes
2 answers
111 views

Iterate over elements, not references on them

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

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

Dereference iterator and then iterate over dereferenced value [duplicate]

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

calling a class object in an iterative way on python

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

How to return an empty **peekable** iterator in Rust?

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

Is there a Rust way to `continue` a loop inside a `map` closure?

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
172 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 ...
xmllmx's user avatar
  • 44.5k
3 votes
1 answer
137 views

Can't resume using the Iterator helper object

✔ 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,371
0 votes
3 answers
206 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 &...
BadUsername's user avatar

15 30 50 per page
1
2 3 4 5
1002