Boost logo

Boost Users :

Subject: [Boost-users] lexical_cast throws when used with empty vector (1.48.0)
From: Braden Northington McDaniel (braden_at_[hidden])
Date: 2011-12-18 01:53:46


Boost 1.48.0's lexical_cast throws bad_lexical_cast when used with an empty vector. This is observable in the following program:

#include <boost/lexical_cast.hpp>
#include <cassert>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

std::ostream & operator<<(std::ostream & out, const std::vector<long> & v)
{
  std::ostream_iterator<long> it(out);
  std::copy(v.begin(), v.end(), it);
  assert(out);
  return out;
}

int main()
{
  std::vector<long> v;
  //v.push_back(1);
  std::cout << boost::lexical_cast<std::string>(v);
}

If the commented line is uncommented (making the vector nonempty), the program runs without an exception.
Is this the intended behavior?

-- 
Braden McDaniel
e-mail/Jabber IM: braden_at_[hidden]
http://endoframe.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net