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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:38:32+00:00 2026-06-14T10:38:32+00:00

For example: std::vector<std::pair<std::string, bool > > v; std::pair<std::string, bool> pr; v.push_back( pr ); Assuming

  • 0

For example:

std::vector<std::pair<std::string, bool > > v;
std::pair<std::string, bool> pr;
v.push_back( pr );

Assuming std::pair has defined a move assignment operator. Will the call to v.push_back automatically use the
move assignment or I need to specifically ask for it like so?

v.push_back( std::move(pr) );
  • 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-14T10:38:34+00:00Added an answer on June 14, 2026 at 10:38 am

    You will only get a move if the argument of the function (in this case, the argument of push_back) is an rvalue, as well as in certain situations when you return objects from a function.

    In your example, pr is not an rvalue, so you won’t get it moved.

    However, if you – for example – pass a temporary object to the vector, like this:

    v.push_back(std::pair<std::string,bool>());
    

    This will be an rvalue and trigger a move.

    You can also trigger the move by explicitly casting the argument to an rvalue in the way you suggested:

    v.push_back(std::move(pr));
    

    Note, however, that in this case you won’t be able to use pr after the call in a meaningful way any more as its contents have been moved away.

    (Of course, another precondition for a move is that the function you call actually accepts rvalue references. For vector push_back this is indeed the case.)

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

Sidebar

Related Questions

Given: class example { public: std::vector<std::vector<int>> a; int b; } func() { example e;
Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,
What is the cheapest way to initialize a std::vector from a C-style array? Example:
I would like to compare 4 character string using wildcards. For example: std::string wildcards[]=
Example: enum Flags { A, B, C, D }; class MyClass { std::string data;
I have a multimap defined by typedef std::pair<int, int> au_pair; //vertices typedef std::pair<int, int>
It is easy given a container to get the associated iterators, example: std::vector<double>::iterator i;
I'm using multitreading and want to merge the results. For example: std::vector<int> A; std::vector<int>
A different question inspired the following thought: Does std::vector<T> have to move all the
For example, is it possible to have a std::vector of these arrays? int *test1

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.