|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82560 - in trunk: boost libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2013-01-20 07:13:31
Author: apolukhin
Date: 2013-01-20 07:13:31 EST (Sun, 20 Jan 2013)
New Revision: 82560
URL: http://svn.boost.org/trac/boost/changeset/82560
Log:
Attempt to add support for lexical conversions of int128 types (refs #7909)
Text files modified:
trunk/boost/lexical_cast.hpp | 29 ++++++++++++++++++++++++++++-
trunk/libs/conversion/test/lexical_cast_integral_types_test.cpp | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 61 insertions(+), 2 deletions(-)
Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp (original)
+++ trunk/boost/lexical_cast.hpp 2013-01-20 07:13:31 EST (Sun, 20 Jan 2013)
@@ -69,6 +69,11 @@
throw_exception(bad_lexical_cast(typeid(Source), typeid(Target)))
#endif
+#if (defined(BOOST_LCAST_HAS_INT128) && !defined(__GNUC__)) || GCC_VERSION > 40700
+#define BOOST_LCAST_HAS_INT128
+#endif
+
+
namespace boost
{
// exception used to indicate runtime lexical_cast failure
@@ -310,6 +315,11 @@
> {};
#endif
+#ifdef BOOST_LCAST_HAS_INT128
+ template <> struct stream_char_common< boost::int128_type >: public boost::mpl::identity< char > {};
+ template <> struct stream_char_common< boost::uint128_type >: public boost::mpl::identity< char > {};
+#endif
+
#if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T)
template <>
struct stream_char_common< wchar_t >
@@ -602,6 +612,10 @@
BOOST_LCAST_DEF(unsigned __int64)
BOOST_LCAST_DEF( __int64)
#endif
+#ifdef BOOST_LCAST_HAS_INT128
+ BOOST_LCAST_DEF(boost::int128_type)
+ BOOST_LCAST_DEF(boost::uint128_type)
+#endif
#undef BOOST_LCAST_DEF
@@ -1723,6 +1737,12 @@
bool operator<<(unsigned __int64 n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
bool operator<<( __int64 n) { return shl_signed(n); }
#endif
+
+#ifdef BOOST_LCAST_HAS_INT128
+ bool operator<<(const boost::uint128_type& n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
+ bool operator<<(const boost::int128_type& n) { return shl_signed(n); }
+#endif
+
bool operator<<(float val) { return shl_real_type(val, start, finish); }
bool operator<<(double val) { return shl_real_type(val, start, finish); }
bool operator<<(long double val) {
@@ -1916,7 +1936,7 @@
}
/************************************ OPERATORS >> ( ... ) ********************************/
- public:
+ public:
bool operator>>(unsigned short& output) { return shr_unsigned(output); }
bool operator>>(unsigned int& output) { return shr_unsigned(output); }
bool operator>>(unsigned long int& output) { return shr_unsigned(output); }
@@ -1930,6 +1950,12 @@
bool operator>>(unsigned __int64& output) { return shr_unsigned(output); }
bool operator>>(__int64& output) { return shr_signed(output); }
#endif
+
+#ifdef BOOST_LCAST_HAS_INT128
+ bool operator>>(boost::uint128_type& output) { return shr_unsigned(output); }
+ bool operator>>(boost::int128_type& output) { return shr_signed(output); }
+#endif
+
bool operator>>(char& output) { return shr_xchar(output); }
bool operator>>(unsigned char& output) { return shr_xchar(output); }
bool operator>>(signed char& output) { return shr_xchar(output); }
@@ -2563,6 +2589,7 @@
#undef BOOST_LCAST_THROW_BAD_CAST
#undef BOOST_LCAST_NO_WCHAR_T
+#undef BOOST_LCAST_HAS_INT128
#endif // BOOST_LEXICAL_CAST_INCLUDED
Modified: trunk/libs/conversion/test/lexical_cast_integral_types_test.cpp
==============================================================================
--- trunk/libs/conversion/test/lexical_cast_integral_types_test.cpp (original)
+++ trunk/libs/conversion/test/lexical_cast_integral_types_test.cpp 2013-01-20 07:13:31 EST (Sun, 20 Jan 2013)
@@ -47,6 +47,10 @@
#define BOOST_LCAST_NO_WCHAR_T
#endif
+#if (defined(BOOST_LCAST_HAS_INT128) && !defined(__GNUC__)) || GCC_VERSION > 40700
+#define BOOST_LCAST_HAS_INT128
+#endif
+
// Test all 65536 values if true:
bool const lcast_test_small_integral_types_completely = false;
@@ -56,6 +60,8 @@
using namespace boost;
+
+
void test_conversion_from_to_short();
void test_conversion_from_to_ushort();
void test_conversion_from_to_int();
@@ -68,6 +74,10 @@
void test_conversion_from_to_longlong();
void test_conversion_from_to_ulonglong();
#endif
+#ifdef BOOST_LCAST_HAS_INT128
+void test_conversion_from_to_int128();
+void test_conversion_from_to_uint128();
+#endif
void test_integral_conversions_on_min_max();
@@ -88,6 +98,10 @@
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_longlong));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ulonglong));
#endif
+#ifdef BOOST_LCAST_HAS_INT128
+ suite->add(BOOST_TEST_CASE(&test_conversion_from_to_int128));
+ suite->add(BOOST_TEST_CASE(&test_conversion_from_to_uint128));
+#endif
suite->add(BOOST_TEST_CASE(&test_integral_conversions_on_min_max));
return suite;
@@ -372,7 +386,7 @@
};
template<class T>
-void test_conversion_from_to_integral()
+void test_conversion_from_to_integral_minimal()
{
char const zero = '0';
signed char const szero = '0';
@@ -438,7 +452,12 @@
must_owerflow_str += '0';
must_owerflow_negative_str += '0';
}
+}
+template<class T>
+void test_conversion_from_to_integral()
+{
+ test_conversion_from_to_integral_minimal<T>();
typedef std::numpunct<char> numpunct;
restore_oldloc guard;
@@ -536,6 +555,19 @@
#endif
+
+#ifdef BOOST_LCAST_HAS_INT128
+void test_conversion_from_to_int128()
+{
+ test_conversion_from_to_integral_minimal<boost::int128_type>();
+}
+
+void test_conversion_from_to_uint128()
+{
+ test_conversion_from_to_integral_minimal<boost::uint128_type>();
+}
+#endif
+
void test_integral_conversions_on_min_max()
{
typedef std::numeric_limits<int> int_limits;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk