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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:08:22+00:00 2026-06-10T06:08:22+00:00

Possible Duplicate: What constitutes a valid state for a “moved from” object in C++11?

  • 0

Possible Duplicate:
What constitutes a valid state for a “moved from” object in C++11?

Consider something like this:

class Foo {};  
std::vector<Foo> v( 5 );

Is it legal to do something like:

v.front() = std::move( v.back() );  

provided that I do something like this afterwards:

v.pop_back();  

More precisely I want to know what is required for an xvalue that has undergone std::move() semantics.
I know it needs to be destructible (obviously). But anything else? Suppose I would call std::vector::insert() or some other function, that may do some copying/moving of the std::move()ed value behind the scenes.
Is that still legal?

In my real case I have std::vector<std::vector<Foo>> and do stuff with that.
But I don’t know if it is legal to std::move() from a std::vector that is still used by the outer std::vector.

  • 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-10T06:08:24+00:00Added an answer on June 10, 2026 at 6:08 am

    Yes, this is valid: you can always destroy a moved-from object. (I cannot find where–or whether–this is specified in the C++ language standard, but if a moved-from object could not be destroyed, I’m sure we’d all consider that a bug.) Since your code only destroys the moved-from object, your code is fine.

    The Standard Library imposes additional requirements on the state of a moved-from object and any type with which a Standard Library component is instantiated must follow these additional rules. The gist is that move and copy operations that are valid on non-moved-from objects of a type must also be valid for moved-from objects of the type. So, for example, after moving the last element, you could assign that element a new value: v.back() = Foo();.

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

Sidebar

Related Questions

Possible Duplicate: When do you use the “this” keyword? If I have the following
Possible Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode? What constitutes a
Possible Duplicate: Find the “#” character in a string with Javascript How do I
Possible Duplicate: Array to named variables How can I convert an array like this
Possible Duplicate: Is there a printf converter to print in binary format? Consider this
Possible Duplicate: Javascript === vs == : Does it matter which “equal” operator I
Possible Duplicate: Is there a way to create a SQL Server function to “join”
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: php == vs === operator Reference - What does this symbol mean

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.