vector of vectors... Yes it sounds crazy
You can access vector elements using a function like get(int index) or the [] operator. At the assembly level those functions will do a "mov dest, [array + index * scale]". A lookup table like the one you posted can be used to do method invocations, but it's not a general purpose data structure. This thread discusses the syntax of template declaration in c++ and not the details of the underlying implementation.
The normal implementation for a std::vector would indeed be a C-like array. I think you mixed something up there. Iterators are a concept to _access_ a container, not a concept how to _store_ things in a container. In the case of a vector of T the iterator could be a T* (you could of course provide an entire iterator class, as long as it fullfills the requirements of a random-access iterator). The user of the std::vector class can then use begin() and end() (and of course rbegin() and rend()) to get the iterator that point to the beginning (ie. the first element in the internal C-like array) and to the end (ie. the (n-1)th element in the C-like array.pcmattman wrote:I'm pretty the STL vector class uses iterators instead of integers for it's internal referencing, but it's still the same concept.
No, you are notI'm pretty [...]
at assembly level, don't forget that everything is possible.
as you are all OS developpers, you shall know assembly as well as abstraction langages, otherwise you will be confused by pointer arythmetics in C or C++ that is really a boring concept.
in assembly, you have a lot of possibilities for addressing.
this is a level 2 addressing:
how to do that in C?
and more, how to do that for multilevels addressing?
i don't post the specific cases i croos while coding, because they are to many.
vector of vector of vector of vector...
like file systems.....
:S
as you are all OS developpers, you shall know assembly as well as abstraction langages, otherwise you will be confused by pointer arythmetics in C or C++ that is really a boring concept.
in assembly, you have a lot of possibilities for addressing.
this is a level 2 addressing:
Code: Select all
mov eax,[esi+eax*4]
mov eax,[eax+eax*4]
call eax
and more, how to do that for multilevels addressing?
i don't post the specific cases i croos while coding, because they are to many.
vector of vector of vector of vector...
like file systems.....
:S
welcome in my dream.
Either way is fine.
Code: Select all
std::vector< SomeClass > vec;
vec.push_back( SomeClass() );
std::vector< SomeClass >::const_iterator it = vec.begin(); // iterator
std::cout << vec[0] // valid, access without bounds checking
<< vec.at( 0 ) // valid, throws exception if out-of-bounds
<< *it; // valid, access through iterator
Every good solution is obvious once you've found it.