forked from boostorg/conversion
Fixes #6717 (now lexical_cast won`t try to support non confirming swprintf)
[SVN r77639]
This commit is contained in:
@@ -26,27 +26,6 @@
|
|||||||
#define BOOST_LCAST_NO_WCHAR_T
|
#define BOOST_LCAST_NO_WCHAR_T
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(__MINGW32__) || defined(__MINGW64__)) && (__GNUC__ == 4) \
|
|
||||||
&& ((__GNUC_MINOR__ == 4) || (__GNUC_MINOR__ == 5)) && defined(__STRICT_ANSI__) \
|
|
||||||
&& !defined(BOOST_LCAST_NO_WCHAR_T)
|
|
||||||
|
|
||||||
// workaround for a mingw bug
|
|
||||||
// http://sourceforge.net/tracker/index.php?func=detail&aid=2373234&group_id=2435&atid=102435
|
|
||||||
#include <_mingw.h>
|
|
||||||
#if (__GNUC_MINOR__ == 4)
|
|
||||||
extern "C" {
|
|
||||||
_CRTIMP int __cdecl swprintf(wchar_t * __restrict__ , const wchar_t * __restrict__ , ...);
|
|
||||||
_CRTIMP int __cdecl vswprintf(wchar_t * __restrict__ , const wchar_t * __restrict__ , ...);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if (__GNUC_MINOR__ == 5)
|
|
||||||
extern "C" {
|
|
||||||
_CRTIMP int __cdecl swprintf(wchar_t * __restrict__ , const wchar_t * __restrict__ , ...);
|
|
||||||
_CRTIMP int __cdecl vswprintf(wchar_t * __restrict__ , const wchar_t * __restrict__ , va_list);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
@@ -1299,34 +1278,40 @@ namespace boost
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class SomeCharT>
|
||||||
|
bool shl_real_type(const T& val, SomeCharT*, SomeCharT*)
|
||||||
|
{
|
||||||
|
return shl_input_streamable(val);
|
||||||
|
}
|
||||||
|
|
||||||
#if (defined _MSC_VER)
|
#if (defined _MSC_VER)
|
||||||
# pragma warning( push )
|
# pragma warning( push )
|
||||||
// C4996: This function or variable may be unsafe. Consider using sprintf_s instead
|
// C4996: This function or variable may be unsafe. Consider using sprintf_s instead
|
||||||
# pragma warning( disable : 4996 )
|
# pragma warning( disable : 4996 )
|
||||||
#endif
|
#endif
|
||||||
|
static bool shl_real_type(float val, char* begin, char*& end)
|
||||||
template <class T>
|
|
||||||
bool shl_float(float val,T* out)
|
|
||||||
{ using namespace std;
|
{ using namespace std;
|
||||||
if (put_inf_nan(start,finish,val)) return true;
|
if (put_inf_nan(begin, end, val)) return true;
|
||||||
finish = start + sprintf(out,"%.*g", static_cast<int>(boost::detail::lcast_get_precision<float >()), val );
|
end = begin;
|
||||||
return finish > start;
|
end += sprintf(begin,"%.*g", static_cast<int>(boost::detail::lcast_get_precision<float>()), val);
|
||||||
|
return end > begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
static bool shl_real_type(double val, char* begin, char*& end)
|
||||||
bool shl_double(double val,T* out)
|
|
||||||
{ using namespace std;
|
{ using namespace std;
|
||||||
if (put_inf_nan(start,finish,val)) return true;
|
if (put_inf_nan(begin, end, val)) return true;
|
||||||
finish = start + sprintf(out,"%.*lg", static_cast<int>(boost::detail::lcast_get_precision<double >()), val );
|
end = begin;
|
||||||
return finish > start;
|
end += sprintf(begin,"%.*lg", static_cast<int>(boost::detail::lcast_get_precision<double>()), val);
|
||||||
|
return end > begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
template <class T>
|
static bool shl_real_type(long double val, char* begin, char*& end)
|
||||||
bool shl_long_double(long double val,T* out)
|
|
||||||
{ using namespace std;
|
{ using namespace std;
|
||||||
if (put_inf_nan(start,finish,val)) return true;
|
if (put_inf_nan(begin, end, val)) return true;
|
||||||
finish = start + sprintf(out,"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double >()), val );
|
end = begin;
|
||||||
return finish > start;
|
end += sprintf(begin,"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double>()), val );
|
||||||
|
return end > begin;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1335,54 +1320,32 @@ namespace boost
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
|
||||||
bool shl_float(float val,wchar_t* out)
|
static bool shl_real_type(float val, wchar_t* begin, wchar_t*& end)
|
||||||
{ using namespace std;
|
{ using namespace std;
|
||||||
if (put_inf_nan(start,finish,val)) return true;
|
if (put_inf_nan(begin, end, val)) return true;
|
||||||
finish = start + swprintf(out,
|
end = begin + swprintf(begin, end-begin,
|
||||||
#if !defined(__MINGW32__) && !defined(UNDER_CE)
|
|
||||||
finish-start,
|
|
||||||
#endif
|
|
||||||
L"%.*g", static_cast<int>(boost::detail::lcast_get_precision<float >()), val );
|
L"%.*g", static_cast<int>(boost::detail::lcast_get_precision<float >()), val );
|
||||||
|
return end > begin;
|
||||||
return finish > start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool shl_real_type(double val, wchar_t* begin, wchar_t*& end)
|
||||||
bool shl_double(double val,wchar_t* out)
|
|
||||||
{ using namespace std;
|
{ using namespace std;
|
||||||
if (put_inf_nan(start,finish,val)) return true;
|
if (put_inf_nan(begin, end, val)) return true;
|
||||||
/* __MINGW32__ is defined for both mingw.org and for mingw-w64.
|
end = begin + swprintf(begin, end-begin,
|
||||||
* For mingw-w64, __MINGW64__ is defined, too, when targetting
|
|
||||||
* 64 bits.
|
|
||||||
*
|
|
||||||
* swprintf realization in MinGW and under WinCE does not conform
|
|
||||||
* to the ISO C
|
|
||||||
* Standard.
|
|
||||||
*/
|
|
||||||
finish = start + swprintf(out,
|
|
||||||
#if !defined(__MINGW32__) && !defined(UNDER_CE)
|
|
||||||
finish-start,
|
|
||||||
#endif
|
|
||||||
L"%.*lg", static_cast<int>(boost::detail::lcast_get_precision<double >()), val );
|
L"%.*lg", static_cast<int>(boost::detail::lcast_get_precision<double >()), val );
|
||||||
return finish > start;
|
return end > begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
static bool shl_real_type(long double val, wchar_t* begin, wchar_t*& end)
|
||||||
bool shl_long_double(long double val,wchar_t* out)
|
|
||||||
{ using namespace std;
|
{ using namespace std;
|
||||||
if (put_inf_nan(start,finish,val)) return true;
|
if (put_inf_nan(begin, end, val)) return true;
|
||||||
finish = start + swprintf(out,
|
end = begin + swprintf(begin, end-begin,
|
||||||
#if !defined(UNDER_CE)
|
|
||||||
finish-start,
|
|
||||||
#endif
|
|
||||||
L"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double >()), val );
|
L"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double >()), val );
|
||||||
return finish > start;
|
return end > begin;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/************************************ OPERATORS << ( ... ) ********************************/
|
/************************************ OPERATORS << ( ... ) ********************************/
|
||||||
public:
|
public:
|
||||||
template<class Alloc>
|
template<class Alloc>
|
||||||
@@ -1486,13 +1449,13 @@ namespace boost
|
|||||||
bool operator<<(unsigned __int64 n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
|
bool operator<<(unsigned __int64 n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
|
||||||
bool operator<<( __int64 n) { return shl_signed(n); }
|
bool operator<<( __int64 n) { return shl_signed(n); }
|
||||||
#endif
|
#endif
|
||||||
bool operator<<(float val) { return shl_float(val,start); }
|
bool operator<<(float val) { return shl_real_type(val, start, finish); }
|
||||||
bool operator<<(double val) { return shl_double(val,start); }
|
bool operator<<(double val) { return shl_real_type(val, start, finish); }
|
||||||
bool operator<<(long double val) {
|
bool operator<<(long double val) {
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
return shl_long_double(val,start);
|
return shl_real_type(val, start, finish);
|
||||||
#else
|
#else
|
||||||
return shl_double(val,start);
|
return shl_real_type(static_cast<double>(val), start, finish);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1884,8 +1847,8 @@ namespace boost
|
|||||||
BOOST_STATIC_CONSTANT(bool, value =
|
BOOST_STATIC_CONSTANT(bool, value =
|
||||||
(
|
(
|
||||||
::boost::type_traits::ice_and<
|
::boost::type_traits::ice_and<
|
||||||
is_arithmetic<Source>::value,
|
::boost::is_arithmetic<Source>::value,
|
||||||
is_arithmetic<Target>::value,
|
::boost::is_arithmetic<Target>::value,
|
||||||
::boost::type_traits::ice_not<
|
::boost::type_traits::ice_not<
|
||||||
detail::is_char_or_wchar<Target>::value
|
detail::is_char_or_wchar<Target>::value
|
||||||
>::value,
|
>::value,
|
||||||
@@ -1923,6 +1886,28 @@ namespace boost
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// this metafunction evaluates to true, if we have optimized comnversion
|
||||||
|
// from Float type to Char array.
|
||||||
|
// Must be in sync with lexical_stream_limited_src<Char, ...>::shl_real_type(...)
|
||||||
|
template <typename Float, typename Char>
|
||||||
|
struct is_this_float_conversion_optimized
|
||||||
|
{
|
||||||
|
typedef ::boost::type_traits::ice_and<
|
||||||
|
::boost::is_float<Float>::value,
|
||||||
|
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
|
||||||
|
::boost::type_traits::ice_or<
|
||||||
|
::boost::type_traits::ice_eq<sizeof(Char), sizeof(char) >::value,
|
||||||
|
::boost::is_same<Char, wchar_t>::value
|
||||||
|
>::value
|
||||||
|
#else
|
||||||
|
::boost::type_traits::ice_eq<sizeof(Char), sizeof(char) >::value
|
||||||
|
#endif
|
||||||
|
> result_type;
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(bool, value = (result_type::value) );
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Target, typename Source>
|
template<typename Target, typename Source>
|
||||||
struct is_char_array_to_stdstring
|
struct is_char_array_to_stdstring
|
||||||
{
|
{
|
||||||
@@ -2003,15 +1988,16 @@ namespace boost
|
|||||||
const bool requires_stringbuf =
|
const bool requires_stringbuf =
|
||||||
!(
|
!(
|
||||||
::boost::type_traits::ice_or<
|
::boost::type_traits::ice_or<
|
||||||
is_stdstring<src >::value,
|
::boost::detail::is_stdstring<src>::value,
|
||||||
is_arithmetic<src >::value,
|
::boost::is_integral<src>::value,
|
||||||
|
::boost::detail::is_this_float_conversion_optimized<src, char_type >::value,
|
||||||
::boost::type_traits::ice_and<
|
::boost::type_traits::ice_and<
|
||||||
is_char_iterator_range<src >::value,
|
::boost::detail::is_char_iterator_range<src >::value,
|
||||||
is_char_types_match
|
is_char_types_match
|
||||||
>::value,
|
>::value,
|
||||||
::boost::type_traits::ice_and<
|
::boost::type_traits::ice_and<
|
||||||
is_pointer<src>::value,
|
::boost::is_pointer<src>::value,
|
||||||
is_char_or_wchar<removed_ptr_t>::value,
|
::boost::detail::is_char_or_wchar<removed_ptr_t>::value,
|
||||||
is_char_types_match
|
is_char_types_match
|
||||||
>::value
|
>::value
|
||||||
>::value
|
>::value
|
||||||
@@ -2047,7 +2033,7 @@ namespace boost
|
|||||||
typedef Source source_type ;
|
typedef Source source_type ;
|
||||||
|
|
||||||
typedef BOOST_DEDUCED_TYPENAME mpl::if_<
|
typedef BOOST_DEDUCED_TYPENAME mpl::if_<
|
||||||
is_arithmetic<Source>, Source, Source const&
|
::boost::is_arithmetic<Source>, Source, Source const&
|
||||||
>::type argument_type ;
|
>::type argument_type ;
|
||||||
|
|
||||||
static source_type nearbyint ( argument_type s )
|
static source_type nearbyint ( argument_type s )
|
||||||
@@ -2138,10 +2124,10 @@ namespace boost
|
|||||||
::boost::is_float<Source>::value
|
::boost::is_float<Source>::value
|
||||||
>::value,
|
>::value,
|
||||||
::boost::type_traits::ice_not<
|
::boost::type_traits::ice_not<
|
||||||
is_same<Source, bool>::value
|
::boost::is_same<Source, bool>::value
|
||||||
>::value,
|
>::value,
|
||||||
::boost::type_traits::ice_not<
|
::boost::type_traits::ice_not<
|
||||||
is_same<Target, bool>::value
|
::boost::is_same<Target, bool>::value
|
||||||
>::value,
|
>::value,
|
||||||
::boost::is_unsigned<Target>::value
|
::boost::is_unsigned<Target>::value
|
||||||
>::value,
|
>::value,
|
||||||
@@ -2157,27 +2143,27 @@ namespace boost
|
|||||||
template<typename Target, typename Source>
|
template<typename Target, typename Source>
|
||||||
inline Target lexical_cast(const Source &arg)
|
inline Target lexical_cast(const Source &arg)
|
||||||
{
|
{
|
||||||
typedef BOOST_DEDUCED_TYPENAME detail::array_to_pointer_decay<Source>::type src;
|
typedef BOOST_DEDUCED_TYPENAME ::boost::detail::array_to_pointer_decay<Source>::type src;
|
||||||
|
|
||||||
typedef BOOST_DEDUCED_TYPENAME ::boost::type_traits::ice_or<
|
typedef BOOST_DEDUCED_TYPENAME ::boost::type_traits::ice_or<
|
||||||
detail::is_xchar_to_xchar<Target, src>::value,
|
::boost::detail::is_xchar_to_xchar<Target, src>::value,
|
||||||
detail::is_char_array_to_stdstring<Target,src>::value,
|
::boost::detail::is_char_array_to_stdstring<Target,src>::value,
|
||||||
::boost::type_traits::ice_and<
|
::boost::type_traits::ice_and<
|
||||||
is_same<Target, src>::value,
|
::boost::is_same<Target, src>::value,
|
||||||
detail::is_stdstring<Target>::value
|
::boost::detail::is_stdstring<Target>::value
|
||||||
>::value
|
>::value
|
||||||
> do_copy_type;
|
> do_copy_type;
|
||||||
|
|
||||||
typedef BOOST_DEDUCED_TYPENAME
|
typedef BOOST_DEDUCED_TYPENAME
|
||||||
detail::is_arithmetic_and_not_xchars<Target, src> do_copy_with_dynamic_check_type;
|
::boost::detail::is_arithmetic_and_not_xchars<Target, src> do_copy_with_dynamic_check_type;
|
||||||
|
|
||||||
typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
|
typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
|
||||||
do_copy_type::value,
|
do_copy_type::value,
|
||||||
detail::lexical_cast_copy<src>,
|
detail::lexical_cast_copy<src>,
|
||||||
BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
|
BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
|
||||||
do_copy_with_dynamic_check_type::value,
|
do_copy_with_dynamic_check_type::value,
|
||||||
detail::lexical_cast_dynamic_num<Target, src>,
|
::boost::detail::lexical_cast_dynamic_num<Target, src>,
|
||||||
detail::lexical_cast_do_cast<Target, src>
|
::boost::detail::lexical_cast_do_cast<Target, src>
|
||||||
>::type
|
>::type
|
||||||
>::type caster_type;
|
>::type caster_type;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user