Questions about Input Iterators (as a concept), in particular in C++.
Questions tagged [input-iterator]
13 questions
5
votes
1 answer
Can I use istream_iterator to copy some istream content into std::string?
I have an istream and need to copy the content between two delimiters to a std::string.
I can find the delimiters' streampos, but when trying to use istream_iterator to iterate over the section of the stream, it does not work. Here's what I…

RL-S
- 734
- 6
- 21
3
votes
1 answer
Why does std::find_if used on std::istream_iterators seem to return the last element?
I am learning C++ through Accelerated C++ by Andrew Koenig and Barbara E. Moo. I am trying to understand how input operators work and their relation to STL algorithms.
Here is the piece of code that confuses me:
#include
#include…

John
- 71
- 6
3
votes
3 answers
Input iterator can be read repeatedly while Output Iterator can only be written once?
I was reading The C++ Programming Language 4th edition by Bjarne Stroustrup. In the iterator chapter (Chapter 31.1.2), it says:
Input iterator: We can iterate forward using ++ and read each element (repeatedly) using *.
Output iterator: We can…

user9607441
- 49
- 5
3
votes
1 answer
Crafting an InputIterator that does not store the value_type
I am creating a type that models InputIterator. In my application, "skip the first hundred thousand elements" is a reasonable thing to do, and creating the value_type is expensive, so I want my iterator to create the value_type only when…

Kyle Markley
- 155
- 4
2
votes
1 answer
Why does `std::input_iterator` requires a `value_type`?
I am trying to create a data structure for arrays of dynamic-sized arrays. Multiple choices are possible, the simplest one being std::vector>. However it is often not efficient and we would like to compress the data of all the inner…

Bérenger
- 2,678
- 2
- 21
- 42
2
votes
1 answer
Stateful C++ Input Iterators post increment problem
I was implementing an iterator that takes another float values producing input iterator and returns true if a rising was detected. So, the iterator works effectively as a Software-ADC (Analog-Digital-Converter).
I've minimized the actual code to the…

modanashar
- 151
- 2
- 9
2
votes
1 answer
How to return a variant from an input iterator with high performance?
I have some file format decoder which returns a custom input iterator. The value type of this iterator (when dereferencing it with *iter) can be one of many token types.
Here's a simplified usage example:
File file {"/path/to/file"};
for (const…

eepp
- 7,255
- 1
- 38
- 56
2
votes
1 answer
Equality comparison for Input iterators
For input iterators, what are the requirements for comparing equality if one of the iterators has been invalidated?
input_iter x = foo();
input_iter y = x;
++x;
return x == y; // What must this return?
In the above example, dereferencing y would…

IanPudney
- 5,941
- 1
- 24
- 39
2
votes
1 answer
C++ Input Iterator
I'm reading C++ Standard (Section Input Iterator) and I'm having hard time to visualize the text in bold:
Note: For input iterators, a == b does not imply ++a == ++b. (Equality does not guarantee the substitution
property or referential…

Orion
- 544
- 5
- 15
1
vote
3 answers
How to implement "dereference and post-increment" for input iterator in C++?
Requirements for InputIterator include *i++ with an equivalent expression being
value_type x = *i;
++i;
return x;
How can one declare such an operator without implementing the standard post-increment i++ returning a non-void value (which…

quant_dev
- 6,181
- 1
- 34
- 57
0
votes
1 answer
Input and output iterators are swappable?
Input iterators Output Iterators
Swappable: The value pointed to by these iterators can be exchanged or swapped.
In these two links it's stated that the value pointed to by input iterators or output iterators can be exchanged or swapped. I'm not…

StackExchange123
- 1,871
- 9
- 24
0
votes
1 answer
traversing a container a second time with an input iterator
there is no guarantee that traversing a container a second time with an input iterator will move through the values in the same order.Also after an input iterator has been incremented, there is no guarantee that its prior value can still be…

Saleh
- 48
- 5
0
votes
1 answer
Iterating over all possible bit permutations
Say I want to iterate over all bit sequences (for lack of better name) in the range 0000-1111. When I want to scale it up to 24 bits, I won't be able to simply compute all possible permutations beforehand; I'd need to compute them on the fly.
How…

noɥʇʎԀʎzɐɹƆ
- 9,967
- 2
- 50
- 67