Boost logo

Boost :

Subject: [boost] [non-instrusive move] interest in new library?
From: THOMAS JORDAN (tomjordan766_at_[hidden])
Date: 2013-01-09 05:40:27

Would there be interest for Boost in a small library providing a simple,
non-instrusive emulation of move semantics for
C++03 (though it could also be used in a C++11 environment)? It consists of
a small number of 'move' function overloads, plus a trait class.
It can be used facilitate move semantics/value-orientated programming in
environments which lack/forbid C++11 or intrusive move libraries, and
facilitate/force copy-elision and RVO optimisations in certain situations
where they might otherwise not occur.

Its mechanism is as follows: it detects at compile-time if the type of the
argument(s) has a member swap function, and if so, it
performs a swap, otherwise is calls the regular assignment operator.

It can be used to provide an emulation of:
move-assignment between lvalues
moving an rvalue to an lvalue
moving an lvalue to a temporary.
It also supports moving between built-in arrays.

Example use-cases are:

//returning a value
std::string foo(std::string s)
     //append something to s
//compiler can perform rvo, if just used 'return s;' compiler would not
perform nrvo
     return move(s); }

//passing a value
std::string s("hello");
void bar(std::string s)
foo(s); //copy
foo(move(s)); //move

//moving a value into place
void MyClass::MyClass(std::string s)
      //move value into default constructed member
      move(s, s_);

Boost list run by bdawes at, gregod at, cpdaniel at, john at