Thread: map::erase

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    164

    map::erase

    whats the return types of erase function?????


    Code:
    #include <map>
    void erase( iterator pos );
    void erase( iterator start, iterator end );
    size_type erase( const key_type& key );
    this is what the reference says


    but in the book i'm reading it says that there's also a version which returns an iterator that points to the entry beyond the entry that was removed....

    the book is Beginning Visual C++ 2008

    im using Visual Studio 2005;


    whats wrong here?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Such a version of erase() exists for the sequential containers, e.g., std::vector.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    The standard library only lists those same 3. Perhaps Microsoft has added another.
    Mainframe assembler programmer by trade. C coder when I can.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    164
    Quote Originally Posted by laserlight View Post
    Such a version of erase() exists for the sequential containers, e.g., std::vector.
    Well i defined a map container and applied teh scop3 resolution operator and then i selected the erase, what I saw there were 4 versions of erase, so microsoft have added this, and my code will b non standard if i used this right?

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The bottom line is if you can get around it, do so, as the Standard functions are portable.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    164
    visual C++ also supports standard c++ doesnt it?

    then why the **** it shows a non standard function

    Microsoft is really ........


    Hey is there any option that supports only Standard code in Visual C++?

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >> then why the **** it shows a non standard function
    >> Microsoft is really .......
    They implemented it because it would be useful, I assume, and that their compiler would be the sole tool used in a C++ project is not an unreasonable assumption. Compiler vendors can do these things without violating the Standard.

    For stricter compilation you can change your project properties. C/C++ -> Language -> Disable Language Extensions.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by manzoor
    visual C++ also supports standard c++ doesnt it?

    then why the **** it shows a non standard function
    Logically, if intellisense only shows what is standard, then it will not show you anything about your own code. I suppose they could have made it only show only the standard parts of standard library components, but then what about cases where the user deliberately wants to use extensions to the standard library?

    Quote Originally Posted by manzoor
    Hey is there any option that supports only Standard code in Visual C++?
    You can disable language extensions, but we are talking about an extension to the standard library, so I am not sure if it will have any effect.

    That said, I note that if you are traversing a map to erase elements having a version of erase() that returns an iterator is actually useful. You could always write your own free function version that does the same.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    The C++ Standard Library book addressed this lack of functionality of map::erase not returning an iterator, and even shows a workaround. So, Microsoft was not really out of bounds, IMHO, providing the extension.
    Mainframe assembler programmer by trade. C coder when I can.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by manzoor View Post
    visual C++ also supports standard c++ doesnt it?

    then why the **** it shows a non standard function
    Allow me to introduce you to Microsoft. Manzoor? Microsoft. Microsoft? Manzoor. Now, you guys get some drinks and have a chat.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed