Opened 17 years ago

Closed 13 years ago

#18 closed Bugs (Fixed)

lexical_cast fails in some cases

Reported by: nobody Owned by: kevlin
Milestone: Component: lexical_cast
Version: None Severity:
Keywords: Cc:

Description

The following code causes a bad_lexical_cast exception

std::string x=boost::lexical_cast<std::string>("");

Is this how lexical_cast should perform?

An empty standard string also causes an exception

std::string x=boost::lexical_cast<std::string>(std::string());

I understand that the underlying stringstream causes this behavior but it does not seem to be intuitive. Calls like the ones above can occur when using member templates like the following

class A
{
public:
  template<typename T>
  std::string f(const T& value)
  {
    return boost::lexical_cast<std::string>(value);
  }
}

Solutions to this problem are welcome.

Change History (1)

comment:1 Changed 13 years ago by kevlin

Status: assignedclosed
Note: See TracTickets for help on using tickets.