mardi 5 septembre 2017

std::forward in non-template function [duplicate]

This question already has an answer here:

There is some function that has rvalue argument. There is an other function that also has rvalue argument. The first function calls the second function:

void inner(int&& a)
{/* ... */}

void outer(int&& a)
{
    inner(std::move(a));
}

I used std::move because we use std::move to pass parameter as rvalue. But my colleague said that std::forward is more appropriate here because we forward (not move) rvalue reference here:

void outer(int&& a)
{
    inner(std::forward(a));
}

Is it true? Which variant is more correct?

Aucun commentaire:

Enregistrer un commentaire