Boost logo

Boost :

From: Robin (darkaurora_at_[hidden])
Date: 2001-09-27 03:46:31


Sorry if this is a well discussed to death issue but why is
lexical_cast taking a parameter by value and not const reference?

Given that string types may be passed as the source, passing by value
is not efficient.

Is there any distinct reason to pass by value, other than following
standard casting convention??

Also, throwing an exception when a lexical_cast fails is not always
ideal. Why not overload it to return a return code? Something like

template <typename Target, typename Source>
  bool lexical_cast( Target &target, const Source &src )
{
  std::stringstream ss;

  if ( !( ss << src) || !( ss >> target) || !( ss >> std::ws).eof() )
  {
    return false;
  }
  return true;
}

PS:I found a similiar discussion Nov 2000 but the issue seems
unresolved. So what is the status?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk