Drop Boost.Integer dependency (#79)

This commit is contained in:
Antony Polukhin
2024-08-14 21:15:33 +03:00
committed by GitHub
parent ff2f0496b0
commit 7f121f8ce3
7 changed files with 29 additions and 42 deletions
-1
View File
@@ -17,7 +17,6 @@ target_link_libraries(boost_lexical_cast
Boost::config
Boost::container
Boost::core
Boost::integer
Boost::throw_exception
Boost::type_traits
)
+1 -2
View File
@@ -19,7 +19,6 @@
#endif
#include <boost/config.hpp>
#include <boost/integer.hpp>
#include <streambuf>
@@ -73,7 +72,7 @@ template<class charT, class BufferT>
typename basic_pointerbuf<charT, BufferT>::pos_type
basic_pointerbuf<charT, BufferT>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
{
typedef typename boost::int_t<sizeof(way) * CHAR_BIT>::least cast_type;
typedef ::std::ios_base::seekdir cast_type;
if(which & ::std::ios_base::out)
return pos_type(off_type(-1));
+18 -29
View File
@@ -13,47 +13,43 @@
#include <limits>
#include <boost/config.hpp>
#include <boost/integer_traits.hpp>
namespace boost { namespace detail {
class lcast_abstract_stub {};
// Calculate an argument to pass to std::ios_base::precision from
// lexical_cast. See alternative implementation for broken standard
// libraries in lcast_get_precision below. Keep them in sync, please.
// lexical_cast.
template<class T>
struct lcast_precision
{
using limits = std::numeric_limits<T>;
BOOST_STATIC_CONSTANT(bool, use_default_precision =
static constexpr bool use_default_precision =
!limits::is_specialized || limits::is_exact
);
;
BOOST_STATIC_CONSTANT(bool, is_specialized_bin =
static constexpr bool is_specialized_bin =
!use_default_precision &&
limits::radix == 2 && limits::digits > 0
);
;
BOOST_STATIC_CONSTANT(bool, is_specialized_dec =
static constexpr bool is_specialized_dec =
!use_default_precision &&
limits::radix == 10 && limits::digits10 > 0
);
;
BOOST_STATIC_CONSTANT(std::streamsize, streamsize_max =
boost::integer_traits<std::streamsize>::const_max
);
static constexpr std::streamsize streamsize_max =
(std::numeric_limits<std::streamsize>::max)()
;
BOOST_STATIC_CONSTANT(unsigned int, precision_dec = limits::digits10 + 1U);
static constexpr unsigned int precision_dec = limits::digits10 + 1U;
static_assert(!is_specialized_dec ||
precision_dec <= streamsize_max + 0UL
, "");
BOOST_STATIC_CONSTANT(unsigned long, precision_bin =
static constexpr unsigned long precision_bin =
2UL + limits::digits * 30103UL / 100000UL
);
;
static_assert(!is_specialized_bin ||
(limits::digits + 0UL < ULONG_MAX / 30103UL &&
@@ -61,30 +57,23 @@ struct lcast_precision
precision_bin <= streamsize_max + 0UL)
, "");
BOOST_STATIC_CONSTANT(std::streamsize, value =
static constexpr std::streamsize value =
is_specialized_bin ? precision_bin
: is_specialized_dec ? precision_dec : 6
);
;
};
template<class T>
inline std::streamsize lcast_get_precision(T* = 0)
{
return lcast_precision<T>::value;
}
template<class T>
inline void lcast_set_precision(std::ios_base& stream, T*)
{
stream.precision(lcast_get_precision<T>());
stream.precision(lcast_precision<T>::value);
}
template<class Source, class Target>
inline void lcast_set_precision(std::ios_base& stream, Source*, Target*)
{
std::streamsize const s = lcast_get_precision(static_cast<Source*>(0));
std::streamsize const t = lcast_get_precision(static_cast<Target*>(0));
std::streamsize const s = lcast_precision<Source>::value;
std::streamsize const t = lcast_precision<Target*>::value;
stream.precision(s > t ? s : t);
}
@@ -39,7 +39,7 @@
#include <boost/type_traits/is_unsigned.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#include <boost/core/snprintf.hpp>
#ifndef BOOST_NO_STD_LOCALE
@@ -201,14 +201,14 @@ namespace boost { namespace detail { namespace lcast {
const double val_as_double = val;
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*g", static_cast<int>(boost::detail::lcast_get_precision<float>()), val_as_double);
"%.*g", static_cast<int>(boost::detail::lcast_precision<float>::value), val_as_double);
return finish > start;
}
bool shl_real_type(double val, char* begin) {
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*g", static_cast<int>(boost::detail::lcast_get_precision<double>()), val);
"%.*g", static_cast<int>(boost::detail::lcast_precision<double>::value), val);
return finish > start;
}
@@ -216,7 +216,7 @@ namespace boost { namespace detail { namespace lcast {
bool shl_real_type(long double val, char* begin) {
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double>()), val );
"%.*Lg", static_cast<int>(boost::detail::lcast_precision<long double>::value), val );
return finish > start;
}
#else
@@ -230,7 +230,7 @@ namespace boost { namespace detail { namespace lcast {
const double val_as_double = val;
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*g",
static_cast<int>(boost::detail::lcast_get_precision<float >()),
static_cast<int>(boost::detail::lcast_precision<float>::value),
val_as_double
);
return finish > start;
@@ -239,7 +239,7 @@ namespace boost { namespace detail { namespace lcast {
bool shl_real_type(double val, wchar_t* begin) {
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*g",
static_cast<int>(boost::detail::lcast_get_precision<double>()),
static_cast<int>(boost::detail::lcast_precision<double>::value),
val
);
return finish > start;
@@ -248,7 +248,7 @@ namespace boost { namespace detail { namespace lcast {
bool shl_real_type(long double val, wchar_t* begin) {
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*Lg",
static_cast<int>(boost::detail::lcast_get_precision<long double>()),
static_cast<int>(boost::detail::lcast_precision<long double>::value),
val
);
return finish > start;
@@ -28,7 +28,7 @@
#endif
#include <boost/limits.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#include <boost/core/cmath.hpp>
#include <cstddef>
#include <cstring>
@@ -30,7 +30,7 @@
#include <cstdio>
#include <boost/limits.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#ifndef BOOST_NO_STD_LOCALE
+1 -1
View File
@@ -35,7 +35,7 @@
#include <boost/limits.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>