#pragma once #include namespace fc { namespace detail { template struct lexical_cast { }; double to_double( const fc::string& s ); inline double to_double( double d ) { return d; } int64_t to_int64( const fc::string& s ); inline int64_t to_int64( double d ) { return static_cast(d); } inline int64_t to_int64( int64_t d ) { return d; } uint64_t to_uint64( const fc::string& s ); inline uint64_t to_uint64( double d ) { return static_cast(d); } inline uint64_t to_uint64( uint64_t d ) { return d; } fc::string to_string( double d ); fc::string to_string( size_t d ); fc::string to_string( uint64_t d ); fc::string to_string( uint32_t d ); fc::string to_string( uint16_t d ); fc::string to_string( uint8_t d ); fc::string to_string( int64_t d ); fc::string to_string( int32_t d ); fc::string to_string( int16_t d ); fc::string to_string( int8_t d ); fc::string to_string( char d ); inline fc::string to_string( const char* d ) { return d; } inline fc::string to_string( fc::string s ) { return s; } template struct lexical_cast { static double cast( const R& v ) { return to_double( v ); } }; template struct lexical_cast { static fc::string cast( const R& v ) { return to_string( v ); } }; template struct lexical_cast { static std::string cast( const R& v ) { return to_string( v ); } }; template struct lexical_cast { static uint64_t cast( const R& v ) { return to_uint64( v ); } }; template struct lexical_cast { static int64_t cast( const R& v ) { return static_cast(to_int64( v )); } }; template struct lexical_cast { static int32_t cast( const R& v ) { return static_cast(to_int64( v )); } }; template struct lexical_cast { static int16_t cast( const R& v ) { return static_cast(to_int64( v )); } }; template struct lexical_cast { static int8_t cast( const R& v ) { return static_cast(to_int64( v )); } }; template struct lexical_cast { static uint32_t cast( const R& v ) { return static_cast(to_uint64( v )); } }; template struct lexical_cast { static uint16_t cast( const R& v ) { return static_cast(to_uint64( v )); } }; template struct lexical_cast { static uint8_t cast( const R& v ) { return static_cast(to_uint64( v )); } }; template struct lexical_cast { static bool cast( const R& v ) { return v != 0; } }; template<> struct lexical_cast { static char cast( const fc::string& v ) { return v[0]; } };// TODO: check string len template<> struct lexical_cast { static bool cast( const fc::string& v ) { return v == "true"; } }; template<> struct lexical_cast { static fc::string cast( const bool& v ) { return v ? "true" : "false";} }; template struct lexical_cast { static float cast( const R& v ) { return static_cast(to_double( v )); } }; } template T lexical_cast( const R& v ) { return detail::lexical_cast::cast(v); } }