Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Boost.Integer dependency #79

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ target_link_libraries(boost_lexical_cast
Boost::config
Boost::container
Boost::core
Boost::integer
Boost::throw_exception
Boost::type_traits
)
Expand Down
3 changes: 1 addition & 2 deletions include/boost/detail/basic_pointerbuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#endif

#include <boost/config.hpp>
#include <boost/integer.hpp>

#include <streambuf>

Expand Down Expand Up @@ -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));
Expand Down
47 changes: 18 additions & 29 deletions include/boost/detail/lcast_precision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,78 +13,67 @@
#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 &&
precision_bin > limits::digits10 + 0UL &&
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);
}

Expand Down
14 changes: 7 additions & 7 deletions include/boost/lexical_cast/detail/converter_lexical_streams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -201,22 +201,22 @@ 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;
}

#ifndef __MINGW32__
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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/lexical_cast/detail/inf_nan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/lexical_cast_old.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Loading