0

I have encountered this sentence in the following blog entry ( https://latedev.wordpress.com/2011/11/16/c-stringstreams/ )

Secondly, the use of a reference as a parameter is a little inefficient for the built-in types like int and double (...)

Is this true? If so why? I've always thought that it's better to use references not to produce copies for methods like :

template <typename T>
string ToStr( const T & t ) {
  ostringstream os;
  os << t;
  return os.str();
}
Patryk
  • 22,602
  • 44
  • 128
  • 244
  • Don't believe everything you read in blogs. The extra memory move will have no impact on almost any program you will ever write. Furthermore, the compiler is free to optimise the use of a reference away if it can prove that there are no aliases to your variable on the code path. – Richard Hodges Dec 13 '14 at 13:05
  • I didn't blindly believe therefore I have asked for more insight into this ;) – Patryk Dec 13 '14 at 13:07

0 Answers0