I have a function like this:
void init_str(std::string _s)
{
std::string s{_s};
}
And I want to have an optimization by allowing a const char* overload to avoid creating a temporary std::string.
void init_str(const char* c)
{
std::string s{c};
}
But I can also use forwarding as well.
template<typename T>
void init_str(T&& t)
{
std::string s{std::forward<T>(t)};
}
But the preference of overloads by the compiler is:
const char*- forwarding
std::string
So what combination of overloads should I prefer?
Aucun commentaire:
Enregistrer un commentaire