|
|
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);
sub some_func
{
my %args = @_;
print $args{string1};
}
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 ?
--
Regards
Steve Collyer
Netspinner Ltd
--
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/
|
|