mirror of
https://github.com/boostorg/conversion.git
synced 2025-08-03 22:44:32 +02:00
Merge branch 'develop'. Drop support of antique compilers
This commit is contained in:
@@ -50,17 +50,6 @@
|
|||||||
# include <boost/limits.hpp>
|
# include <boost/limits.hpp>
|
||||||
# include <boost/detail/select_type.hpp>
|
# include <boost/detail/select_type.hpp>
|
||||||
|
|
||||||
// It has been demonstrated numerous times that MSVC 6.0 fails silently at link
|
|
||||||
// time if you use a template function which has template parameters that don't
|
|
||||||
// appear in the function's argument list.
|
|
||||||
//
|
|
||||||
// TODO: Add this to config.hpp?
|
|
||||||
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
|
|
||||||
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
|
|
||||||
# else
|
|
||||||
# define BOOST_EXPLICIT_DEFAULT_TARGET
|
|
||||||
# endif
|
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
// See the documentation for descriptions of how to choose between
|
// See the documentation for descriptions of how to choose between
|
||||||
@@ -73,7 +62,7 @@ namespace boost
|
|||||||
// section 15.8 exercise 1, page 425.
|
// section 15.8 exercise 1, page 425.
|
||||||
|
|
||||||
template <class Target, class Source>
|
template <class Target, class Source>
|
||||||
inline Target polymorphic_cast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
|
inline Target polymorphic_cast(Source* x)
|
||||||
{
|
{
|
||||||
Target tmp = dynamic_cast<Target>(x);
|
Target tmp = dynamic_cast<Target>(x);
|
||||||
if ( tmp == 0 ) throw std::bad_cast();
|
if ( tmp == 0 ) throw std::bad_cast();
|
||||||
@@ -92,14 +81,12 @@ namespace boost
|
|||||||
// Contributed by Dave Abrahams
|
// Contributed by Dave Abrahams
|
||||||
|
|
||||||
template <class Target, class Source>
|
template <class Target, class Source>
|
||||||
inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
|
inline Target polymorphic_downcast(Source* x)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT( dynamic_cast<Target>(x) == x ); // detect logic error
|
BOOST_ASSERT( dynamic_cast<Target>(x) == x ); // detect logic error
|
||||||
return static_cast<Target>(x);
|
return static_cast<Target>(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
# undef BOOST_EXPLICIT_DEFAULT_TARGET
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
# include <boost/numeric/conversion/cast.hpp>
|
# include <boost/numeric/conversion/cast.hpp>
|
||||||
|
0
include/boost/implicit_cast.hpp
Executable file → Normal file
0
include/boost/implicit_cast.hpp
Executable file → Normal file
@@ -631,12 +631,11 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline
|
||||||
BOOST_DEDUCED_TYPENAME boost::make_unsigned<T>::type lcast_to_unsigned(const T value) BOOST_NOEXCEPT
|
BOOST_DEDUCED_TYPENAME boost::make_unsigned<T>::type lcast_to_unsigned(const T value) BOOST_NOEXCEPT {
|
||||||
{
|
|
||||||
typedef BOOST_DEDUCED_TYPENAME boost::make_unsigned<T>::type result_type;
|
typedef BOOST_DEDUCED_TYPENAME boost::make_unsigned<T>::type result_type;
|
||||||
return static_cast<result_type>(
|
return value < 0
|
||||||
value < 0 ? 0u - static_cast<result_type>(value) : value
|
? static_cast<result_type>(0u - static_cast<result_type>(value))
|
||||||
);
|
: static_cast<result_type>(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1064,9 +1063,6 @@ namespace boost {
|
|||||||
CharT const capital_e = lcast_char_constants<CharT>::capital_e;
|
CharT const capital_e = lcast_char_constants<CharT>::capital_e;
|
||||||
CharT const lowercase_e = lcast_char_constants<CharT>::lowercase_e;
|
CharT const lowercase_e = lcast_char_constants<CharT>::lowercase_e;
|
||||||
|
|
||||||
typedef BOOST_DEDUCED_TYPENAME Traits::int_type int_type;
|
|
||||||
int_type const zero = Traits::to_int_type(czero);
|
|
||||||
|
|
||||||
/* Getting the plus/minus sign */
|
/* Getting the plus/minus sign */
|
||||||
bool const has_minus = Traits::eq(*begin, minus);
|
bool const has_minus = Traits::eq(*begin, minus);
|
||||||
if (has_minus || Traits::eq(*begin, plus)) {
|
if (has_minus || Traits::eq(*begin, plus)) {
|
||||||
@@ -1106,7 +1102,7 @@ namespace boost {
|
|||||||
if (found_decimal) {
|
if (found_decimal) {
|
||||||
/* We allow no thousand_separators after decimal point */
|
/* We allow no thousand_separators after decimal point */
|
||||||
|
|
||||||
const mantissa_type tmp_sub_value = static_cast<mantissa_type>(*begin - zero);
|
const mantissa_type tmp_sub_value = static_cast<mantissa_type>(*begin - czero);
|
||||||
if (Traits::eq(*begin, lowercase_e) || Traits::eq(*begin, capital_e)) break;
|
if (Traits::eq(*begin, lowercase_e) || Traits::eq(*begin, capital_e)) break;
|
||||||
if ( *begin < czero || *begin >= czero + 10 ) return false;
|
if ( *begin < czero || *begin >= czero + 10 ) return false;
|
||||||
if ( is_mantissa_full
|
if ( is_mantissa_full
|
||||||
@@ -1128,7 +1124,7 @@ namespace boost {
|
|||||||
/* Checking for mantissa overflow. If overflow will
|
/* Checking for mantissa overflow. If overflow will
|
||||||
* occur, them we only increase multiplyer
|
* occur, them we only increase multiplyer
|
||||||
*/
|
*/
|
||||||
const mantissa_type tmp_sub_value = static_cast<mantissa_type>(*begin - zero);
|
const mantissa_type tmp_sub_value = static_cast<mantissa_type>(*begin - czero);
|
||||||
if( is_mantissa_full
|
if( is_mantissa_full
|
||||||
|| ((std::numeric_limits<mantissa_type>::max)() - tmp_sub_value) / 10u < mantissa
|
|| ((std::numeric_limits<mantissa_type>::max)() - tmp_sub_value) / 10u < mantissa
|
||||||
)
|
)
|
||||||
@@ -1224,7 +1220,7 @@ namespace boost {
|
|||||||
|
|
||||||
pow_of_10_t exp_pow_of_10 = 0;
|
pow_of_10_t exp_pow_of_10 = 0;
|
||||||
while (begin != end) {
|
while (begin != end) {
|
||||||
pow_of_10_t const sub_value = *begin - zero;
|
pow_of_10_t const sub_value = *begin - czero;
|
||||||
|
|
||||||
if ( *begin < czero || *begin >= czero + 10
|
if ( *begin < czero || *begin >= czero + 10
|
||||||
|| ((std::numeric_limits<pow_of_10_t>::max)() - sub_value) / 10 < exp_pow_of_10)
|
|| ((std::numeric_limits<pow_of_10_t>::max)() - sub_value) / 10 < exp_pow_of_10)
|
||||||
@@ -1733,7 +1729,7 @@ namespace boost {
|
|||||||
} else {
|
} else {
|
||||||
utype const comp_val = static_cast<utype>((std::numeric_limits<Type>::max)());
|
utype const comp_val = static_cast<utype>((std::numeric_limits<Type>::max)());
|
||||||
succeed = succeed && out_tmp<=comp_val;
|
succeed = succeed && out_tmp<=comp_val;
|
||||||
output = out_tmp;
|
output = static_cast<Type>(out_tmp);
|
||||||
}
|
}
|
||||||
return succeed;
|
return succeed;
|
||||||
}
|
}
|
||||||
@@ -1804,7 +1800,7 @@ namespace boost {
|
|||||||
template <std::size_t N, class ArrayT>
|
template <std::size_t N, class ArrayT>
|
||||||
bool shr_std_array(ArrayT& output) BOOST_NOEXCEPT {
|
bool shr_std_array(ArrayT& output) BOOST_NOEXCEPT {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
const std::size_t size = finish - start;
|
const std::size_t size = static_cast<std::size_t>(finish - start);
|
||||||
if (size > N - 1) { // `-1` because we need to store \0 at the end
|
if (size > N - 1) { // `-1` because we need to store \0 at the end
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -367,10 +367,36 @@ void test_conversion_from_to_integral_for_locale()
|
|||||||
BOOST_CHECK( lexical_cast<T>("30000") == static_cast<T>(30000) );
|
BOOST_CHECK( lexical_cast<T>("30000") == static_cast<T>(30000) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
test_conversion_from_integral_to_integral<T>();
|
test_conversion_from_integral_to_integral<T>();
|
||||||
|
|
||||||
|
// This is a part of test_conversion_from_integral_to_string<T>('0') method,
|
||||||
|
// but with BOOST_CHECK_EQUAL instead of BOOST_CHECK. It is required to see
|
||||||
|
// what is produced by the to_str<char>(t) method in situations when result
|
||||||
|
// is different. BOOST_CHECK does not work with wchar_t.
|
||||||
|
typedef std::numeric_limits<T> limits;
|
||||||
|
T t = (limits::min)();
|
||||||
|
BOOST_CHECK_EQUAL(lexical_cast<std::string>(t), to_str<char>(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');
|
test_conversion_from_string_to_integral<T>('0');
|
||||||
#if !defined(BOOST_LCAST_NO_WCHAR_T)
|
#if !defined(BOOST_LCAST_NO_WCHAR_T)
|
||||||
|
if (lexical_cast<std::wstring>(t) != to_str<wchar_t>(t)) {
|
||||||
|
// Something went wrong, and now we are attempting to find and print the
|
||||||
|
// difference.
|
||||||
|
std::wstring wstr = to_str<wchar_t>(t);
|
||||||
|
std::string lcast_str = lexical_cast<std::string>(t);
|
||||||
|
std::string str;
|
||||||
|
str.reserve(wstr.size());
|
||||||
|
for (std::size_t i = 0; i < wstr.size(); ++i) {
|
||||||
|
str.push_back(static_cast<char>(wstr[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(lcast_str.length(), lexical_cast<std::wstring>(t).length());
|
||||||
|
BOOST_CHECK_EQUAL(to_str<char>(t), str);
|
||||||
|
BOOST_CHECK_EQUAL(lcast_str, str);
|
||||||
|
}
|
||||||
|
|
||||||
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');
|
test_conversion_from_string_to_integral<T>(L'0');
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user