13 questions
2
votes
1
answer
890
views
Why does `std::input_iterator<In>` 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<std::vector<T>>. However it is often not ...
2
votes
1
answer
123
views
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-...
0
votes
1
answer
133
views
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 ...
6
votes
1
answer
948
views
Can I use istream_iterator<char> 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<char> to iterate over the ...
3
votes
1
answer
322
views
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 ...
3
votes
3
answers
1k
views
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 (...
2
votes
1
answer
123
views
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 ...
2
votes
1
answer
301
views
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 ...
0
votes
1
answer
73
views
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 ...
3
votes
1
answer
53
views
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 ...
0
votes
1
answer
807
views
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 ...
2
votes
1
answer
5k
views
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 ...
2
votes
3
answers
1k
views
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 ...