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?
I tried to use the first variant the next way:
std::string str = "str";
fact_t<std::string> f(str);
But it leads to an error of compile time. Although as I understood from other topics and cppreference that str
is lvalue and std::forward
allows to use it. Where am I missing?
P.S. I'm sorry if is a stupid question but I really can't get.