forked from boostorg/conversion
Support for string with non-default char_traits and allocator.
[SVN r41387]
This commit is contained in:
@@ -86,6 +86,14 @@ namespace boost
|
|||||||
typedef char type;
|
typedef char type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
template<class CharT, class Traits, class Alloc>
|
||||||
|
struct stream_char< std::basic_string<CharT,Traits,Alloc> >
|
||||||
|
{
|
||||||
|
typedef CharT type;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||||
template<>
|
template<>
|
||||||
@@ -107,11 +115,13 @@ namespace boost
|
|||||||
typedef wchar_t type;
|
typedef wchar_t type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
template<>
|
template<>
|
||||||
struct stream_char<std::wstring>
|
struct stream_char<std::wstring>
|
||||||
{
|
{
|
||||||
typedef wchar_t type;
|
typedef wchar_t type;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename TargetChar, typename SourceChar>
|
template<typename TargetChar, typename SourceChar>
|
||||||
@@ -127,6 +137,44 @@ namespace boost
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace detail // deduce_char_traits template
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
template<class CharT, class Target, class Source>
|
||||||
|
struct deduce_char_traits
|
||||||
|
{
|
||||||
|
typedef std::char_traits<CharT> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class CharT, class Traits, class Alloc, class Source>
|
||||||
|
struct deduce_char_traits< CharT
|
||||||
|
, std::basic_string<CharT,Traits,Alloc>
|
||||||
|
, Source
|
||||||
|
>
|
||||||
|
{
|
||||||
|
typedef Traits type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class CharT, class Target, class Traits, class Alloc>
|
||||||
|
struct deduce_char_traits< CharT
|
||||||
|
, Target
|
||||||
|
, std::basic_string<CharT,Traits,Alloc>
|
||||||
|
>
|
||||||
|
{
|
||||||
|
typedef Traits type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class CharT, class Traits, class Alloc1, class Alloc2>
|
||||||
|
struct deduce_char_traits< CharT
|
||||||
|
, std::basic_string<CharT,Traits,Alloc1>
|
||||||
|
, std::basic_string<CharT,Traits,Alloc2>
|
||||||
|
>
|
||||||
|
{
|
||||||
|
typedef Traits type;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
namespace detail // lcast_src_length
|
namespace detail // lcast_src_length
|
||||||
{
|
{
|
||||||
// Return max. length of string representation of Source;
|
// Return max. length of string representation of Source;
|
||||||
@@ -309,8 +357,6 @@ namespace boost
|
|||||||
#undef BOOST_AUX_LEXICAL_CAST_DEF1
|
#undef BOOST_AUX_LEXICAL_CAST_DEF1
|
||||||
|
|
||||||
#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
|
#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
|
||||||
// This #if is in sync with lcast_precision
|
|
||||||
|
|
||||||
// Helper for floating point types.
|
// Helper for floating point types.
|
||||||
// -1.23456789e-123456
|
// -1.23456789e-123456
|
||||||
// ^ sign
|
// ^ sign
|
||||||
@@ -450,9 +496,7 @@ namespace boost
|
|||||||
|
|
||||||
namespace detail // lcast_put_unsigned
|
namespace detail // lcast_put_unsigned
|
||||||
{
|
{
|
||||||
// I'd personally put lcast_put_unsigned in .cpp file if not
|
template<class Traits, class T, class CharT>
|
||||||
// boost practice for header-only libraries (Alexander Nasonov).
|
|
||||||
template<typename T, typename CharT>
|
|
||||||
CharT* lcast_put_unsigned(T n, CharT* finish)
|
CharT* lcast_put_unsigned(T n, CharT* finish)
|
||||||
{
|
{
|
||||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
@@ -482,6 +526,9 @@ namespace boost
|
|||||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
BOOST_STATIC_ASSERT(std::numeric_limits<T>::digits10 < CHAR_MAX);
|
BOOST_STATIC_ASSERT(std::numeric_limits<T>::digits10 < CHAR_MAX);
|
||||||
#endif
|
#endif
|
||||||
|
typedef typename Traits::int_type int_type;
|
||||||
|
CharT const czero = lcast_char_constants<CharT>::zero;
|
||||||
|
int_type const zero = Traits::to_int_type(czero);
|
||||||
|
|
||||||
char left = last_grp_size;
|
char left = last_grp_size;
|
||||||
|
|
||||||
@@ -498,14 +545,13 @@ namespace boost
|
|||||||
|
|
||||||
left = last_grp_size;
|
left = last_grp_size;
|
||||||
--finish;
|
--finish;
|
||||||
*finish = thousands_sep;
|
Traits::assign(*finish, thousands_sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
--left;
|
--left;
|
||||||
--finish;
|
--finish;
|
||||||
int const digit = static_cast<int>(n % 10);
|
int_type const digit = static_cast<int_type>(n % 10U);
|
||||||
int const cdigit = digit + lcast_char_constants<CharT>::zero;
|
Traits::assign(*finish, Traits::to_char_type(zero + digit));
|
||||||
*finish = static_cast<char>(cdigit);
|
|
||||||
n /= 10;
|
n /= 10;
|
||||||
} while(n);
|
} while(n);
|
||||||
|
|
||||||
@@ -515,7 +561,7 @@ namespace boost
|
|||||||
|
|
||||||
namespace detail // stream wrapper for handling lexical conversions
|
namespace detail // stream wrapper for handling lexical conversions
|
||||||
{
|
{
|
||||||
template<typename Target, typename Source>
|
template<typename Target, typename Source, typename Traits>
|
||||||
class lexical_stream
|
class lexical_stream
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -523,6 +569,8 @@ namespace boost
|
|||||||
typename stream_char<Target>::type,
|
typename stream_char<Target>::type,
|
||||||
typename stream_char<Source>::type>::type char_type;
|
typename stream_char<Source>::type>::type char_type;
|
||||||
|
|
||||||
|
typedef Traits traits_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lexical_stream(char_type* = 0, char_type* = 0)
|
lexical_stream(char_type* = 0, char_type* = 0)
|
||||||
{
|
{
|
||||||
@@ -552,9 +600,12 @@ namespace boost
|
|||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
#else
|
#else
|
||||||
std::char_traits<char_type>::eof();
|
traits_type::eof();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
|
||||||
bool operator>>(std::string &output)
|
bool operator>>(std::string &output)
|
||||||
{
|
{
|
||||||
#if defined(BOOST_NO_STRINGSTREAM)
|
#if defined(BOOST_NO_STRINGSTREAM)
|
||||||
@@ -570,13 +621,29 @@ namespace boost
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
bool operator>>(std::basic_string<char_type,traits_type>& output)
|
||||||
|
{
|
||||||
|
stream.str().swap(output);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Alloc>
|
||||||
|
bool operator>>(std::basic_string<char_type,traits_type,Alloc>& out)
|
||||||
|
{
|
||||||
|
std::basic_string<char_type,traits_type> str(stream.str());
|
||||||
|
out.assign(str.begin(), str.end());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
#if defined(BOOST_NO_STRINGSTREAM)
|
#if defined(BOOST_NO_STRINGSTREAM)
|
||||||
std::strstream stream;
|
std::strstream stream;
|
||||||
#elif defined(BOOST_NO_STD_LOCALE)
|
#elif defined(BOOST_NO_STD_LOCALE)
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
#else
|
#else
|
||||||
std::basic_stringstream<char_type> stream;
|
std::basic_stringstream<char_type,traits_type> stream;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -586,6 +653,7 @@ namespace boost
|
|||||||
// String representation of Source has an upper limit.
|
// String representation of Source has an upper limit.
|
||||||
template< class CharT // a result of widest_char transformation
|
template< class CharT // a result of widest_char transformation
|
||||||
, class Base // lexical_streambuf_fake or basic_streambuf<CharT>
|
, class Base // lexical_streambuf_fake or basic_streambuf<CharT>
|
||||||
|
, class Traits // usually char_traits<CharT>
|
||||||
>
|
>
|
||||||
class lexical_stream_limited_src : public Base
|
class lexical_stream_limited_src : public Base
|
||||||
{
|
{
|
||||||
@@ -599,19 +667,20 @@ namespace boost
|
|||||||
|
|
||||||
static void widen_and_assign(char*p, char ch)
|
static void widen_and_assign(char*p, char ch)
|
||||||
{
|
{
|
||||||
*p = ch;
|
Traits::assign(*p, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||||
static void widen_and_assign(wchar_t* p, char ch)
|
static void widen_and_assign(wchar_t* p, char ch)
|
||||||
{
|
{
|
||||||
std::locale loc;
|
std::locale loc;
|
||||||
*p = BOOST_USE_FACET(std::ctype<wchar_t>, loc).widen(ch);
|
wchar_t w = BOOST_USE_FACET(std::ctype<wchar_t>, loc).widen(ch);
|
||||||
|
Traits::assign(*p, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void widen_and_assign(wchar_t* p, wchar_t ch)
|
static void widen_and_assign(wchar_t* p, wchar_t ch)
|
||||||
{
|
{
|
||||||
*p = ch;
|
Traits::assign(*p, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void widen_and_assign(char*, wchar_t ch); // undefined
|
static void widen_and_assign(char*, wchar_t ch); // undefined
|
||||||
@@ -641,7 +710,7 @@ namespace boost
|
|||||||
|
|
||||||
public: // output
|
public: // output
|
||||||
|
|
||||||
template<class Traits, class Alloc>
|
template<class Alloc>
|
||||||
bool operator<<(std::basic_string<CharT,Traits,Alloc> const& str)
|
bool operator<<(std::basic_string<CharT,Traits,Alloc> const& str)
|
||||||
{
|
{
|
||||||
start = const_cast<CharT*>(str.data());
|
start = const_cast<CharT*>(str.data());
|
||||||
@@ -705,7 +774,7 @@ namespace boost
|
|||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
#else
|
#else
|
||||||
std::char_traits<CharT>::eof();
|
Traits::eof();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,7 +790,7 @@ namespace boost
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
template<class Traits, class Alloc>
|
template<class Alloc>
|
||||||
bool operator>>(std::basic_string<CharT,Traits,Alloc>& str)
|
bool operator>>(std::basic_string<CharT,Traits,Alloc>& str)
|
||||||
{
|
{
|
||||||
str.assign(start, finish);
|
str.assign(start, finish);
|
||||||
@@ -730,17 +799,21 @@ namespace boost
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
bool value)
|
bool value)
|
||||||
{
|
{
|
||||||
*start = value + lcast_char_constants<CharT>::zero;
|
typedef typename Traits::int_type int_type;
|
||||||
|
CharT const czero = lcast_char_constants<CharT>::zero;
|
||||||
|
int_type const zero = Traits::to_int_type(czero);
|
||||||
|
Traits::assign(*start, Traits::to_char_type(zero + value));
|
||||||
finish = start + 1;
|
finish = start + 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(char ch)
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
|
char ch)
|
||||||
{
|
{
|
||||||
widen_and_assign(start, ch);
|
widen_and_assign(start, ch);
|
||||||
finish = start + 1;
|
finish = start + 1;
|
||||||
@@ -748,8 +821,8 @@ namespace boost
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(DISABLE_WIDE_CHAR_SUPPORT) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
#if !defined(DISABLE_WIDE_CHAR_SUPPORT) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
wchar_t ch)
|
wchar_t ch)
|
||||||
{
|
{
|
||||||
widen_and_assign(start, ch);
|
widen_and_assign(start, ch);
|
||||||
@@ -758,140 +831,163 @@ namespace boost
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(short n)
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
|
short n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(lcast_to_unsigned(n), finish);
|
start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
*--start = lcast_char_constants<CharT>::minus;
|
{
|
||||||
|
--start;
|
||||||
|
CharT const minus = lcast_char_constants<CharT>::minus;
|
||||||
|
Traits::assign(*start, minus);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(int n)
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
|
int n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(lcast_to_unsigned(n), finish);
|
start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
*--start = lcast_char_constants<CharT>::minus;
|
{
|
||||||
|
--start;
|
||||||
|
CharT const minus = lcast_char_constants<CharT>::minus;
|
||||||
|
Traits::assign(*start, minus);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(long n)
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
|
long n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(lcast_to_unsigned(n), finish);
|
start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
*--start = lcast_char_constants<CharT>::minus;
|
{
|
||||||
|
--start;
|
||||||
|
CharT const minus = lcast_char_constants<CharT>::minus;
|
||||||
|
Traits::assign(*start, minus);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BOOST_HAS_LONG_LONG)
|
#if defined(BOOST_HAS_LONG_LONG)
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
boost::long_long_type n)
|
boost::long_long_type n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(lcast_to_unsigned(n), finish);
|
start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
*--start = lcast_char_constants<CharT>::minus;
|
{
|
||||||
|
--start;
|
||||||
|
CharT const minus = lcast_char_constants<CharT>::minus;
|
||||||
|
Traits::assign(*start, minus);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#elif defined(BOOST_HAS_MS_INT64)
|
#elif defined(BOOST_HAS_MS_INT64)
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
__int64 n)
|
__int64 n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(lcast_to_unsigned(n), finish);
|
start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
*--start = lcast_char_constants<CharT>::minus;
|
{
|
||||||
|
--start;
|
||||||
|
CharT const minus = lcast_char_constants<CharT>::minus;
|
||||||
|
Traits::assign(*start, minus);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
unsigned short n)
|
unsigned short n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(lcast_to_unsigned(n), finish);
|
start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
unsigned int n)
|
unsigned int n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(n, finish);
|
start = lcast_put_unsigned<Traits>(n, finish);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
unsigned long n)
|
unsigned long n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(n, finish);
|
start = lcast_put_unsigned<Traits>(n, finish);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BOOST_HAS_LONG_LONG)
|
#if defined(BOOST_HAS_LONG_LONG)
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
boost::ulong_long_type n)
|
boost::ulong_long_type n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(n, finish);
|
start = lcast_put_unsigned<Traits>(n, finish);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#elif defined(BOOST_HAS_MS_INT64)
|
#elif defined(BOOST_HAS_MS_INT64)
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
unsigned __int64 n)
|
unsigned __int64 n)
|
||||||
{
|
{
|
||||||
start = lcast_put_unsigned(n, finish);
|
start = lcast_put_unsigned<Traits>(n, finish);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
float val)
|
float val)
|
||||||
{
|
{
|
||||||
return this->lcast_put(val);
|
return this->lcast_put(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
double val)
|
double val)
|
||||||
{
|
{
|
||||||
return this->lcast_put(val);
|
return this->lcast_put(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
long double val)
|
long double val)
|
||||||
{
|
{
|
||||||
return this->lcast_put(val);
|
return this->lcast_put(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator<<(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator<<(
|
||||||
CharT const* str)
|
CharT const* str)
|
||||||
{
|
{
|
||||||
start = const_cast<CharT*>(str);
|
start = const_cast<CharT*>(str);
|
||||||
finish = start + std::char_traits<CharT>::length(str);
|
finish = start + Traits::length(str);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator>>(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator>>(
|
||||||
CharT& output)
|
CharT& output)
|
||||||
{
|
{
|
||||||
bool const ok = (finish - start == 1);
|
bool const ok = (finish - start == 1);
|
||||||
if(ok)
|
if(ok)
|
||||||
output = *start;
|
Traits::assign(output, *start);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator>>(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator>>(
|
||||||
std::string& str)
|
std::string& str)
|
||||||
{
|
{
|
||||||
str.assign(start, finish);
|
str.assign(start, finish);
|
||||||
@@ -899,8 +995,8 @@ namespace boost
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||||
template<typename CharT, class Base>
|
template<typename CharT, class Base, class Traits>
|
||||||
inline bool lexical_stream_limited_src<CharT,Base>::operator>>(
|
inline bool lexical_stream_limited_src<CharT,Base,Traits>::operator>>(
|
||||||
std::wstring& str)
|
std::wstring& str)
|
||||||
{
|
{
|
||||||
str.assign(start, finish);
|
str.assign(start, finish);
|
||||||
@@ -1021,6 +1117,12 @@ namespace boost
|
|||||||
BOOST_DEDUCED_TYPENAME boost::call_traits<Source>::param_type arg,
|
BOOST_DEDUCED_TYPENAME boost::call_traits<Source>::param_type arg,
|
||||||
CharT* buf, std::size_t src_len)
|
CharT* buf, std::size_t src_len)
|
||||||
{
|
{
|
||||||
|
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
typedef BOOST_DEDUCED_TYPENAME
|
||||||
|
deduce_char_traits<CharT,Target,Source>::type traits;
|
||||||
|
#else
|
||||||
|
typedef std::char_traits<CharT> traits;
|
||||||
|
#endif
|
||||||
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
|
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
|
||||||
lcast_streambuf_for_target<Target>::value ||
|
lcast_streambuf_for_target<Target>::value ||
|
||||||
lcast_streambuf_for_source<Source>::value
|
lcast_streambuf_for_source<Source>::value
|
||||||
@@ -1030,8 +1132,8 @@ namespace boost
|
|||||||
|
|
||||||
BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
|
BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
|
||||||
Unlimited
|
Unlimited
|
||||||
, detail::lexical_stream<Target, Source>
|
, detail::lexical_stream<Target,Source,traits>
|
||||||
, detail::lexical_stream_limited_src<CharT,base>
|
, detail::lexical_stream_limited_src<CharT,base,traits>
|
||||||
>::type interpreter(buf, buf + src_len);
|
>::type interpreter(buf, buf + src_len);
|
||||||
|
|
||||||
// The original form, reproduced below, is more elegant
|
// The original form, reproduced below, is more elegant
|
||||||
|
@@ -24,6 +24,9 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <boost/test/floating_point_comparison.hpp>
|
#include <boost/test/floating_point_comparison.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#if defined(BOOST_NO_STRINGSTREAM) || \
|
#if defined(BOOST_NO_STRINGSTREAM) || \
|
||||||
defined(BOOST_NO_STD_WSTRING) || \
|
defined(BOOST_NO_STD_WSTRING) || \
|
||||||
defined(BOOST_NO_STD_LOCALE)
|
defined(BOOST_NO_STD_LOCALE)
|
||||||
@@ -35,6 +38,16 @@
|
|||||||
#define LCAST_TEST_LONGLONG
|
#define LCAST_TEST_LONGLONG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<class CharT>
|
||||||
|
struct my_traits : std::char_traits<CharT>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class CharT>
|
||||||
|
struct my_allocator : std::allocator<CharT>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
// Test all 65536 values if true:
|
// Test all 65536 values if true:
|
||||||
bool const lcast_test_small_integral_types_completely = false;
|
bool const lcast_test_small_integral_types_completely = false;
|
||||||
|
|
||||||
@@ -57,15 +70,21 @@ void test_conversion_from_wstring();
|
|||||||
void test_conversion_to_wstring();
|
void test_conversion_to_wstring();
|
||||||
void test_bad_lexical_cast();
|
void test_bad_lexical_cast();
|
||||||
void test_no_whitespace_stripping();
|
void test_no_whitespace_stripping();
|
||||||
void test_conversion_from_short();
|
void test_conversion_from_to_short();
|
||||||
void test_conversion_from_ushort();
|
void test_conversion_from_to_ushort();
|
||||||
void test_conversion_from_int();
|
void test_conversion_from_to_int();
|
||||||
void test_conversion_from_uint();
|
void test_conversion_from_to_uint();
|
||||||
void test_conversion_from_long();
|
void test_conversion_from_to_long();
|
||||||
void test_conversion_from_ulong();
|
void test_conversion_from_to_ulong();
|
||||||
#ifdef LCAST_TEST_LONGLONG
|
#ifdef LCAST_TEST_LONGLONG
|
||||||
void test_conversion_from_longlong();
|
void test_conversion_from_to_longlong();
|
||||||
void test_conversion_from_ulonglong();
|
void test_conversion_from_to_ulonglong();
|
||||||
|
#endif
|
||||||
|
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
void test_traits();
|
||||||
|
void test_wtraits();
|
||||||
|
void test_allocator();
|
||||||
|
void test_wallocator();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||||
@@ -87,15 +106,21 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
|
|||||||
#endif
|
#endif
|
||||||
suite->add(BOOST_TEST_CASE(test_bad_lexical_cast));
|
suite->add(BOOST_TEST_CASE(test_bad_lexical_cast));
|
||||||
suite->add(BOOST_TEST_CASE(test_no_whitespace_stripping));
|
suite->add(BOOST_TEST_CASE(test_no_whitespace_stripping));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_short));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_short));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_ushort));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ushort));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_int));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_int));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_uint));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_uint));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_ulong));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ulong));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_long));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_long));
|
||||||
#ifdef LCAST_TEST_LONGLONG
|
#ifdef LCAST_TEST_LONGLONG
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_longlong));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_longlong));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_ulonglong));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ulonglong));
|
||||||
|
#endif
|
||||||
|
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
suite->add(BOOST_TEST_CASE(&test_traits));
|
||||||
|
suite->add(BOOST_TEST_CASE(&test_wtraits));
|
||||||
|
suite->add(BOOST_TEST_CASE(&test_allocator));
|
||||||
|
suite->add(BOOST_TEST_CASE(&test_wallocator));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
@@ -129,10 +154,15 @@ void test_conversion_to_int()
|
|||||||
BOOST_CHECK_EQUAL(0, lexical_cast<int>('0'));
|
BOOST_CHECK_EQUAL(0, lexical_cast<int>('0'));
|
||||||
BOOST_CHECK_THROW(lexical_cast<int>('A'), bad_lexical_cast);
|
BOOST_CHECK_THROW(lexical_cast<int>('A'), bad_lexical_cast);
|
||||||
BOOST_CHECK_EQUAL(1, lexical_cast<int>(1));
|
BOOST_CHECK_EQUAL(1, lexical_cast<int>(1));
|
||||||
|
BOOST_CHECK_EQUAL(1, lexical_cast<int>(1.0));
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(
|
BOOST_CHECK_EQUAL(
|
||||||
(std::numeric_limits<int>::max)(),
|
(std::numeric_limits<int>::max)(),
|
||||||
lexical_cast<int>((std::numeric_limits<int>::max)()));
|
lexical_cast<int>((std::numeric_limits<int>::max)()));
|
||||||
BOOST_CHECK_EQUAL(1, lexical_cast<int>(1.0));
|
|
||||||
|
BOOST_CHECK_EQUAL(
|
||||||
|
(std::numeric_limits<int>::min)(),
|
||||||
|
lexical_cast<int>((std::numeric_limits<int>::min)()));
|
||||||
|
|
||||||
BOOST_CHECK_THROW(lexical_cast<int>(1.23), bad_lexical_cast);
|
BOOST_CHECK_THROW(lexical_cast<int>(1.23), bad_lexical_cast);
|
||||||
|
|
||||||
@@ -407,7 +437,7 @@ void test_conversion_from_integral_to_char(CharT zero)
|
|||||||
|
|
||||||
BOOST_CHECK_THROW(lexical_cast<CharT>(static_cast<T>(10)), bad_lexical_cast);
|
BOOST_CHECK_THROW(lexical_cast<CharT>(static_cast<T>(10)), bad_lexical_cast);
|
||||||
|
|
||||||
T t = std::numeric_limits<T>::max();
|
T t = (std::numeric_limits<T>::max)();
|
||||||
BOOST_CHECK_THROW(lexical_cast<CharT>(t), bad_lexical_cast);
|
BOOST_CHECK_THROW(lexical_cast<CharT>(t), bad_lexical_cast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,10 +457,10 @@ void test_conversion_from_integral_to_integral()
|
|||||||
BOOST_CHECK(lexical_cast<long>(t) == st);
|
BOOST_CHECK(lexical_cast<long>(t) == st);
|
||||||
BOOST_CHECK(lexical_cast<unsigned long>(t) == ut);
|
BOOST_CHECK(lexical_cast<unsigned long>(t) == ut);
|
||||||
|
|
||||||
t = std::numeric_limits<T>::max();
|
t = (std::numeric_limits<T>::max)();
|
||||||
BOOST_CHECK(lexical_cast<T>(t) == t);
|
BOOST_CHECK(lexical_cast<T>(t) == t);
|
||||||
|
|
||||||
t = std::numeric_limits<T>::min();
|
t = (std::numeric_limits<T>::min)();
|
||||||
BOOST_CHECK(lexical_cast<T>(t) == t);
|
BOOST_CHECK(lexical_cast<T>(t) == t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,19 +472,20 @@ void test_conversion_from_integral_to_string(CharT)
|
|||||||
|
|
||||||
T t;
|
T t;
|
||||||
|
|
||||||
t = limits::min();
|
t = (limits::min)();
|
||||||
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
||||||
|
|
||||||
t = limits::max();
|
t = (limits::max)();
|
||||||
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
||||||
|
|
||||||
if(limits::digits <= 16 && lcast_test_small_integral_types_completely)
|
if(limits::digits <= 16 && lcast_test_small_integral_types_completely)
|
||||||
for(t = 1 + limits::min(); t != limits::max(); ++t)
|
// min and max have already been tested.
|
||||||
|
for(t = 1 + (limits::min)(); t != (limits::max)(); ++t)
|
||||||
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
T const min_val = limits::min();
|
T const min_val = (limits::min)();
|
||||||
T const max_val = limits::max();
|
T const max_val = (limits::max)();
|
||||||
T const half_max_val = max_val / 2;
|
T const half_max_val = max_val / 2;
|
||||||
T const cnt = lcast_integral_test_counter; // to supress warnings
|
T const cnt = lcast_integral_test_counter; // to supress warnings
|
||||||
unsigned int const counter = cnt < half_max_val ? cnt : half_max_val;
|
unsigned int const counter = cnt < half_max_val ? cnt : half_max_val;
|
||||||
@@ -480,20 +511,75 @@ void test_conversion_from_integral_to_string(CharT)
|
|||||||
T ten_power = 100;
|
T ten_power = 100;
|
||||||
for(int e = 2; e <= limits::digits10; ++e, ten_power *= 10)
|
for(int e = 2; e <= limits::digits10; ++e, ten_power *= 10)
|
||||||
{
|
{
|
||||||
// I believe that (ten_power + 100) never overflows
|
// ten_power + 100 probably never overflows
|
||||||
for(t = ten_power - 100; t != ten_power + 100; ++t)
|
for(t = ten_power - 100; t != ten_power + 100; ++t)
|
||||||
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T, class CharT>
|
||||||
|
void test_conversion_from_string_to_integral(CharT)
|
||||||
|
{
|
||||||
|
typedef std::numeric_limits<T> limits;
|
||||||
|
|
||||||
|
T t;
|
||||||
|
|
||||||
|
t = (limits::min)();
|
||||||
|
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
|
||||||
|
|
||||||
|
t = (limits::max)();
|
||||||
|
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
|
||||||
|
|
||||||
|
if(limits::digits <= 16 && lcast_test_small_integral_types_completely)
|
||||||
|
// min and max have already been tested.
|
||||||
|
for(t = 1 + (limits::min)(); t != (limits::max)(); ++t)
|
||||||
|
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
T const min_val = (limits::min)();
|
||||||
|
T const max_val = (limits::max)();
|
||||||
|
T const half_max_val = max_val / 2;
|
||||||
|
T const cnt = lcast_integral_test_counter; // to supress warnings
|
||||||
|
unsigned int const counter = cnt < half_max_val ? cnt : half_max_val;
|
||||||
|
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
// Test values around min:
|
||||||
|
t = min_val;
|
||||||
|
for(i = 0; i < counter; ++i, ++t)
|
||||||
|
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
|
||||||
|
|
||||||
|
// Test values around max:
|
||||||
|
t = max_val;
|
||||||
|
for(i = 0; i < counter; ++i, --t)
|
||||||
|
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
|
||||||
|
|
||||||
|
// Test values around zero:
|
||||||
|
if(limits::is_signed)
|
||||||
|
for(t = -counter; t < static_cast<T>(counter); ++t)
|
||||||
|
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
|
||||||
|
|
||||||
|
// Test values around 100, 1000, 10000, ...
|
||||||
|
T ten_power = 100;
|
||||||
|
for(int e = 2; e <= limits::digits10; ++e, ten_power *= 10)
|
||||||
|
{
|
||||||
|
// ten_power + 100 probably never overflows
|
||||||
|
for(t = ten_power - 100; t != ten_power + 100; ++t)
|
||||||
|
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void test_conversion_from_integral_for_locale()
|
void test_conversion_from_to_integral_for_locale()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral_to_integral<T>();
|
test_conversion_from_integral_to_integral<T>();
|
||||||
test_conversion_from_integral_to_string<T>('0');
|
test_conversion_from_integral_to_string<T>('0');
|
||||||
|
test_conversion_from_string_to_integral<T>('0');
|
||||||
#if !defined(DISABLE_WIDE_CHAR_SUPPORT) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
#if !defined(DISABLE_WIDE_CHAR_SUPPORT) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||||
test_conversion_from_integral_to_string<T>(L'0');
|
test_conversion_from_integral_to_string<T>(L'0');
|
||||||
|
test_conversion_from_string_to_integral<T>(L'0');
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,7 +590,7 @@ struct restore_oldloc
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void test_conversion_from_integral()
|
void test_conversion_from_to_integral()
|
||||||
{
|
{
|
||||||
char const zero = '0';
|
char const zero = '0';
|
||||||
signed char const szero = '0';
|
signed char const szero = '0';
|
||||||
@@ -517,7 +603,7 @@ void test_conversion_from_integral()
|
|||||||
test_conversion_from_integral_to_char<T>(wzero);
|
test_conversion_from_integral_to_char<T>(wzero);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// test_conversion_from_integral_for_locale
|
// test_conversion_from_to_integral_for_locale
|
||||||
|
|
||||||
typedef std::numpunct<char> numpunct;
|
typedef std::numpunct<char> numpunct;
|
||||||
|
|
||||||
@@ -527,7 +613,7 @@ void test_conversion_from_integral()
|
|||||||
std::string grouping1 = BOOST_USE_FACET(numpunct, oldloc).grouping();
|
std::string grouping1 = BOOST_USE_FACET(numpunct, oldloc).grouping();
|
||||||
std::string grouping2(grouping1);
|
std::string grouping2(grouping1);
|
||||||
|
|
||||||
test_conversion_from_integral_for_locale<T>();
|
test_conversion_from_to_integral_for_locale<T>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -544,64 +630,121 @@ void test_conversion_from_integral()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(grouping1 != grouping2)
|
if(grouping1 != grouping2)
|
||||||
test_conversion_from_integral_for_locale<T>();
|
test_conversion_from_to_integral_for_locale<T>();
|
||||||
|
|
||||||
if(grouping1.empty() && grouping2.empty())
|
if(grouping1.empty() && grouping2.empty())
|
||||||
BOOST_TEST_MESSAGE("Formatting with thousands_sep has not been tested");
|
BOOST_TEST_MESSAGE("Formatting with thousands_sep has not been tested");
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_short()
|
void test_conversion_from_to_short()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<short>();
|
test_conversion_from_to_integral<short>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_ushort()
|
void test_conversion_from_to_ushort()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<unsigned short>();
|
test_conversion_from_to_integral<unsigned short>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_int()
|
void test_conversion_from_to_int()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<int>();
|
test_conversion_from_to_integral<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_uint()
|
void test_conversion_from_to_uint()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<unsigned int>();
|
test_conversion_from_to_integral<unsigned int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_ulong()
|
void test_conversion_from_to_ulong()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<unsigned long>();
|
test_conversion_from_to_integral<unsigned long>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_long()
|
void test_conversion_from_to_long()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<long>();
|
test_conversion_from_to_integral<long>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BOOST_HAS_LONG_LONG)
|
#if defined(BOOST_HAS_LONG_LONG)
|
||||||
|
|
||||||
void test_conversion_from_longlong()
|
void test_conversion_from_to_longlong()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<boost::long_long_type>();
|
test_conversion_from_to_integral<boost::long_long_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_ulonglong()
|
void test_conversion_from_to_ulonglong()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<boost::ulong_long_type>();
|
test_conversion_from_to_integral<boost::ulong_long_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(LCAST_TEST_LONGLONG)
|
#elif defined(LCAST_TEST_LONGLONG)
|
||||||
|
|
||||||
void test_conversion_from_longlong()
|
void test_conversion_from_to_longlong()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<__int64>();
|
test_conversion_from_to_integral<__int64>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion_from_ulonglong()
|
void test_conversion_from_to_ulonglong()
|
||||||
{
|
{
|
||||||
test_conversion_from_integral<unsigned __int64>();
|
test_conversion_from_to_integral<unsigned __int64>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
void test_traits()
|
||||||
|
{
|
||||||
|
typedef std::basic_string<char, my_traits<char> > my_string;
|
||||||
|
|
||||||
|
my_string const s("s");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<char>(s) == s[0]);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(-1) == "-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_wtraits()
|
||||||
|
{
|
||||||
|
typedef std::basic_string<wchar_t, my_traits<wchar_t> > my_string;
|
||||||
|
|
||||||
|
my_string const s(L"s");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<wchar_t>(s) == s[0]);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
|
||||||
|
//BOOST_CHECK(boost::lexical_cast<my_string>(-1) == L"-1");
|
||||||
|
// Commented out because gcc 3.3 doesn't support this:
|
||||||
|
// basic_ostream<wchar_t, my_traits<wchar_t> > o; o << -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_allocator()
|
||||||
|
{
|
||||||
|
typedef std::basic_string< char
|
||||||
|
, std::char_traits<char>
|
||||||
|
, my_allocator<char>
|
||||||
|
> my_string;
|
||||||
|
|
||||||
|
my_string s("s");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<char>(s) == s[0]);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<std::string>(s) == "s");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(1) == "1");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>("s") == s);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(std::string("s")) == s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_wallocator()
|
||||||
|
{
|
||||||
|
typedef std::basic_string< wchar_t
|
||||||
|
, std::char_traits<wchar_t>
|
||||||
|
, my_allocator<wchar_t>
|
||||||
|
> my_string;
|
||||||
|
|
||||||
|
my_string s(L"s");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<wchar_t>(s) == s[0]);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<std::wstring>(s) == L"s");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(1) == L"1");
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(L"s") == s);
|
||||||
|
BOOST_CHECK(boost::lexical_cast<my_string>(std::wstring(L"s")) == s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user