e.jahandar
e.jahandar

Reputation: 1763

Getting Java style Iterator from QMap<K, T> without specifying T, K

Is there any way obtaining java style iterator from QMap without specifying K and T explicitly ?

for example, writing

QMap<QString, SomeType> map;
auto qIt = map.getIterator();

Instead of

QMap<QString, SomeType> map;
QMapIterator<QString, SomeType> qIt(map);

Upvotes: 0

Views: 58

Answers (1)

G.M.
G.M.

Reputation: 12879

If you're just trying to save on some repetitive typing then you could write a small function template to take advantage of the fact that the template parameters will be deduced from the passed arguments...

template<typename Key, typename Value>
QMapIterator<Key, Value> make_qiter (QMap<Key, Value> &map)
{
  return(QMapIterator<Key, Value>(map));
}

Then use as...

QMap<QString, SomeType> map;
auto qIt = make_qiter(map);

Upvotes: 3

Related Questions