So basically my question is: When should I use an rvalue reference? In this example, I'm working on a logger class (it just logs things to the console...). I have different functions to log messages on different log levels. They take in an std::string as a parameter. Should I have two versions of each function, the first one for a "normal" reference and the second for an rvalue reference?
namespace lnr
{
class logger
{
public:
logger(const string& name);
logger(const string&& name);
~logger() = default;
const void trace(const string& message) const;
const void trace(const string&& message) const;
const void info(const string& message) const;
const void info(const string&& message) const;
const void warn(const string& message) const;
const void warn(const string&& message) const;
const void error(const string& message) const;
const void error(const string&& message) const;
private:
const string name;
};
}
Because it is quiete common to log something with both
logger.trace("Hello");
and
std::string error_message = "...";
logger.error(error_message);
But having every function two times is really weird and it also seems a bit unnecessary...