名前空間
変種
操作

std::move

提供: cppreference.com
< cpp‎ | utility


 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
Defined in header <utility>
template< class T >
typename std::remove_reference<T>::type&& move( T&& t );
(C++11およびそれ以降)
std::moveその引数に右辺値参照を取得します。右辺値参照は、他には一時的なオブジェクト、リソースを所有しているオブジェクトへの右辺値参照がオプションを持っている(これは必須ではありません)移動引数のうち、リソースに実行するために渡されたので、ライブラリのコードによって生成されるより迅速に、空の値を持つ引数を残す。ライブラリのコードは、引数に有効な値を残すために必要ですが、そうでなければ型や関数のドキュメントがない限り、結果の引数の値には、他の制約もありません。これは、それが再び引数から移動を使用しないように、一般的に賢明だということを意味します。あなたが再びそれを使用する必要がある場合は、そうする前に既知の値でそれを再初期化するようにしてください.
Original:
std::move obtains an rvalue reference to its argument. Rvalue references are otherwise only produced by temporary objects, so library code that's passed an rvalue reference to a resource-owning object has the option (but isn't required) to move the resource out of the argument in order to run more quickly, leaving the argument with an empty value. The library code is required to leave a valid value in the argument, but unless the type or function documents otherwise, there are no other constraints on the resulting argument value. This means that it's generally wisest to avoid using a moved from argument again. If you have to use it again, be sure to re-initialize it with a known value before doing so.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

t -
オブジェクトを移動することができます
Original:
the object to be moved
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

static_cast<typename std::remove_reference<T>::type&&>(t)

[編集] 例外

noexcept specification:  
noexcept
  (C++11およびそれ以降)

[編集]

#include <iostream>
#include <utility>
#include <vector>
#include <string>
int main()
{
    std::string str = "Hello";
    std::vector<std::string> v;
 
    // uses the push_back(const T&) overload, which means 
    // we'll incur the cost of copying str
    v.push_back(str);
    std::cout << "After copy, str is \"" << str << "\"\n";
 
    // uses the rvalue reference push_back(T&&) overload, 
    // which means no strings will copied; instead, the contents
    // of str will be moved into the vector.  This is less
    // expensive, but also means str might now be empty.
    v.push_back(std::move(str));
    std::cout << "After move, str is \"" << str << "\"\n";
 
    std::cout << "The contents of the vector are \"" << v[0]
                                         << "\", \"" << v[1] << "\"\n";
}

Output:

After copy, str is "Hello"
After move, str is ""
The contents of the vector are "Hello", "Hello"

[編集] 複雑

定数
Original:
Constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] も参照してください

(C++11)
転送関数の引数
Original:
forwards a function argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
ムーブコンストラクタがスローされない場合、右辺値参照を取得します
Original:
obtains an rvalue reference if the move constructor does not throw
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]