CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Building Interactive UIs with ASP.NET Ajax: Rebinding Client-Side Events After a Partial Page Postback
  • Speed Up Repetitive Insert, Update, and Delete Query Statements
  • Binding Data to Silverlight 4.0 Controls Using ASP.NET MVC Framework 2.0
  • ADO.NET Data Services in the .NET Framework

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old February 19th, 2010, 07:11 AM
    airo.miranda airo.miranda is offline
    Junior Member
     
    Join Date: Feb 2010
    Posts: 12
    airo.miranda is an unknown quantity at this point (<10)
    Getting Map Position

    Hello All, have another doubt in maps.
    Suppose the following code:

    map<unsigned long long, cars> > carOne;

    cars anyCar;

    mapOne[anyKey] = anyCar;

    When I do the last command, is there anyway that I can find the position in mapOne where the anyCar was inserted without needing to use the mapOne.find(anyKey) command?

    Thanks in advance!
    Reply With Quote
      #2    
    Old February 19th, 2010, 07:30 AM
    laserlight laserlight is online now
    Elite Member
    Power Poster
     
    Join Date: Jan 2006
    Location: Singapore
    Posts: 4,808
    laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)laserlight has much to be proud of (1500+)
    Re: Getting Map Position

    I do not think so. Take a look at this thread on efficient map(/set) insertion.
    __________________
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful
    Reply With Quote
      #3    
    Old February 19th, 2010, 09:42 AM
    monarch_dodra's Avatar
    monarch_dodra monarch_dodra is online now
    Senior Member
     
    Join Date: Jun 2009
    Location: France
    Posts: 1,204
    monarch_dodra is a jewel in the rough (200+)monarch_dodra is a jewel in the rough (200+)monarch_dodra is a jewel in the rough (200+)
    Re: Getting Map Position

    Quote:
    Originally Posted by laserlight View Post
    I do not think so. Take a look at this thread on efficient map(/set) insertion.
    Hehe, sorry for never answering that thread, but rest assure your reply was read.

    On a side note, I would answer yes, it is possible. If you use lower_bound before you insert, then you should get an iterator.

    Either your iterator points to your actual object, and you don't need to find.

    Either the object is not in your map, you can use insertion with hint, and then, your object will be inserted at --iterator position.

    But to be quite frank, unless your application is absolutly time critical, all this extra development really isn't worth the performance gain, given the potential for disastrous bugs... (what if your map was empty when you lower bounded, what if --iterator is before begin etc...). Potential for bugs: 90%.

    I would just stick to map[key] = value; it = find(key);
    Potential for bugs: 10%.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:25 AM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.