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

  • Home
  • SEARCH
  • 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 7874895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:53:26+00:00 2026-06-03T02:53:26+00:00

The syntax of STL list::insert is as below – iterator insert(iterator __position, const value_type&

  • 0

The syntax of STL list::insert is as below –

  iterator
  insert(iterator __position, const value_type& __x);

Why a iterator instead of a reference to an iterator is being passed?

  • 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-03T02:53:27+00:00Added an answer on June 3, 2026 at 2:53 am

    An implementation would be allowed to pass the iterator by const reference instead of by value. There is no relevant semantic difference.

    Passing by value is slightly more efficient in this case. The iterator object contains a single pointer to a list element object on the heap. Remember that passing by reference is essentially passing by pointer, behind the scenes. (Although a reference is not the same as a pointer, when crossing an actual function call boundary, there is no other viable implementation.)

    So, passing by value means the pointer-to-heap gets passed, but passing by reference means the pointer-to-iterator gets passed, and then two indirections are required inside the insert function. (This does in theory depend on the ABI, but anyway there cannot be a disadvantage to pass by value.)

    A quick illustration of passing semantics:

    template< typename param >
    void same_params( param a, param b ) {
        std::cout << ( &a == &b ) << '\n';
    }
    
    int main() {
        int const five = 5;
        same_params< int const & >( five, five ); // true
        same_params< int const & >( five, 6 ); // false
        same_params< int const & >( five, 5 ); // unspecified
        same_params< int const & >( 5, 5 ); // unspecified
    
        same_params< int >( five, five ); // false (for any arguments)
    }
    

    http://ideone.com/2mC07

    If it weren’t passing pointers, there is no way for same_params< int const & > to work.

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

Sidebar

Related Questions

Based on http://www.cplusplus.com/reference/stl/vector/vector/ explicit vector ( const Allocator& = Allocator() ); This vector constructor
i am reading in a binary file via the usual c++/STL/iostream syntax. i am
Ruby syntax reference says about case statements: Comparisons are done by operator === infact,
I'm trying to understand the syntax used in STL for a class. Our teacher
The syntax for the wait system call is pid= wait(&var) where pid is the
What does the below syntax represents? typedef UserArray<T,W,L,H> MyType; where: T = type of
This code is written on fly, plz ignore syntax mistakes if any. std::list<MY_STRUCT> myList;
I am writing an iterator for a container which is being used in place
The syntax for the setTimeout function in javascript code below is correct setTimeout(document.getElementById('test').style.display='none',3000); I
The syntax for mapping: a = [a, b, c, d] #=> [a, b, c,

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.