Among other answers, you can also overload foo() :
template <typename T> void foo(T t) {} void foo(std::string &t) {} std::string str("some huge text"); foo(str);
This way you do not change the actual behavior of foo() and do not do your work with the overloaded version.
source share