*/
class lexical_error: public std::runtime_error
{
public:
lexical_error(const std::string &w): runtime_error(w) { }
*/
class lexical_error: public std::runtime_error
{
public:
lexical_error(const std::string &w): runtime_error(w) { }
class format_mismatch: public lexical_error
{
public:
format_mismatch(const std::string &w): lexical_error(w) { }
class format_mismatch: public lexical_error
{
public:
format_mismatch(const std::string &w): lexical_error(w) { }
- LexicalConverter(const std::string &s, const Fmt &f): fmt(f), buf(s) { }
+ LexicalConverter(const std::string &s, const Fmt &f): fmt(f), filled(true), buf(s) { }
void operator<<(LexicalConverter &, unsigned short);
void operator<<(LexicalConverter &, unsigned);
void operator<<(LexicalConverter &, unsigned long);
void operator<<(LexicalConverter &, unsigned short);
void operator<<(LexicalConverter &, unsigned);
void operator<<(LexicalConverter &, unsigned long);
void operator<<(LexicalConverter &, long long);
void operator<<(LexicalConverter &, unsigned long long);
void operator<<(LexicalConverter &, long long);
void operator<<(LexicalConverter &, unsigned long long);
void operator<<(LexicalConverter &, bool);
void operator<<(LexicalConverter &, float);
void operator<<(LexicalConverter &, double);
void operator<<(LexicalConverter &, bool);
void operator<<(LexicalConverter &, float);
void operator<<(LexicalConverter &, double);
void operator>>(const LexicalConverter &, unsigned short &);
void operator>>(const LexicalConverter &, unsigned int &);
void operator>>(const LexicalConverter &, unsigned long &);
void operator>>(const LexicalConverter &, unsigned short &);
void operator>>(const LexicalConverter &, unsigned int &);
void operator>>(const LexicalConverter &, unsigned long &);
void operator>>(const LexicalConverter &, long long &);
void operator>>(const LexicalConverter &, unsigned long long &);
void operator>>(const LexicalConverter &, long long &);
void operator>>(const LexicalConverter &, unsigned long long &);
void operator>>(const LexicalConverter &, bool &);
void operator>>(const LexicalConverter &, float &);
void operator>>(const LexicalConverter &, double &);
void operator>>(const LexicalConverter &, bool &);
void operator>>(const LexicalConverter &, float &);
void operator>>(const LexicalConverter &, double &);
- static T &v;
-
- /* The expression must depend on the template parameter, or the compiler
- will give an error. */
- template<typename U>
- static Yes f(int (*)[sizeof(s<<HasFormattedOutput<U>::v)]);
- template<typename U>
- static No f(...);
-
- enum { value = Evaluate<sizeof(f<T>(0))>::value };
+ template<typename T>
+ static Yes f(int (*)[sizeof(s<<reinterpret_cast<const T &>(s))]);
+ using Sfinae::f;
operator>>(const LexicalConverter &c, T &v)
{
std::istringstream ss(c.get());
ss.setf(std::ios_base::fmtflags(0), std::ios_base::skipws);
operator>>(const LexicalConverter &c, T &v)
{
std::istringstream ss(c.get());
ss.setf(std::ios_base::fmtflags(0), std::ios_base::skipws);
static std::string cast(const F &v, const Fmt &f = Fmt())
{
LexicalConverter conv(f);
static std::string cast(const F &v, const Fmt &f = Fmt())
{
LexicalConverter conv(f);
static std::string cast(const std::string &v, const Fmt &f = Fmt())
{
LexicalConverter conv(f);
static std::string cast(const std::string &v, const Fmt &f = Fmt())
{
LexicalConverter conv(f);
-// The main interface to the lexical conversion machinery
-
+/** Perform a lexical conversion between a string and another type. The source
+type can normally be deduced by the compiler, so this can be used just like the
+standard C++ casts. A format may additionally be specified to force a specific
+interpretation. */
template<typename T, typename F>
inline T lexical_cast(const F &v, const Fmt &f = Fmt())
{
template<typename T, typename F>
inline T lexical_cast(const F &v, const Fmt &f = Fmt())
{