I am wondering about one thing.
I have code in a function that looks identical, except for one thing that differs depending on one variable.
I will use the example code:
if(value.first == "int")
{
auto temp = value.second;
return std::stoi(temp);
}
else if(value.first == "double")
{
auto temp = value.second;
return std::stod(temp);
}
… etc with other types.
This is, of course, only an insignificant fraction. Let’s say that we have a lot of such else ifs and code in each block even more.
Is it possible to create a single function that can be called with some argument, maybe some template? Which depending on the call will convert these std::sto* to the type it wants.
So as not to write many lines of code just one function.
marcfranc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1