Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #68392

Re: Weird use of maps.

From Manfred <noname@add.invalid>
Newsgroups comp.lang.c++
Subject Re: Weird use of maps.
Date 2019-09-13 17:49 +0200
Organization Aioe.org NNTP Server
Message-ID <qlgdqa$1fg$1@gioia.aioe.org> (permalink)
References <qk5vm0$52n$1@dont-email.me> <87ftllb15b.fsf@ID-208667.user.individual.de> <qk791e$a2h$4@dont-email.me> <871rx33kkd.fsf@ID-208667.user.individual.de> <qk9pog$3hu$1@dont-email.me>

Show all headers | View raw


On 8/30/2019 2:14 AM, James Kuyper wrote:
> If he'd used QMap<QString, int> for the part map, and QMap<QSTring,
> QMap<QString, int> > for the message map, it would all have worked fine
> (except for the bug that I fixed), and he would have been able to
> extract the map directly, rather than by calling toMap(). So why did he
> use QVariant instead? I'm getting the impression that he used QVariant
> without bothering to consider whether it was actually needed.

An abstract reason (i.e. with no sight of the code) is to distinguish 
between an empty message and a non existing message:
You know that if you call messageMap["foo"] and the is no "foo" element, 
the map creates a default object for you (at least std::map does, I 
guess QtMap does it too)
If the value is a variant you get a default variant (which obviously 
isn't a map), and if the value is a map you get an empty map, i.e. an 
empty message.

Just guessing, as said I have no idea if this might even remotely be the 
case.
(BTW of course if I had to try and access an element without 
constructing one find() would be the right thing to do)

A similar argument would apply if you chose to use a vector: if you have 
a vector of variants you could count how many fragments have been 
received by counting how many elements contain strings, instead of using 
empty strings for non-received elements, which could be wrong depending 
on the transmission protocol.

Disclaimer: even if any of the above could explain what happened with 
the code, there is no way to say if it could be in any way a good choice 
without more info on the code and its purpose.
 From what you have posted it seems to be an overcomplicated solution 
for a relatively easy problem anyway, so caution is in order.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-28 09:30 -0400
  Re: Weird use of maps. Jens Kallup <jkallup@web.de> - 2019-08-28 16:22 +0200
    Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-28 20:46 -0400
  Re: Weird use of maps. Öö Tiib <ootiib@hot.ee> - 2019-08-28 09:00 -0700
    Re: Weird use of maps. "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-08-28 14:54 -0700
    Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-28 20:58 -0400
      Re: Weird use of maps. David Brown <david.brown@hesbynett.no> - 2019-08-29 10:24 +0200
        Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-29 10:05 -0400
  Re: Weird use of maps. Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2019-08-28 19:19 +0100
    Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-28 21:05 -0400
  Re: Weird use of maps. usenet@stegropa.de (Stefan Große Pawig) - 2019-08-28 20:22 +0200
    Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-28 21:08 -0400
    Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-28 21:16 -0400
      Re: Weird use of maps. usenet@stegropa.de (Stefan Große Pawig) - 2019-08-29 20:14 +0200
        Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-29 20:14 -0400
          Re: Weird use of maps. David Brown <david.brown@hesbynett.no> - 2019-08-30 08:28 +0200
            Re: Weird use of maps. Öö Tiib <ootiib@hot.ee> - 2019-08-30 00:15 -0700
          Re: Weird use of maps. Manfred <noname@add.invalid> - 2019-09-13 17:49 +0200
            Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-09-13 15:04 -0400
  Re: Weird use of maps. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-08-28 19:33 +0000
    Re: Weird use of maps. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-28 21:11 -0400

csiph-web