Несмотря на то, что вы объявили параметр indirect_print
как type &&
, его класс значений - не rvalue, а lvalue. Любой именованный объект является lvalue.
template <typename type>
void indirect_print(type && value) {
explicit_print(explicit_return::forward<type>(value)); // `value` is lvalue here
}
Вот почему вы всегда вызываете type&
версию вашей forward
.
Удалите explicit_print
и indirect_print
и перепишите main
как:
int main()
{
string a("perfect");
print(explicit_return::forward<std::string>(a));
print(explicit_return::forward<std::string>(move(a)));
print(explicit_return::forward<std::string>("forward"));
}
и вы увидите разницу:
cp-r:perfect
mv-r:perfect
mv-r:forward