Kurosaki Isshin and Ishida Ryuuken: Seele Schneider

By: FilipinoDudeNZ

335   6   105120

Uploaded on 05/15/2009

Ryuuken explains the nature of Seele Schneider, ofcourse Isshin is there to tease him.

Comments (2):

By anonymous    2017-09-20

1. "What is it?"

While std::move() "looks like" a function - I would say it isn't really a function. It's sort of a converter between ways the compiler considers an expression's value.

2. "What does it do?"

The first thing to note is that std::move() doesn't actually move anything.

If you've ever watched the animation series Bleach - it does the equivalent of Quincy Seele Schneider's Reishi softening (see also its use in this scene).

Seriously, though, it converts an expression from being an lvalue or pure rvalue (such as a variable you might be using for a long time yet, or a temporary you're passing around for a while, respectively) to being an xvalue. An xvalue tells the compiler:

You can plunder me, move anything I'm holding and use it elsewhere (since I'm going to be destroyed soon anyway)".

in other words, when you use std::move(x), you're allowing yourself (or the compiler) to cannibalize x. So if x has, say, its own buffer in memory - after std::move()ing you can use that buffer for whatever else you like.

3. "When should it be used?"

Another way to ask this question is "What would I use/cannibalize an object's resources for?" well, if you're writing application code, you would probably not be messing around a lot with temporary objects created by the compiler. So mainly you would do this in places like constructors, operator methods, STL-algorithm-like functions etc. where objects get created and destroyed automagically alot. Of course, that's just a rule of thumb.

A typical use is 'moving' resources from one object to another instead of copying. @Guillaume links to this page which has a straightforward short example: swapping two objects with less copying.

template <class T>
swap(T& a, T& b) {
    T tmp(a);   // we now have two copies of a
    a = b;      // we now have two copies of b (+ discarded a copy of a)
    b = tmp;    // we now have two copies of tmp (+ discarded a copy of b)

using move allows you to swap the resources instead of copying them around:

template <class T>
swap(T& a, T& b) {
    T tmp(std::move(a));
    a = std::move(b);   
    b = std::move(tmp);

Think of what happens when T is, say, vector<int> of size n. In the first version you read and write 3*n elements, in the second version you basically read and write just the 3 pointers to the vectors' buffers. Of course, class T needs to know how to do the moving; you should have a move-assignment operator and a move-constructor for class T for this to work.

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.