Can someone give me a convincing argument against always using a templated constructor that perfect forwards its arguments to initialize its member variables?
In the very simple example case:
template<typename T>
class SocketError : public std::exception {
public:
SocketError(T&& what_arg)
: what_arg_(std::forward<T>(what_arg)) { }
virtual const char* what() const noexcept override {
std::cout << what_arg_;
}
private:
std::string what_arg_;
};
A more complicated case might use a variadic template or multiple universal reference constructor arguments.
I'm finding it hard to convince myself that this is a bad idea, so if anyone would like to enlighten me, please do.
Downsides I'm aware of:
Potentially increased size of the object code
Debugging can be a bitch
I'm aware that certain compiler optimizations may make this less valuable, but let's generalize here.