Quote Originally Posted by Scope View Post
Can you look on my implementation? I tested this code and think that it works fine.
Here are my comments on your implementation:

Your iterator advertizes itself a forward iterator, therefore it should provide default construction and post-incrementation.

Line 36: the return type should ve value_type &, not value_type (see more about this below).

Operator ==: your implementation works perfectly, but you could make it faster thanks to the precondition that *this and rhs are on the same container. For instance:
Qt Code:
  1. return outer_iterator == rhs.outer_iterator && (outer_iterator == outer_end || inner_iterator == rhs.inner_iterator);
To copy to clipboard, switch view to plain text mode 
About the wrong return type at line 36: you chose to implement an iterator (as opposed to a const_iterator), which is expected to let the user modify the elements of the container; that is why operator*() should return a non-const reference to the element. Naturally you should also add a comment warning the user against modifying Data::scope and Data::name through this iterator, as this would break the invariant of your Container. (std::map and std::unordered_map have exactly the same problem.)

You should also provide a const_iterator in addition to the iterator, especially if all the iterations you care about are read-only (and the fact that your current operator*() returns a copy of the element is a clear indication that it is the case). Not only will you enjoy the added safety from the type system, but you will also gain a performance advantage since the underlying QHash::const_iterators will not force the QHash to perform a deep copy in case of implicit sharing.

Quote Originally Posted by Scope View Post
And importan question, whether i should stay with QHash whether I can obtain better performance using QMap?

Especially when keys are type of QString which can have between one to over a dozen characters and when each Container should have average 1 <= x <= 30 properties as Data.
You will most likely obtain better performance with a QHash than with a QMap. The main advantage of QMap over QHash is that the collection is sorted. Unless you care about that, you should stick with QHash.

Quote Originally Posted by Scope View Post
I found on Qt blog that this problem can be solve using simple template

Qt Code:
  1. template<class T> const T &const_(const T &t) { return t; }
  2. for(auto it : const_(vector)) { ... }
To copy to clipboard, switch view to plain text mode 
For that to work, you must provide a const_iterator and const begin() and end() methods. Also, your syntax is friendlier than the static_cast beast I wrote in a previous post, but requires the additional helper definition of const_; I still cannot understand why the standard library does not provide it.