#include #include #include #include #include #include std::ostream & operator<<(std::ostream & out, const std::vector & v) { std::ostream_iterator it(out); std::copy(v.begin(), v.end(), it); assert(out); return out; } int main() { try { std::vector v; // Uncomment the following line and no exception is thrown. // v.push_back(1); std::cout << boost::lexical_cast(v) << std::endl; } catch (const boost::bad_lexical_cast & ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } }