Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [iterator]

An iterator is an object-oriented programming pattern which for the most part functions similarly to a pointer to an object inside a collection with the added ability to traverse through the collection in a defined manner, agnostic of the actual implementation or even object addresses in physical memory. Iterators may be further limited in particular traversal directions.

-2
votes
0answers
26 views

I'm trying to make a collection class in C# [on hold]

As a side project i'm trying to remake one of my favorite games from the old days, moria/angband. I'm doing it from scratch and in C#. In order to store the inventory I have the following classes, ...
0
votes
0answers
11 views

Make lambdas concise using enumerations? [migrated]

Generally, we are looking to create a logging framework that can target human readable output as well as various structured data formats. So, a goal is minimizing code duplication in packaging the ...
2
votes
1answer
83 views

Iterating over different Objects which are ordered by index number

I am currently working on a bigger project where I found a part of it which seems very ugly to me from the code. I stripped out the algorithm and made a working code, so it can be reviewed. I have ...
1
vote
1answer
220 views

Applying multiple php FilterIterator instances in a cascading fashion

I wrote an implementation of php FilterIterator objects that allows me to apply them in a "cascade" way, so I can finally obtain an array of objects which is the ...
0
votes
0answers
45 views

An iterator returning all possible permutations of a list in Java - follow-up

(See the previous and initial iteration.) My main attempt here was to get rid of monolithic code and split the implementation into smaller methods when applicable and do more extensive commenting. ...
5
votes
3answers
422 views

Python generator for “barely obtuse” triangles (Project Euler 224)

I am trying to solve Project Euler Problem 224: Let us call an integer sided triangle with sides a ≤ b ≤ c barely obtuse if the sides satisfy a2 + b2 = c2 - 1. How many barely obtuse triangles ...
4
votes
2answers
71 views

Python grouped iterator

I wanted to write an iterator that would split items up into groups, so i can bulk insert into mysql without crashing or overwhelming the server. This is the implementation I came up with. I am ...
2
votes
0answers
36 views

Iterator that groups elements of its source

I wrote an iterator to access the pixel in an packed image. It works, but it is slow. 1.Are there any mistakes that can be avoided and might lead to better speed? 2.Are there any pitfalls that ...
2
votes
1answer
49 views

Class representing digital PLC address

I have a project where I work with digital addresses for a Programmable Logic Controller (PLC). The requirement is that the user gives a start address e.g. 1000.0 and then for example the next 20 ...
4
votes
2answers
88 views

Finding the common iterator category in C++

I created a template trait which finds the common iterator category between a set of given iterator categories. More specifically, it's a class with a member type alias to one of the iterator tags ...
2
votes
1answer
33 views

Finding the Original Fractions from Rounded Decimals

The data I'm using is summoning rates from a gacha game, One Piece Treasure Cruise. The game provides the probability of getting a certain character in percents rounded to the nearest thousandth. ...
6
votes
2answers
105 views

Walking directory tree like python does

I like python's os.walk and I was missing it in C#. It's a very convenient API so I thought I create my own utility that does something similar. The original API ...
4
votes
1answer
118 views

back_inserter for several container arguments

Recently I wrote a back_inserter with the same interface as the std::back_inserter just for supporting several containers in the constructor and doing push_back for each. The solution needs C++17. ...
1
vote
1answer
47 views

Convert a type u16 number to a matrix (Vec<Vec<u8>> or array) of 4 x 4

I am a Rust newbie and I am not familiar with all the iterator options. This is what I have so far. How can I make this better or at least avoid collecting twice into a Vec? ...
-1
votes
1answer
59 views

Check if an element exists in a list of dictionaries [closed]

The logic of the code to build was as follows, two logical conditions; If the value of dictionary element matches in the list of dictionaries return the particular dictionary, and if no element ...
4
votes
1answer
252 views

Reverse C++11 range-based for loop

I wrote this snippet: ...
0
votes
0answers
39 views

Deferred Iteration in TypeScript

I've published a new TypeScript library currently in beta, and was hoping to get feedback on certain aspects of it, particularly implementation details for improving the performance of deferred ...
6
votes
1answer
58 views

General nested for

I needed a general-purpose function that accepts some sequence_container<sequence_container<T>> and iterates all permutations of the inner container. To ...
6
votes
3answers
137 views

Progress bar wrapper class in C++

I've recently written a simple progress bar class in C++ to mimic usage of similar libraries I've used in Python. The idea is to take some iterable container (e.g. ...
4
votes
4answers
747 views

Take a desired string, iterate through objects to see if it exists in a given field and append a number until a unique string is found

I wanted to in the most generic way possible write a method in C# to achieve the following. Take in a string, a set of objects, and a function to access the field of a given object Look at all of the ...
2
votes
1answer
89 views

Handling related generic type parameters

In answering a question on StackOverflow, it occurred to me that a more generic version of GroupBy for C# that delegated membership in each group to a class could ...
-1
votes
1answer
210 views

putting sql-query response directly to foreach-loop?

Is there any reason to not do this? Putting the query directly inside a foreach-statment when the only time the result is going to be used is within that location.. ...
10
votes
4answers
1k views

Basic iterator supporting vector implementation

On the fly, I just implemented this iterator supporting vector class to understand how range-based for loop works. It's really basic but let me know what can be improved. Vector.h ...
7
votes
3answers
136 views

Endless stream: stream a range and return default value if the range is exhausted

Introduction: Motivation Sometimes there is a need to merge N > 1 ranges, and they don't have equal length, but there is a value which can be used in case the range is already exhausted. It is ...
7
votes
3answers
1k views
7
votes
2answers
296 views

Iterator for BFS binary tree traversal

I implemented an iterator pattern for C# using IEnumerator and IEnumerable. The goal of the implementation is to traverse a ...
5
votes
2answers
67 views

Iterable object on set of ids

For some of the algorithms that I am implementing it turned out to be useful storing ids in order to iterate on objects, while also avoiding having to think about reallocation and invalidation of ...
1
vote
4answers
357 views

Implementing a custom iterator by inheriting from an existing iterator class and overriding operator*

My goal is to write very little code and I want a custom iterator that only changes the behavior of the dereference operator* but copies the rest of the behavior ...
4
votes
1answer
54 views

General use multi-dimensional container using operator[]

This is a followup to a previous question of mine on same subject. Context I want to have a tool that allows to simulate as much as possible a C++ standard container for a multidimensional ...
6
votes
1answer
816 views

Getting serial port list

Needed to get a local serial port list. System.IO.Ports.SerialPort.GetPortNames() returns names but not the descriptions like you can see in Device Manager: ...
3
votes
1answer
184 views

Flatten nested iterables

I wrote a program sometime ago that reads csv files, sorts, reorders and groups their columns/rows' content (with itertools) and later labels the groups using a ...
9
votes
2answers
196 views

Multi-dimensional container using operator[]

This is a late followup to a previous question of mine on same subject. Context: I want to have a tool that allows to use all the C++ goodies (algorithms, for loop on containers, etc.) on a ...
2
votes
1answer
112 views

Implementation of generic unordered list in java

This question is a follow-up question of this question. These features are added to the new class - Generic class User is capable of setting the size ...
6
votes
2answers
479 views

Generic in order traversal iterator for binary trees

This actually started off as member type for the binary_search_tree, but after realizing that it doesn't compare to values or use the value objects inside of it, I ...
7
votes
2answers
58 views

Acts like an iterator, but counts

I’m making a “counting iterator” which emulates a constant container of consecutive values of some integral type. It is mostly boilerplate, going through the list of requirements for different ...
7
votes
1answer
80 views

Custom container for iterating over combinations of elements from multiple sets

Motivated by some SO quesitons [1, 2] I made an attempt at implementing a custom container with a bi-directional custom iterator for iterating over all combinations of elements from multiple sets. I ...
9
votes
2answers
705 views

Determine added, removed and kept items between two lists

My code is determining the difference between two iterables in terms of items that have been addded, removed and kept. The items are assumed to be sortable and there are no duplicates. ...
-6
votes
1answer
99 views

Poor decision of IEnumerable of IEnumerable of IEnumerable [closed]

I wish to improve a class design that causes me readability and performance problems as the code grows. ...
18
votes
8answers
2k views

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

I was reading this question, and the answer that mentioned streams, and a thought had occurred to me. In many cases (at least in my usage) I want to determine if a sequence (or ...
6
votes
1answer
71 views

Iterator over a container with indexing operation

This is a random access iterator that stores an index and a reference to a container. It iterates over any container with indexing operation. It does not have copy assignment / move assignment ...
8
votes
2answers
388 views

Parsing oscilloscope binary data file with C++

Preliminaries I have OWON oscilloscope that is able to record waveform in file in three formats: Text format .txt: the first lines are some general information ...
2
votes
0answers
239 views

Iterator for custom List class

I have extended a custom list class I have been working on with a Iterator class. I have not used std::iterator as a base class as it will be deprecated in C++17. ...
10
votes
2answers
799 views

Custom C++ random access iterator for pointers to arrays

I have implemented a custom iterator to iterate over an array that is held by a pointer. The iterator accepts a unit which specifies by which amount the underlying pointer is increased (or decreased) ...
3
votes
0answers
185 views

Helper trait for modularizing iterator chains which involve grouping items in tuples

The itertools::Itertools::tuples method from the itertools crate appears to be limited in the aspect that the trait ...
4
votes
1answer
101 views

Lazy lists with transformations, using generators & iterators

I built this very-basic lazy list (I'll add more methods as I need them). You provide it an array, a generator or any iterator. It creates a lazy list, which lets you run a pipeline of transformations ...
6
votes
3answers
728 views

Compute Convex Hull

The question asks to compute the convex hull of a set of 2D points. A convex hull is basically a series of consecutive line segments that suffice to enclose all the points in the area. In this ...
5
votes
1answer
2k views

Check if multiple lists contain an element from a large external list

I have a list of lists (many tokenised sentences). For anyone who doesn't know what tokenised sentences are, my list is like so: ...
3
votes
2answers
1k views

Example of adding STL iterator support to custom collection class

I'm trying to create an example of a custom collection with an API meeting the requirements of STL iterator templates, as a learning experience. The collection used here, a ring buffer, is merely a ...
0
votes
0answers
34 views

Using Generators for private scope

There's something about this code that's pretty neat-o to me, but is it a bad idea? Is there a name for programming like this? First, the generator itself: ...
5
votes
1answer
106 views

C++ container — variable byte coded numbers list

I'm writing a container for unsigned integers, which uses variable byte coding. It works but some decisions I took look ugly so I would be glad if you gave me some hints for improving the design. I ...