std ::前方和のstd ::移動

std ::前方パーフェクト前方

元のプロパティのパラメータ(パラメータテンプレートには、引用時間である)ことを保証するために:プロパティの値が転送された後に残った基準値が残ったままで、右基準値は転送された後のプロパティの正しい値のまま

void show(std::string& str) {
    std::cout<<"lvalue:"<<str<<std::endl;
}

void show(std::string&& str) {
    std::cout<<"rvalue:"<<str<<std::endl;
}


template<typename T>
void ShowWrapper(T&& t) {
    show(std::forward<T>(t));
}

void TestForward() {
    std::string str("left");
    ShowWrapper(str);//lvalue:left
    ShowWrapper("right"); //rvalue:right
}

std ::移動

右の値に左の値

void TestMove() {
    std::string str("move");
    ShowWrapper(str);//rvalue:move
}

おすすめ

転載: www.cnblogs.com/smallredness/p/11085369.html