Click here to Skip to main content
15,915,748 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Confuse about AddRef / Release. Pin
qur26-Dec-02 6:41
qur26-Dec-02 6:41 
GeneralRe: Confuse about AddRef / Release. Pin
pba_26-Dec-02 10:12
pba_26-Dec-02 10:12 
GeneralInsert into map without lookup Pin
peterchen23-Dec-02 4:47
peterchen23-Dec-02 4:47 
GeneralRe: Insert into map without lookup Pin
valikac23-Dec-02 5:04
valikac23-Dec-02 5:04 
GeneralRe: Insert into map without lookup Pin
Stuart Dootson23-Dec-02 21:51
professionalStuart Dootson23-Dec-02 21:51 
GeneralRe: Insert into map without lookup Pin
peterchen24-Dec-02 12:12
peterchen24-Dec-02 12:12 
GeneralRe: Insert into map without lookup Pin
Jörgen Sigvardsson24-Dec-02 12:27
Jörgen Sigvardsson24-Dec-02 12:27 
GeneralRe: Insert into map without lookup Pin
Joaquín M López Muñoz26-Dec-02 21:00
Joaquín M López Muñoz26-Dec-02 21:00 
There's a version of std::map::insert that accepts an iterator as a hint to the appropriate insertion place. You can take advantage of this if you previously save the position of the immediately preceding element in the map, as the following example shows:
#pragma warning(disable:4786)
#include <map>
 
using namespace std;
 
template <class map_type>
map_type::iterator insert_if_not_present(map_type& m,const map_type::value_type& v)
{
  map_type::iterator it=m.lower_bound(v.first);
  if(it!=m.end()){
    if(!m.key_comp()(v.first,it->first)){ // already present
      return it;
    }
  }
  if(it!=m.begin())--it; // set the insertion point
  return m.insert(it,v);
}
 
int main(void)
{
  map<int,int> m;
 
  insert_if_not_present(m,make_pair(1,1));
  insert_if_not_present(m,make_pair(2,2));
  insert_if_not_present(m,make_pair(3,3));
  insert_if_not_present(m,make_pair(2,2));
 
  return 0;
}


Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralNeed help using object in ATL ActiveX EXE window services server. Pin
bahruddina22-Dec-02 17:48
bahruddina22-Dec-02 17:48 
GeneralSearch (Compare) Functor and std::pair :: STL Pin
valikac21-Dec-02 16:54
valikac21-Dec-02 16:54 
GeneralRe: Search (Compare) Functor and std::pair :: STL Pin
Joaquín M López Muñoz22-Dec-02 20:04
Joaquín M López Muñoz22-Dec-02 20:04 
GeneralRe: Search (Compare) Functor and std::pair :: STL Pin
valikac23-Dec-02 4:59
valikac23-Dec-02 4:59 
GeneralUnsorted Map and Multimap :: STL Pin
valikac21-Dec-02 11:08
valikac21-Dec-02 11:08 
GeneralRe: Unsorted Map and Multimap :: STL Pin
Tim Smith21-Dec-02 11:30
Tim Smith21-Dec-02 11:30 
GeneralRe: Unsorted Map and Multimap :: STL Pin
valikac21-Dec-02 11:43
valikac21-Dec-02 11:43 
GeneralRe: Unsorted Map and Multimap :: STL Pin
Christian Graus21-Dec-02 11:33
protectorChristian Graus21-Dec-02 11:33 
GeneralRe: Unsorted Map and Multimap :: STL Pin
valikac21-Dec-02 12:43
valikac21-Dec-02 12:43 
GeneralRe: Unsorted Map and Multimap :: STL Pin
Christian Graus21-Dec-02 12:46
protectorChristian Graus21-Dec-02 12:46 
GeneralRe: Unsorted Map and Multimap :: STL Pin
valikac21-Dec-02 12:50
valikac21-Dec-02 12:50 
GeneralPackaging a VC++ Software Pin
xxhimanshu21-Dec-02 1:46
xxhimanshu21-Dec-02 1:46 
GeneralRe: Packaging a VC++ Software Pin
Anatoly Ivasyuk24-Dec-02 5:57
Anatoly Ivasyuk24-Dec-02 5:57 
Generalserialize using stream. - binary Pin
magicast20-Dec-02 2:48
magicast20-Dec-02 2:48 
GeneralRe: serialize using stream. - binary Pin
AlexO20-Dec-02 4:04
AlexO20-Dec-02 4:04 
GeneralRe: serialize using stream. - binary Pin
Ben Burnett5-Jan-03 13:17
Ben Burnett5-Jan-03 13:17 
GeneralNeed help using SafeArray/VARIANT from ASP/VBScript client Pin
bahruddina19-Dec-02 16:20
bahruddina19-Dec-02 16:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.