#include <iostream>
#include <string>
struct S {
std::string name_ = "defaulted";
S()
{
std::cout << "ctor\n";
}
S(const char* name) : name_(name) {
std::cout << "char* ctor \n";
}
S(const S& copy)
{
std::cout << "copy ctor\n";
name_ = copy.name_;
}
S(S&& rhs) {
std::cout << "move ctor " << name_ << "\n";
name_ = rhs.name_;
rhs.name_ = "new";
name_ += " moved"; }
};
void fn(S s)
{
std::cout << "fn(" << s.name_ << ")\n";
}
template<typename T>
void fwd_test(T&& t)
{
fn(std::forward<T>(t));
fn(std::forward<T>(t));
}
int main() {
fwd_test(S("source"));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKc3RydWN0IFMgewoJc3RkOjpzdHJpbmcgbmFtZV8gPSAiZGVmYXVsdGVkIjsKCVMoKQoJewoJCXN0ZDo6Y291dCA8PCAiY3RvclxuIjsKCX0KCVMoY29uc3QgY2hhciogbmFtZSkgOiBuYW1lXyhuYW1lKSB7CgkJc3RkOjpjb3V0IDw8ICJjaGFyKiBjdG9yIFxuIjsKCX0KCVMoY29uc3QgUyYgY29weSkKCXsKCQlzdGQ6OmNvdXQgPDwgImNvcHkgY3RvclxuIjsKCQluYW1lXyA9IGNvcHkubmFtZV87Cgl9CglTKFMmJiByaHMpIHsgCgkJc3RkOjpjb3V0IDw8ICJtb3ZlIGN0b3IgIiA8PCBuYW1lXyA8PCAiXG4iOwoJCW5hbWVfID0gcmhzLm5hbWVfOwoJCXJocy5uYW1lXyA9ICJuZXciOwoJCW5hbWVfICs9ICIgbW92ZWQiOyB9Cn07Cgp2b2lkIGZuKFMgcykKewoJc3RkOjpjb3V0IDw8ICJmbigiIDw8IHMubmFtZV8gPDwgIilcbiI7Cn0KCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnZvaWQgZndkX3Rlc3QoVCYmIHQpCnsKCWZuKHN0ZDo6Zm9yd2FyZDxUPih0KSk7CglmbihzdGQ6OmZvcndhcmQ8VD4odCkpOwp9CgppbnQgbWFpbigpIHsKCWZ3ZF90ZXN0KFMoInNvdXJjZSIpKTsKfQ==