I have these typedefs for std::string and a function
using FirstName = std::string;
using SecondName = std::string;
void DoSmth(const FirstName& f, const SecondName& s)
{
/* some mixture of f.empty(), s.size(), f.substr() and other useful std::string member functions*/
}
How can I teach the compiler to warn me in the next DoSmth call:
void CallDoSmth()
{
FirstName f = "Sher";
SecondName s = "Andrei";
DoSmth(s, f);
}
Here is one implementation with tags. Another solution would be:
struct FirstName {
std::string value;
explicit FirstName(std::string str) : value(std::move(str)) {}
};
In both presented solutions there is an overhead to call member functions of a std::string. Is there a way to get an error in CallDoSmth(), but do not change anything in DoSmth()?