map::erase

This is a discussion on map::erase within the C++ Programming forums, part of the General Programming Boards category; whats the return types of erase function????? Code: #include <map> void erase( iterator pos ); void erase( iterator start, iterator ...

  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
    22,313
    Such a version of erase() exists for the sequential containers, e.g., std::vector.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    Katy, Texas
    Posts
    2,309
    The standard library only lists those same 3. Perhaps Microsoft has added another.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,763
    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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,763
    >> 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
    22,313
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    Katy, Texas
    Posts
    2,309
    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.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21