Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:12:54+00:00 2026-06-01T20:12:54+00:00

About the STL container set and multiset ,the return types of the insert functions

  • 0

About the STL container set and multiset,the return types of the insert functions are not all the same.
set provides the following interface:

pair<iterator,bool> insert(const value_type& elem); 
iterator  insert(iterator pos_hint, const value_type& elem); 

multiset provides the following interface:

iterator  insert(const value_type& elem); 
iterator  insert(iterator pos_hint, const value_type& elem);

In the first function of set, the member second of the pair structure returns whether the insertion is successful.The insertion of an element might fail for a set if it already contains an element with the same value.But in the second function of set,the insert function just returns an iterator.What will happen if the insertion fails?Could someone tell me that?
Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:12:55+00:00Added an answer on June 1, 2026 at 8:12 pm

    But in the second function of set,the insert function just returns an iterator.What will happen if the insertion fails?

    In the set::insert version that just returns a plain iterator (and not a pair<iterator,bool>), when an existing element is found the set is left unchanged and the insert will return an iterator to the existing element (that prevented the insertion).

    In multiset::insert, the function is always successful.

    23.2.4 Associative Container Requirements

    iterator a.insert(p, t)

    Effects: Inserts t if and only if there is no element with key
    equivalent to the key of t in containers with unique keys; always
    inserts t in containers with equivalent keys. always returns the
    iterator pointing to the element with key equivalent to the key of t.
    t is inserted as close as possible to the position just prior to p.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning STL now. I read about set container. I have question when
I'm a bit confused about using STL set::find() for a set of my own
I asked a question while ago about accessing the underlying container of STL adapters
I'm implementing a custom container with an STL-like interface for a 3D grid control
I need a container that implements the following API (and need not implement anything
I've always been a bit confused about how STL containers (vector, list, map...) store
I'm reading about STL algorithms and the book pointed out that algorithms like find
I have some questions about vector in STL to clarify..... Where are the objects
About to create a form using Zend Form, all the form elements should have
I want to perform deep copies of an STL container of pointers to polymorphic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.