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


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

std::map: best way to get biggest key?

From Rui Maciel <rui.maciel@gmail.com>
Newsgroups comp.lang.c++
Subject std::map: best way to get biggest key?
Date 2012-02-11 21:44 +0000
Organization Aioe.org NNTP Server
Message-ID <jh6nft$43f$1@speranza.aioe.org> (permalink)

Show all headers | View raw


The typical way to get the biggest key of a std::map is to rely on the 
default sorting for std::map (based on std::less) and simply check the key 
of the last element of a map, as:

<code>
std::map<key,value> my_map;
//...
key largest_key = my_map.rbegin()->first
<code>


Yet, this trick is a bit flimsy and isn't very elegant.  Does anyone know if 
there is a better way to extract the biggest key of a std::map?


Thanks in advance,
Rui Maciel

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


Thread

std::map: best way to get biggest key? Rui Maciel <rui.maciel@gmail.com> - 2012-02-11 21:44 +0000
  Re: std::map: best way to get biggest key? Leigh Johnston <leigh@i42.co.uk> - 2012-02-11 21:57 +0000
    Re: std::map: best way to get biggest key? Rui Maciel <rui.maciel@gmail.com> - 2012-02-11 22:09 +0000
      Re: std::map: best way to get biggest key? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-02-11 23:28 +0100
        Re: std::map: best way to get biggest key? Rui Maciel <rui.maciel@gmail.com> - 2012-02-12 15:07 +0000
          Re: std::map: best way to get biggest key? Dombo <dombo@disposable.invalid> - 2012-02-12 17:00 +0100
          Re: std::map: best way to get biggest key? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-02-12 18:41 +0100
          Re: std::map: best way to get biggest key? Ian Collins <ian-news@hotmail.com> - 2012-02-13 07:13 +1300
          Re: std::map: best way to get biggest key? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-12 19:40 +0000
          Re: std::map: best way to get biggest key? Joshua Maurice <joshuamaurice@gmail.com> - 2012-02-12 13:25 -0800
      Re: std::map: best way to get biggest key? Dombo <dombo@disposable.invalid> - 2012-02-11 23:29 +0100
      Re: std::map: best way to get biggest key? Paavo Helde <myfirstname@osa.pri.ee> - 2012-02-11 16:39 -0600
        Re: std::map: best way to get biggest key? Rui Maciel <rui.maciel@gmail.com> - 2012-02-12 15:16 +0000
          Re: std::map: best way to get biggest key? Goran <goran.pusic@gmail.com> - 2012-02-12 08:41 -0800
          Re: std::map: best way to get biggest key? Leigh Johnston <leigh@i42.co.uk> - 2012-02-12 18:48 +0000

csiph-web