c++ - Using move semantic to push element into two containers -


i have read moving semantics , rvalue reference.

having class has 2 containers of pointers struct. e.g

struct person{    person(int , int a){       id  = i;       age =    }    person(person && p){        id  = p.id;        age = p.id;    }    int id;    int age; } class holder{   private:    vector<person*> one;    vector<person*> two; } 

both containers should recieve same person , , 1 should sorted age , id. like

void person::insert( int age , int id ){     person* tmp = new person(age , id );     one.push_back(tmp);     // sort somehow 1 .. isnt important example     two.push_back(tmp);     // same sort } 

but improved using r-value reference , moving semantic? make step faster / better memory cost? , first of make sense it? e.g

   void person::insert(person*&& p){        one.push_back(p);        // sort        two.push_back(p);        // sort?    } 

i appreciate explanation of concept in case misunderstood move semantic.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -