mercredi 12 décembre 2018

What's difference between forward and move in the constructor of class?

I read a lot about it but still can't get. What's difference between these two variants:

template <typename val_t>
class fact_t: public exp_t<val_t> {
    val_t m_value;
public:
    fact_t(val_t &&value) : m_value{std::forward<val_t>(value)} {}
};

template <typename val_t>
class fact_t: public exp_t<val_t> {
    val_t m_value;
public:
    fact_t(val_t &&value) : m_value{std::move(value)} {}
};

Can someone show an example when one variant will fail but another will work still?

Aucun commentaire:

Enregistrer un commentaire