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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:20:05+00:00 2026-05-31T17:20:05+00:00

In C++11, value parameters (and other values) enjoy implicit move when returned: A func(A

  • 0

In C++11, value parameters (and other values) enjoy implicit move when returned:

A func(A a) {
    return a; // uses A::A(A&&) if it exists
}

At least in MSVC 2010, rvalue reference parameters need std::move:

A func(A && a) {
    return a; // uses A::A(A const&) even if A::A(A&&) exists
}

I would imagine that inside functions, an rvalue reference and a value behave similar, with the only difference that in case of values, the function itself is responsible for destruction, while for rvalue references, the responsibility is outside.

What is the motivation for treating them differently in the standard?

  • 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-05-31T17:20:06+00:00Added an answer on May 31, 2026 at 5:20 pm

    The standardization committee expended great effort in creating wording so that moves would only ever happen in exactly two circumstances:

    1. When it is clearly safe to do so.
    2. When the user explicitly asks (via std::move or a similar cast).

    A value parameter will unquestionably be destroyed at the end of the function. Therefore, returning it by move is clearly safe; it can’t be touched by other code after the return (not unless you’re deliberately trying to break things, in which case you probably triggered undefined behavior). Therefore, it can be moved from in the return.

    A && variable could be referring to a temporary. But it could be referring to an lvalue (a named variable). It is therefore not clearly safe to move from it; the original variable could be lurking around. And since you didn’t explicitly ask to move from it (ie: you didn’t call std::move in this function), no movement can take place.

    The only time a && variable will be implicitly moved from (ie: without std::move) is when you return it. std::move<T> returns a T&&. It is legal for that return value to invoke the move constructor, because it is a return value.

    Now it is very difficult to call A func(A &&a) with an lvalue without calling std::move (or an equivalent cast). So technically, it should be fine for parameters of && type to be implicitly moved from. But the standards committee wanted moves to be explicit for && types, just to make sure that movement didn’t implicitly happen within the scope of this function. That is, it can’t use outside-of-function knowledge about where the && comes from.

    In general, you should only take parameters by && in two cases: either you’re writing a move constructor (or move assignment operator, but even that can be done by value), or you’re writing a forwarding function. There may be a few other cases, but you shouldn’t take && to a type unless you have something special in mind. If A is a moveable type, then just take it by value.

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

Sidebar

Related Questions

Can a function return more than one value directly (i.e., without returning in parameters
I have a bunch of named value parameters in a Dictionary<string, object> , which
I got this parameter: $objDbCmd.Parameters.Add(@telephone, [System.Data.SqlDbType]::VarChar, 18) | Out-Null; $objDbCmd.Parameters[@telephone].Value = $objUser.Telephone; Where the
How can I get the value of the URL hash (eg PARAMETERS in url
I have passed to template dictionary parameters like parameters={ 'value':'some_value', 'style':{} } and inside
im trying to pass two parameters to a function, i being an int value
I have a parameter @Department and set its value in the Dataset to =Join(Parameters!Department.Value,,)
I understand that if I enter the following =IIf(Parameters!HOURINPUT.Value = 1, true, false) into
Is there a preferred way to return multiple values from a C++ function? For
I have a dataset that returns a '' (blank) value amongst the other records.

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.