In this talk by Sutter at 1:15:26 it was presented a code like below,
class A{
std::string name_;
public:
template<class String, class=
std::enable_if_t< !std::is_same<std::decay_t<String>, std::string>::value > >
void set_name(String && name)
noexcept(std::isnothrow_assignable<std::string &, String>::value)
{
name_ = std::forward<String>(name);
}
}
I know how std::forward works, if name is a lvalue, name_ will get copy constructed; and if name is a rvalue, name_ will get move constructed. But in the slide it also says that Optimized to steal from rvalues (and more), what is more?
And later it shows that this code seems the fastest among all the four implementations, especially for char *, anybody has the patience to walk through this code and explain what more is being optimized and why it is the fastest, particularly in the case of char * ?
Aucun commentaire:
Enregistrer un commentaire