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 9023475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:46:11+00:00 2026-06-16T05:46:11+00:00

Some methods of std::list, and probably other STL containers, have a new overload added

  • 0

Some methods of std::list, and probably other STL containers, have a new overload added in C++11. The one I need is list::splice(). One method takes a list& parameter, the other one takes a list&& parameters.

I’d like to know what the difference, and which ine I should prefer.

I looked at the implementation of libstdc++ (the standard C++ library used by the GCC compiler) and it uses the list&& version in both cases internally. Also the C++11 specification says nothing about this issue. It just offers 2 methods without explaining the difference.

You don’t move the list itself, and you don’t move the nodes (copying their pointers seems like the way to move nodes from one list to another), so why does it matter? I have just one idea, maybe using list&& is like a promise to the compiler you don’t need the other list anymore and the the compiler can save a few operations because it doesn’t have to keep the other list valid…

  • 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-16T05:46:13+00:00Added an answer on June 16, 2026 at 5:46 am

    You shouldn’t need to care very much. The overload with the std::list&& parameter will be chosen when the argument you pass is an rvalue – usually when the object it refers to is a temporary. You don’t need to explicitly say which overload you want to use.

    The reason these two versions of the function exist is for convenience, so that the client doesn’t have to create a temp std::list variable from the temporary object before passing it to splice (thanks to @HowardHinnent in the comments).

    Also, when the list you’re splicing from is a temporary object, there’s no point caring about maintaining its state. The && version of the function may just rip the guts from that list, leaving a mess all over the floor. This might be done for efficiency (but actually, std::list doesn’t have much reason to).

    If you have a std::list, other, that you know you’ll never use again, you can voluntarily say “I don’t care what you do with it”, by using std::move:

    l.splice(pos, std::move(other));
    

    The expression std::move(other) is an rvalue, so the splice function will treat it as though it were a temporary.

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

Sidebar

Related Questions

I have some C++ methods that have std::set<std::string> as argument or return value. I
I used SWIG to wrap my c++ class. Some methods have a const std::string&
I have some code which deals with various std::list objects, and I am currently
I have one std::list<> container and these threads: One writer thread which adds elements
I have some methods that are used by several classes. My idea was to
I need to call some methods in Wininet.dll from a Java program. I can
I need to run some methods before the first call of a wcf service,
Just random pick some methods that I have found: sforce.connection.describeSObject sforce.SearchResult sforce.sObject sforce.LeadConvert() sforce.connection.create()
So I have made a .dll containing some methods that I wish to use
I have a list of about a hundreds unique strings in C++, I need

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.