All Questions
Tagged with containers iterator
238
questions
0
votes
2
answers
50
views
Extract the node from BST, preserving the fake node
I am writing a binary search tree (BST) with bidirectional iterator. To present .end() I have "fake node", that is the rightest son of the tree. I have problem with extract: my code works ...
0
votes
1
answer
85
views
How do I best simulate a check for contiguous storage before C++20?
C++20 added the contiguous_iterator trait, which I can (?) use on a container's iterators to determine whether it has contiguous storage.
But - what if I can only rely on C++11? What's the closest I ...
0
votes
1
answer
136
views
How should equality be defined for C++ iterators?
I'm implementing a directed graph data structure, where edges live in two simultaneous linked lists: The list of a vertex's outgoing edges, and the list of the opposite vertex's incoming edges.
I've ...
1
vote
0
answers
85
views
Store objects in different containers, and access them with a uniform interface
I have a set of objects linked together, stored in multiple containers of different types.
I want to use an uniform interface, independent of the specific containers.
So far, I could find two ways to ...
1
vote
0
answers
61
views
How to wrapping around STL containers and get proper const and non-const behavior?
When wrapping a container type e.g. std::vector< T > where T is a smart-pointer type e.g. std::shared_ptr< SomeType >, is there a way to simultaneously ensure const correctness and enable ...
0
votes
2
answers
121
views
How do standard library containers know what's before the past-the-end iterator?
I'm trying to implement my own list and map, and I've been having trouble with the end() method since these containers aren't contiguous in memory.
After some research, I've ended up implementing the ...
0
votes
0
answers
151
views
Rust how to wrap container to support Iterator in custom struct
What I'd like to be able to do is rely on existing containers to handle however they contain multiple items, and use their existing iterator to iterate over the container. I am aware of the existing ...
1
vote
1
answer
229
views
How to make a C++ STACK container iterable?
Can we write a myStack class that will be implemented in terms of std::stack so that it offers all of its member functions plus an additional feature: iterators?
I tried some options, but they seem to ...
2
votes
0
answers
91
views
Why range based for loop doesn't work with iterator, which points to container? [duplicate]
I have this code and it doesn't compile. It has an error:
cannot assign to variable 'value' with const-qualified type 'const int &'
value = 5;
#include <vector>
#include <set>
int ...
0
votes
0
answers
36
views
Correctly return pointer to key/value pair from bespoke associative container & iterator
I have an associative container that is implemented internally as two linear arrays, one of keys, and one of values. Both arrays are kept sorted so a binary search of keys yields the index of the ...
0
votes
2
answers
247
views
Cannot convert custom iterator to const_iterator
I am coding an implementation/copy of the std::vector container, and I am having some issues with its iterators.
My random_access_iterator and vector class are implemented like this:
namespace ft
{
...
-1
votes
1
answer
57
views
Do list iterators to map<int, list<double>> remain valid after map insertions/deletions?
std::list iterators remain valid under insertions and deletions. This is not the case for std::map iterators. I wonder if list iterators to objects of the type map<int, list> remain valid after ...
0
votes
0
answers
84
views
Usage of std::iterator. Converting std::deque<T>::{const_iterator|iterator} to std::iterator<Args...>
I got interface IDocument and ConcreteDocument implementing it. I want to allow users to iterate through any concrete document, so Im tried to add begin() and end() members in interface.
IDocument:
...
0
votes
1
answer
200
views
How to overload an iterator so it can be incremented in a dereferenceable state?
to give context i'm trying to re-implement vector container, and while reading about it's iterator system requirements, i've stumbled upon this requirement from cplusplus reference:
can be ...
-2
votes
1
answer
59
views
What's the actual reasoning behind iterator categorization in STL?
For reasons of efficiency it's not possible to have every container work with every generic algorithm -- STL Tutorial and Reference Guide.
So i'm learning about STL and i was reading the mentioned ...