@@ -6,22 +6,21 @@ namespace json {
66namespace detail {
77
88template <class In , class Tr >
9- void print_exception_details_internal (In first, In current, In last , const Tr&) {
9+ int distance_in_stream_internal (In first, In current, const Tr&) {
1010 (void )first;
1111 (void )current;
12- ( void )last ;
12+ return - 1 ;
1313}
1414
1515template <class In >
16- void print_exception_details_internal (In first, In current, In last, const std::random_access_iterator_tag &) {
17- (void )last;
18- std::cerr << " an error occured " << std::distance (first, current) << " characters into the stream:" << std::endl;
16+ int distance_in_stream_internal (In first, In current, const std::random_access_iterator_tag &) {
17+ return std::distance (first, current);
1918}
2019
2120template <class In >
22- void print_exception_details (In first, In current, In last ) {
21+ int distance_in_stream (In first, In current) {
2322 typedef typename std::iterator_traits<In>::iterator_category Cat;
24- print_exception_details_internal (first, current, last , Cat ());
23+ return distance_in_stream_internal (first, current, Cat ());
2524}
2625
2726}
@@ -33,8 +32,8 @@ value parse(In first, In last) {
3332
3433 try {
3534 return p.parse ();
36- } catch (const exception &e) {
37- detail::print_exception_details (p.begin (), p.current (), p. end ());
35+ } catch (exception &e) {
36+ e. location = detail::distance_in_stream (p.begin (), p.current ());
3837 throw ;
3938 }
4039}
@@ -55,7 +54,11 @@ inline double to_number(const value &v) {
5554 if (!is_number (v)) {
5655 throw invalid_type_cast ();
5756 }
57+ #if __cplusplus >= 201103L
58+ return stod (as_string (v), 0 );
59+ #else
5860 return strtod (as_string (v).c_str (), 0 );
61+ #endif
5962}
6063
6164inline object to_object (const value &v) {
0 commit comments