I'm writing a bunch of functions like this:
template <>
Error SyntaxError<unfinished_string>(unsigned int line) {
std::stringstream message;
message << "SyntaxError: unfinished string (starting at line " << line << ").";
return Error(Error::Type::syntax, message.str());
}
template <>
Error SyntaxError<malformed_number>(std::string number, unsigned int line) {
std::stringstream message;
message << "SyntaxError: malformed number (" << number << ") at line " << line << '.';
return Error(Error::Type::Syntax, message.str());
}
...
And it wouldn't be bad to have a variadic function / macro that looked something like this:
Error proto(/*variable number & type of arguments*/) {
std::stringstream message;
message << "SyntaxError: " << /*arguments passed, separated by <<s */;
return Error(Error::Type::syntax, message.str());
}
So that I could then write my functions as:
template <>
Error SyntaxError<unfinished_string>(unsigned int line) {
return proto("unfinished string (starting at line ", line, ").");
}
template <>
Error SyntaxError<malformed_number>(std::string number, unsigned int line) {
return proto("malformed number (", number, ") at line ", line, '.');
}
Is that by any chance possible? How if yes?