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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:15:58+00:00 2026-06-06T14:15:58+00:00

It is often said that in C++11 it is sane to return std::vector by

  • 0

It is often said that in C++11 it is sane to return std::vector by value.

In C++03 this was mostly true as RVO should optimize away the copy. But that should scared most developers away.

  • In C++11 will a returned std::vector local variable always be moved?
  • What if that vector is a member of a local variable instead of a local variable itself?
  • Obviously returning a global variable will not be moved. What other cases will it not be moved?
  • 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-06T14:16:00+00:00Added an answer on June 6, 2026 at 2:16 pm

    First, every time a copy could be elided before, it can still be elided now, and moves can be elided in the same situations. For the rest of this post I’ll assume that elision doesn’t happen for some reason (pretend the compiler writer was lazy in a bad way).

    In C++11 will a returned std::vector local variable always be moved?

    Every time the criteria for copy elision are met, or the variable is explicitly std::moved.

    What if that vector is a member of a local variable instead of a local variable itself?

    It won’t be moved unless explicitly std::moved.

    Obviously returning a global variable will not be moved. What other cases will it not be moved?

    Every time the criteria for copy elision are not met and the variable is not explicitly std::moved.

    None of those is a valid reason to not to return by value. Return by value is ok, because even when the value is not automatically moved you can force it with std::move.

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

Sidebar

Related Questions

It is often said that, you should not rebase commits that you have already
I was often said that rule : HTML is static ; in other words
I come from a python background, where it's often said that it's easier to
It seems to be often said that Task Manager does not provide an accurate
Possible Duplicate: What is a translation unit in C++ It is often said that
It is often said when unit testing to dont test the database as that
It is often said that using LDAP is a good way to store data
It is often said that the code with lots of templates is going to
Often, when searching for answers, I have found that certain websites will allow you
Often when writing PHP I'll have it output some HTML like this - echo

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.