This is the mail archive of the
mailing list for the GCC project.
Re: [GSoC] Question about std::map
- From: Trevor Saunders <tsaunders at mozilla dot com>
- To: Tobias Grosser <tobias at grosser dot es>
- Cc: Roman Gareev <gareevroman at gmail dot com>, gcc at gcc dot gnu dot org, Mircea Namolaru <mircea dot namolaru at inria dot fr>
- Date: Thu, 3 Jul 2014 22:16:09 -0400
- Subject: Re: [GSoC] Question about std::map
- Authentication-results: sourceware.org; auth=none
- References: <CABGF_gfEPTkYLxg74bykZasx6TTRMtWRTQRYWkc4B7g=Ex84fg at mail dot gmail dot com> <53B5987B dot 4060306 at grosser dot es>
On Thu, Jul 03, 2014 at 07:52:59PM +0200, Tobias Grosser wrote:
> On 03/07/2014 19:23, Roman Gareev wrote:
> >Dear gcc contributors,
> >could you please answer a few questions about std::map? Does gcc have
> >a policy that forbids using of map in the source code of gcc? Can this
> >using create a new installation dependency, which requires libstdc++?
> >I would be very grateful for your comments.
> This suggests that using std::map is allowed. Running "grep 'std::' *"
> on gcc, we only find a couple of std::make_pair, std::min and std::max
> calls, but I don't see why we should not use std::map. I would say go for it
> if there are no vetos. It seems to be the right tool for what you are aiming
> for and certainly makes the code a lot more readable.
I'm certainly not opposed to using the stl when it makes sense, and
reinventing our own stl has a fairly high cost. However I think the
question of if you should use std::map is a complicated one. First
remember std::map is a tree, not a hash table, and consider which
performance characteristic you want. Also remember the stl in some
cases trades off possible optimizations to be more generic, if you
implement your own version of something you can say ban arrays larger
than 2^32 and thereby save a bit of space. When you use the stl you
also need to make sure you don't call things that can throw exceptions
since gcc is built with -fno-exceptions and generally isn't exception
I think there are some stl things you should basically always prefer
e.g. std::swap, there are some things you should think about before
using, and some things that are best avoided. Personally I think you
should favor hash tables to std::map most of the time because of there
generally better performance.
btw if you have specific gripes about the stlish bits gcc already has
I'd like to hear them.