Ticket #6298: lexical_cast_test.cpp

File lexical_cast_test.cpp, 636 bytes (added by Braden McDaniel <braden@…>, 11 years ago)

Test case

Line 
1#include <boost/lexical_cast.hpp>
2#include <cassert>
3#include <iostream>
4#include <iterator>
5#include <string>
6#include <vector>
7
8std::ostream & operator<<(std::ostream & out, const std::vector<long> & v)
9{
10 std::ostream_iterator<long> it(out);
11 std::copy(v.begin(), v.end(), it);
12 assert(out);
13 return out;
14}
15
16int main()
17{
18 try {
19 std::vector<long> v;
20 // Uncomment the following line and no exception is thrown.
21 // v.push_back(1);
22 std::cout << boost::lexical_cast<std::string>(v) << std::endl;
23 } catch (const boost::bad_lexical_cast & ex) {
24 std::cerr << ex.what() << std::endl;
25 return EXIT_FAILURE;
26 }
27}