]> git.lyx.org Git - lyx.git/blob - boost/boost/lexical_cast.hpp
complie fix
[lyx.git] / boost / boost / lexical_cast.hpp
1 //  boost lexical_cast.hpp header  -------------------------------------------//
2
3 //  See http://www.boost.org for most recent version including documentation.
4
5 #ifndef BOOST_LEXICAL_CAST_INCLUDED
6 #define BOOST_LEXICAL_CAST_INCLUDED
7
8 // what:  lexical_cast custom keyword cast
9 // who:   contributed by Kevlin Henney, with alternative naming, behaviors
10 //        and fixes contributed by Dave Abrahams, Daryle Walker and other
11 //        Boosters on the list
12 // when:  November 2000
13 // where: tested with MSVC 6.0, BCC 5.5, and g++ 2.91
14
15 #include <boost/config.hpp>
16
17 // Some sstream implementations are broken for the purposes of lexical cast.
18 # if defined(BOOST_NO_STRINGSTREAM)
19 #  define BOOST_LEXICAL_CAST_USE_STRSTREAM
20 # endif
21
22 #ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
23 # include <strstream>
24 #else
25 # include <sstream>
26 #endif
27
28 #include <typeinfo>
29
30 namespace boost
31 {
32     // exception used to indicate runtime lexical_cast failure
33     class bad_lexical_cast : public std::bad_cast
34     {
35     public:
36         // constructors, destructors, and assignment operator defaulted
37
38         // function inlined for brevity and consistency with rest of library
39         virtual const char * what() const throw()
40         {
41             return "bad lexical cast: "
42                    "source type value could not be interpreted as target";
43         }
44     };
45
46     template<typename Target, typename Source>
47     Target lexical_cast(Source arg)
48     {
49 # ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
50         std::strstream interpreter; // for out-of-the-box g++ 2.95.2
51 # else
52         std::stringstream interpreter;
53 # endif
54         Target result;
55
56         if(!(interpreter << arg) || !(interpreter >> result) ||
57            !(interpreter >> std::ws).eof())
58             throw bad_lexical_cast();
59
60         return result;
61     }
62 }
63
64 // Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
65 //
66 // Permission to use, copy, modify, and distribute this software for any
67 // purpose is hereby granted without fee, provided that this copyright and
68 // permissions notice appear in all copies and derivatives.
69 //
70 // This software is provided "as is" without express or implied warranty.
71
72 #ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM
73 # undef BOOST_LEXICAL_CAST_USE_STRSTREAM
74 #endif
75
76 #endif