Thiago Macieira wrote:
> Which means the following helper function can solve your problem:
> template<typename Key, typename Value>
> QMap<Key, Value> &operator<<(QMap<Key, Value> &map, QPair<Key, Value> v)
> map.insert(v.first, v.second);
> return map;
> Then you can write:
> some_func(QMap<QString,int>() << qMakePair(string1, 1)
> << qMakePair(string2, 2)
> << qMakePair(string3, 3));
That's the kind of solution I was vaguely thinking about. The
motivation for this is that I want to replicate the ability,
available in Perl, to do something like:
some_func(string1 => 1, string2 => 2, string => 3);
my %args = @_;
so I was trying to dream up a similar-ish syntax. This would
be useful for code that deals with the various QSql classes.
At the moment I'm not sure that it's possible to do much better
than what you have done - you'd need language support (I think)
for a std::make_pair literal syntax.
> 3) I could probably add that operator<< to QMap, right?
Hmm. I don't know. Is it of general enough interest ?
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/