Skip to content
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
38 changes: 18 additions & 20 deletions include/boost/lexical_cast/detail/converter_lexical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@

#include <cstddef>
#include <string>
#include <type_traits>
#include <boost/limits.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/type_identity.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_float.hpp>
#include <boost/detail/lcast_precision.hpp>

#include <boost/lexical_cast/detail/widest_char.hpp>
#include <boost/lexical_cast/detail/is_character.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>

#include <array>

Expand Down Expand Up @@ -97,21 +95,21 @@ namespace boost {
// Returns one of char, wchar_t, char16_t, char32_t or deduce_character_type_later<T> types
// Executed on Stage 1 (See deduce_source_char<T> and deduce_target_char<T>)
template < typename Type >
struct stream_char_common: public boost::conditional<
struct stream_char_common: public std::conditional<
boost::detail::is_character< Type >::value,
Type,
boost::detail::deduce_character_type_later< Type >
> {};

template < typename Char >
struct stream_char_common< Char* >: public boost::conditional<
struct stream_char_common< Char* >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< Char* >
> {};

template < typename Char >
struct stream_char_common< const Char* >: public boost::conditional<
struct stream_char_common< const Char* >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< const Char* >
Expand All @@ -124,14 +122,14 @@ namespace boost {
};

template < typename Char >
struct stream_char_common< boost::iterator_range< Char* > >: public boost::conditional<
struct stream_char_common< boost::iterator_range< Char* > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::iterator_range< Char* > >
> {};

template < typename Char >
struct stream_char_common< boost::iterator_range< const Char* > >: public boost::conditional<
struct stream_char_common< boost::iterator_range< const Char* > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::iterator_range< const Char* > >
Expand All @@ -150,29 +148,29 @@ namespace boost {
};

template < typename Char, std::size_t N >
struct stream_char_common< boost::array< Char, N > >: public boost::conditional<
struct stream_char_common< boost::array< Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::array< Char, N > >
> {};

template < typename Char, std::size_t N >
struct stream_char_common< boost::array< const Char, N > >: public boost::conditional<
struct stream_char_common< boost::array< const Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::array< const Char, N > >
> {};

#ifndef BOOST_NO_CXX11_HDR_ARRAY
template < typename Char, std::size_t N >
struct stream_char_common< std::array<Char, N > >: public boost::conditional<
struct stream_char_common< std::array<Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< std::array< Char, N > >
> {};

template < typename Char, std::size_t N >
struct stream_char_common< std::array< const Char, N > >: public boost::conditional<
struct stream_char_common< std::array< const Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< std::array< const Char, N > >
Expand Down Expand Up @@ -363,7 +361,7 @@ namespace boost {
// When is_specialized is false, the whole expression is 0.
template <class Source>
struct lcast_src_length<
Source, typename boost::enable_if<boost::is_integral<Source> >::type
Source, typename std::enable_if<boost::detail::lcast::is_integral<Source>::value >::type
>
{
BOOST_STATIC_CONSTANT(std::size_t, value =
Expand All @@ -385,7 +383,7 @@ namespace boost {
// sign + leading digit + decimal point + "e" + exponent sign == 5
template<class Source>
struct lcast_src_length<
Source, typename boost::enable_if<boost::is_float<Source> >::type
Source, typename std::enable_if<std::is_floating_point<Source>::value >::type
>
{
static_assert(
Expand All @@ -404,7 +402,7 @@ namespace boost {
template <class Source, class Target>
struct lexical_cast_stream_traits {
typedef typename boost::detail::array_to_pointer_decay<Source>::type src;
typedef typename boost::remove_cv<src>::type no_cv_src;
typedef typename std::remove_cv<src>::type no_cv_src;

typedef boost::detail::deduce_source_char<no_cv_src> deduce_src_char_metafunc;
typedef typename deduce_src_char_metafunc::type src_char_t;
Expand All @@ -415,13 +413,13 @@ namespace boost {
>::type char_type;

#if !defined(BOOST_NO_CXX11_CHAR16_T) && defined(BOOST_NO_CXX11_UNICODE_LITERALS)
static_assert(!boost::is_same<char16_t, src_char_t>::value
&& !boost::is_same<char16_t, target_char_t>::value,
static_assert(!std::is_same<char16_t, src_char_t>::value
&& !std::is_same<char16_t, target_char_t>::value,
"Your compiler does not have full support for char16_t" );
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && defined(BOOST_NO_CXX11_UNICODE_LITERALS)
static_assert(!boost::is_same<char32_t, src_char_t>::value
&& !boost::is_same<char32_t, target_char_t>::value,
static_assert(!std::is_same<char32_t, src_char_t>::value
&& !std::is_same<char32_t, target_char_t>::value,
"Your compiler does not have full support for char32_t" );
#endif

Expand Down
51 changes: 21 additions & 30 deletions include/boost/lexical_cast/detail/converter_lexical_streams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@
#include <string>
#include <cstring>
#include <cstdio>
#include <type_traits>
#include <boost/limits.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/is_unsigned.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>
#include <boost/config/workaround.hpp>
#include <boost/core/snprintf.hpp>

Expand Down Expand Up @@ -71,13 +68,7 @@

#include <array>

#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_float.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/container/container_fwd.hpp>
#include <boost/core/enable_if.hpp>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
Expand All @@ -97,8 +88,8 @@ namespace boost { namespace detail { namespace lcast {

template <typename T>
struct exact {
static_assert(!boost::is_const<T>::value, "");
static_assert(!boost::is_reference<T>::value, "");
static_assert(!std::is_const<T>::value, "");
static_assert(!std::is_reference<T>::value, "");

const T& payload;
};
Expand Down Expand Up @@ -185,7 +176,7 @@ namespace boost { namespace detail { namespace lcast {
template <class T>
inline bool shl_signed(const T n) {
CharT* tmp_finish = buffer + CharacterBufferSize;
typedef typename boost::make_unsigned<T>::type utype;
typedef typename boost::detail::lcast::make_unsigned<T>::type utype;
CharT* tmp_start = lcast_put_unsigned<Traits, utype, CharT>(lcast_to_unsigned(n), tmp_finish).convert();
if (n < 0) {
--tmp_start;
Expand Down Expand Up @@ -256,11 +247,11 @@ namespace boost { namespace detail { namespace lcast {
#endif
public:
template <class C>
using enable_if_compatible_char_t = typename boost::enable_if_c<
boost::is_same<const C, const CharT>::value || (
boost::is_same<const char, const CharT>::value && (
boost::is_same<const C, const unsigned char>::value ||
boost::is_same<const C, const signed char>::value
using enable_if_compatible_char_t = typename std::enable_if<
std::is_same<const C, const CharT>::value || (
std::is_same<const char, const CharT>::value && (
std::is_same<const C, const unsigned char>::value ||
std::is_same<const C, const signed char>::value
)
), bool
>::type;
Expand Down Expand Up @@ -304,19 +295,19 @@ namespace boost { namespace detail { namespace lcast {
bool stream_in(lcast::exact<signed char> x) { return shl_char(static_cast<char>(x.payload)); }

template <class C>
typename boost::enable_if_c<boost::detail::is_character<C>::value, bool>::type
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<C> x) { return shl_char(x.payload); }

template <class Type>
enable_if_compatible_char_t<Type>
stream_in(lcast::exact<Type*> x) { return shl_char_array(reinterpret_cast<CharT const*>(x.payload)); }

template <class Type>
typename boost::enable_if_c<boost::is_signed<Type>::value && !boost::is_enum<Type>::value, bool>::type
typename std::enable_if<!std::is_floating_point<Type>::value && boost::detail::lcast::is_signed<Type>::value && !std::is_enum<Type>::value, bool>::type
stream_in(lcast::exact<Type> x) { return shl_signed(x.payload); }

template <class Type>
typename boost::enable_if_c<boost::is_unsigned<Type>::value && !boost::is_enum<Type>::value, bool>::type
typename std::enable_if<boost::detail::lcast::is_unsigned<Type>::value && !std::is_enum<Type>::value, bool>::type
stream_in(lcast::exact<Type> x) { return shl_unsigned(x.payload); }

template <class Type>
Expand Down Expand Up @@ -398,7 +389,7 @@ namespace boost { namespace detail { namespace lcast {
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
// If you have compilation error at this point, than your STL library
// does not support such conversions. Try updating it.
static_assert(boost::is_same<char, CharT>::value, "");
static_assert(std::is_same<char, CharT>::value, "");
#endif

#ifndef BOOST_NO_EXCEPTIONS
Expand Down Expand Up @@ -440,11 +431,11 @@ namespace boost { namespace detail { namespace lcast {

public:
template <class Type>
typename boost::enable_if_c<boost::detail::is_character<Type>::value && sizeof(char) == sizeof(Type), bool>::type
typename std::enable_if<boost::detail::is_character<Type>::value && sizeof(char) == sizeof(Type), bool>::type
stream_in(lcast::exact<const Type*> x) { return shl_char_array(reinterpret_cast<char const*>(x.payload)); }

template <class Type>
typename boost::enable_if_c<boost::detail::is_character<Type>::value && sizeof(char) != sizeof(Type), bool>::type
typename std::enable_if<boost::detail::is_character<Type>::value && sizeof(char) != sizeof(Type), bool>::type
stream_in(lcast::exact<const Type*> x) { return shl_char_array(x.payload); }

bool stream_in(lcast::exact<float> x) { return shl_real(x.payload); }
Expand All @@ -458,14 +449,14 @@ namespace boost { namespace detail { namespace lcast {
}

template <class C>
typename boost::enable_if_c<boost::detail::is_character<C>::value, bool>::type
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<iterator_range<C*>> x) noexcept {
auto buf = boost::conversion::detail::make_buffer_view(x.payload.begin(), x.payload.end());
return stream_in(lcast::exact<decltype(buf)>{buf});
}

template <class C>
typename boost::enable_if_c<boost::detail::is_character<C>::value, bool>::type
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<iterator_range<const C*>> x) noexcept {
auto buf = boost::conversion::detail::make_buffer_view(x.payload.begin(), x.payload.end());
return stream_in(lcast::exact<decltype(buf)>{buf});
Expand Down Expand Up @@ -526,7 +517,7 @@ namespace boost { namespace detail { namespace lcast {
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
typedef typename make_unsigned<Type>::type utype;
typedef typename boost::detail::lcast::make_unsigned<Type>::type utype;
utype out_tmp = 0;
bool const has_minus = Traits::eq(minus, *start);

Expand All @@ -552,12 +543,12 @@ namespace boost { namespace detail { namespace lcast {
bool shr_using_base_class(InputStreamable& output)
{
static_assert(
!boost::is_pointer<InputStreamable>::value,
!std::is_pointer<InputStreamable>::value,
"boost::lexical_cast can not convert to pointers"
);

#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
static_assert(boost::is_same<char, CharT>::value,
static_assert(std::is_same<char, CharT>::value,
"boost::lexical_cast can not convert, because your STL library does not "
"support such conversions. Try updating it."
);
Expand Down
40 changes: 18 additions & 22 deletions include/boost/lexical_cast/detail/converter_numeric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@
# pragma once
#endif

#include <type_traits>
#include <boost/core/cmath.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/limits.hpp>
#include <boost/type_traits/type_identity.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/type_traits/is_float.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>

namespace boost { namespace detail {

Expand All @@ -52,8 +48,8 @@ constexpr bool is_out_of_range_for(T value) noexcept {

// integral -> integral
template <typename Target, typename Source>
typename boost::enable_if_c<
!boost::is_floating_point<Source>::value && !boost::is_floating_point<Target>::value, bool
typename std::enable_if<
!std::is_floating_point<Source>::value && !std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
const Target target_tmp = static_cast<Target>(arg);
const Source arg_restored = static_cast<Source>(target_tmp);
Expand All @@ -66,8 +62,8 @@ typename boost::enable_if_c<

// integral -> floating point
template <typename Target, typename Source>
typename boost::enable_if_c<
!boost::is_floating_point<Source>::value && boost::is_floating_point<Target>::value, bool
typename std::enable_if<
!std::is_floating_point<Source>::value && std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
const Target target_tmp = static_cast<Target>(arg);
result = target_tmp;
Expand All @@ -77,8 +73,8 @@ typename boost::enable_if_c<

// floating point -> floating point
template <typename Target, typename Source>
typename boost::enable_if_c<
boost::is_floating_point<Source>::value && boost::is_floating_point<Target>::value, bool
typename std::enable_if<
std::is_floating_point<Source>::value && std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
const Target target_tmp = static_cast<Target>(arg);
const Source arg_restored = static_cast<Source>(target_tmp);
Expand All @@ -92,8 +88,8 @@ typename boost::enable_if_c<

// floating point -> integral
template <typename Target, typename Source>
typename boost::enable_if_c<
boost::is_floating_point<Source>::value && !boost::is_floating_point<Target>::value, bool
typename std::enable_if<
std::is_floating_point<Source>::value && !std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
if (detail::is_out_of_range_for<Target>(arg)) {
return false;
Expand Down Expand Up @@ -124,10 +120,10 @@ struct lexical_cast_dynamic_num_ignoring_minus
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
static inline bool try_convert(Source arg, Target& result) noexcept {
typedef typename boost::conditional<
boost::is_float<Source>::value,
typedef typename std::conditional<
std::is_floating_point<Source>::value,
boost::type_identity<Source>,
boost::make_unsigned<Source>
boost::detail::lcast::make_unsigned<Source>
>::type usource_lazy_t;
typedef typename usource_lazy_t::type usource_t;

Expand Down Expand Up @@ -165,11 +161,11 @@ template <typename Target, typename Source>
struct dynamic_num_converter_impl
{
static inline bool try_convert(Source arg, Target& result) noexcept {
typedef typename boost::conditional<
boost::is_unsigned<Target>::value &&
(boost::is_signed<Source>::value || boost::is_float<Source>::value) &&
!(boost::is_same<Source, bool>::value) &&
!(boost::is_same<Target, bool>::value),
typedef typename std::conditional<
boost::detail::lcast::is_unsigned<Target>::value &&
(boost::detail::lcast::is_signed<Source>::value || std::is_floating_point<Source>::value) &&
!(std::is_same<Source, bool>::value) &&
!(std::is_same<Target, bool>::value),
lexical_cast_dynamic_num_ignoring_minus,
lexical_cast_dynamic_num_not_ignoring_minus
>::type caster_type;
Expand Down
Loading
Loading