This commit is contained in:
2026-03-23 20:54:41 +08:00
commit e13b3650e9
4596 changed files with 1015768 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
#define BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <iosfwd>
namespace boost { namespace conversion { namespace detail {
template < typename CharT >
struct buffer_view {
const CharT* begin;
const CharT* end;
};
template < typename CharT >
buffer_view<CharT> make_buffer_view(const CharT* begin, const CharT* end) {
return buffer_view<CharT>{begin, end};
}
inline buffer_view<char> make_buffer_view(const signed char* begin, const signed char* end) {
return buffer_view<char>{
reinterpret_cast<const char*>(begin),
reinterpret_cast<const char*>(end)
};
}
inline buffer_view<char> make_buffer_view(const unsigned char* begin, const unsigned char* end) {
return buffer_view<char>{
reinterpret_cast<const char*>(begin),
reinterpret_cast<const char*>(end)
};
}
template< typename CharT, typename Elem, typename Traits >
std::basic_ostream<Elem,Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os,
buffer_view<CharT> r)
{
while (r.begin != r.end) {
os << r.begin[0];
++r.begin;
}
return os;
}
}}} // namespace boost::conversion::detail
#endif // BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP

View File

@@ -0,0 +1,483 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
#include <cstddef>
#include <string>
#include <type_traits>
#include <boost/limits.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>
#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
#include <string_view>
#endif
#include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/container/container_fwd.hpp>
#include <boost/lexical_cast/detail/converter_lexical_streams.hpp>
namespace boost {
// Forward declaration
template<class T, std::size_t N>
class array;
template<class IteratorT>
class iterator_range;
// Forward declaration of boost::basic_string_view from Utility
template<class Ch, class Tr> class basic_string_view;
namespace detail // normalize_single_byte_char<Char>
{
// Converts signed/unsigned char to char
template < class Char >
struct normalize_single_byte_char
{
using type = Char;
};
template <>
struct normalize_single_byte_char< signed char >
{
using type = char;
};
template <>
struct normalize_single_byte_char< unsigned char >
{
using type = char;
};
}
namespace detail // deduce_character_type_later<T>
{
// Helper type, meaning that stram character for T must be deduced
// at Stage 2 (See deduce_source_char<T> and deduce_target_char<T>)
template < class T > struct deduce_character_type_later {};
}
namespace detail // stream_char_common<T>
{
// Selectors to choose stream character type (common for Source and Target)
// 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 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 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 std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< const Char* >
> {};
template < typename Char >
struct stream_char_common< boost::conversion::detail::buffer_view< Char > >
{
using type = Char;
};
template < typename Char >
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 std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::iterator_range< const Char* > >
> {};
template < class Char, class Traits, class Alloc >
struct stream_char_common< std::basic_string< Char, Traits, Alloc > >
{
using type = Char;
};
template < class Char, class Traits, class Alloc >
struct stream_char_common< boost::container::basic_string< Char, Traits, Alloc > >
{
using type = Char;
};
template < typename Char, std::size_t N >
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 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 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 std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< std::array< const Char, N > >
> {};
#endif
#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
template < class Char, class Traits >
struct stream_char_common< std::basic_string_view< Char, Traits > >
{
using type = Char;
};
#endif
template < class Char, class Traits >
struct stream_char_common< boost::basic_string_view< Char, Traits > >
{
using type = Char;
};
#ifdef BOOST_HAS_INT128
template <> struct stream_char_common< boost::int128_type >
{
using type = char;
};
template <> struct stream_char_common< boost::uint128_type >
{
using type = char;
};
#endif
#if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T)
template <>
struct stream_char_common< wchar_t >
{
using type = char;
};
#endif
}
namespace detail // deduce_source_char_impl<T>
{
// If type T is `deduce_character_type_later` type, then tries to deduce
// character type using streaming metafunctions.
// Otherwise supplied type T is a character type, that must be normalized
// using normalize_single_byte_char<Char>.
// Executed at Stage 2 (See deduce_source_char<T> and deduce_target_char<T>)
template < class Char >
struct deduce_source_char_impl
{
typedef typename boost::detail::normalize_single_byte_char< Char >::type type;
};
template < class T >
struct deduce_source_char_impl< deduce_character_type_later< T > >
{
template <class U>
static auto left_shift_type(long)
-> decltype( std::declval<std::basic_ostream< char >&>() << std::declval<const U&>(), char{});
#if !defined(BOOST_LCAST_NO_WCHAR_T)
template <class U>
static auto left_shift_type(int)
-> decltype( std::declval<std::basic_ostream< wchar_t >&>() << std::declval<const U&>(), wchar_t{});
#endif
template <class U>
static void left_shift_type(...);
using type = decltype(left_shift_type<T>(1L));
static_assert(!std::is_same<type, void>::value,
#if defined(BOOST_LCAST_NO_WCHAR_T)
"Source type is not std::ostream`able and std::wostream`s are "
"not supported by your STL implementation"
#else
"Source type is neither std::ostream`able nor std::wostream`able"
#endif
);
};
}
namespace detail // deduce_target_char_impl<T>
{
// If type T is `deduce_character_type_later` type, then tries to deduce
// character type using boost::has_right_shift<T> metafunction.
// Otherwise supplied type T is a character type, that must be normalized
// using normalize_single_byte_char<Char>.
// Executed at Stage 2 (See deduce_source_char<T> and deduce_target_char<T>)
template < class Char >
struct deduce_target_char_impl
{
typedef typename normalize_single_byte_char< Char >::type type;
};
template < class T >
struct deduce_target_char_impl< deduce_character_type_later<T> >
{
template <class U>
static auto right_shift_type(long)
-> decltype( std::declval<std::basic_istream< char >&>() >> std::declval<U&>(), char{});
#if !defined(BOOST_LCAST_NO_WCHAR_T)
template <class U>
static auto right_shift_type(int)
-> decltype( std::declval<std::basic_istream< wchar_t >&>() >> std::declval<U&>(), wchar_t{});
#endif
template <class U>
static void right_shift_type(...);
using type = decltype(right_shift_type<T>(1L));
static_assert(!std::is_same<type, void>::value,
#if defined(BOOST_LCAST_NO_WCHAR_T)
"Target type is not std::istream`able and std::wistream`s are "
"not supported by your STL implementation"
#else
"Target type is neither std::istream`able nor std::wistream`able"
#endif
);
};
}
namespace detail // deduce_target_char<T> and deduce_source_char<T>
{
// We deduce stream character types in two stages.
//
// Stage 1 is common for Target and Source. At Stage 1 we get
// non normalized character type (may contain unsigned/signed char)
// or deduce_character_type_later<T> where T is the original type.
// Stage 1 is executed by stream_char_common<T>
//
// At Stage 2 we normalize character types or try to deduce character
// type using metafunctions.
// Stage 2 is executed by deduce_target_char_impl<T> and
// deduce_source_char_impl<T>
//
// deduce_target_char<T> and deduce_source_char<T> functions combine
// both stages
template < class T >
struct deduce_target_char
{
typedef typename stream_char_common< T >::type stage1_type;
typedef typename deduce_target_char_impl< stage1_type >::type type;
};
template < class T >
struct deduce_source_char
{
typedef typename stream_char_common< T >::type stage1_type;
typedef typename deduce_source_char_impl< stage1_type >::type type;
};
}
namespace detail // array_to_pointer_decay<T>
{
template<class T>
struct array_to_pointer_decay
{
typedef T type;
};
template<class T, std::size_t N>
struct array_to_pointer_decay<T[N]>
{
typedef const T * type;
};
}
namespace detail // lcast_src_length
{
// Return max. length of string representation of Source;
template< class Source, // Source type of lexical_cast.
class Enable = void // helper type
>
struct lcast_src_length
{
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
};
// Helper for integral types.
// Notes on length calculation:
// Max length for 32bit int with grouping "\1" and thousands_sep ',':
// "-2,1,4,7,4,8,3,6,4,7"
// ^ - is_signed
// ^ - 1 digit not counted by digits10
// ^^^^^^^^^^^^^^^^^^ - digits10 * 2
//
// Constant is_specialized is used instead of constant 1
// to prevent buffer overflow in a rare case when
// <boost/limits.hpp> doesn't add missing specialization for
// numeric_limits<T> for some integral type T.
// When is_specialized is false, the whole expression is 0.
template <class Source>
struct lcast_src_length<
Source, typename std::enable_if<boost::detail::lcast::is_integral<Source>::value >::type
>
{
BOOST_STATIC_CONSTANT(std::size_t, value =
std::numeric_limits<Source>::is_signed +
std::numeric_limits<Source>::is_specialized + /* == 1 */
std::numeric_limits<Source>::digits10 * 2
);
};
// Helper for floating point types.
// -1.23456789e-123456
// ^ sign
// ^ leading digit
// ^ decimal point
// ^^^^^^^^ lcast_precision<Source>::value
// ^ "e"
// ^ exponent sign
// ^^^^^^ exponent (assumed 6 or less digits)
// sign + leading digit + decimal point + "e" + exponent sign == 5
template<class Source>
struct lcast_src_length<
Source, typename std::enable_if<std::is_floating_point<Source>::value >::type
>
{
static_assert(
std::numeric_limits<Source>::max_exponent10 <= 999999L &&
std::numeric_limits<Source>::min_exponent10 >= -999999L
, "");
BOOST_STATIC_CONSTANT(std::size_t, value =
5 + lcast_precision<Source>::value + 6
);
};
}
namespace detail // lexical_cast_stream_traits<Source, Target>
{
template <class Source, class Target>
struct lexical_cast_stream_traits {
typedef typename boost::detail::array_to_pointer_decay<Source>::type 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;
typedef typename boost::detail::deduce_target_char<Target>::type target_char_t;
typedef typename boost::detail::widest_char<
target_char_t, src_char_t
>::type char_type;
#if !defined(BOOST_NO_CXX11_CHAR16_T) && defined(BOOST_NO_CXX11_UNICODE_LITERALS)
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(!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
typedef std::char_traits<char_type> traits;
typedef boost::detail::lcast_src_length<no_cv_src> len_t;
};
}
namespace detail
{
template<typename Target, typename Source>
struct lexical_converter_impl
{
typedef lexical_cast_stream_traits<Source, Target> stream_trait;
typedef detail::lcast::optimized_src_stream<
typename stream_trait::char_type,
typename stream_trait::traits,
stream_trait::len_t::value + 1
> optimized_src_stream;
template <class T>
static auto detect_type(int)
-> decltype(std::declval<optimized_src_stream&>().stream_in(std::declval<lcast::exact<T>>()), optimized_src_stream{});
template <class T>
static lcast::ios_src_stream<typename stream_trait::char_type, typename stream_trait::traits> detect_type(...);
using from_src_stream = decltype(detect_type<Source>(1));
typedef detail::lcast::to_target_stream<
typename stream_trait::char_type,
typename stream_trait::traits
> to_target_stream;
static inline bool try_convert(const Source& arg, Target& result) {
from_src_stream src_stream;
if (!src_stream.stream_in(lcast::exact<Source>{arg}))
return false;
to_target_stream out(src_stream.cbegin(), src_stream.cend());
if (!out.stream_out(result))
return false;
return true;
}
};
}
} // namespace boost
#undef BOOST_LCAST_NO_WCHAR_T
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP

View File

@@ -0,0 +1,751 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014, Nowember 2016
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_STREAMS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_STREAMS_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
#include <cstddef>
#include <string>
#include <cstring>
#include <cstdio>
#include <type_traits>
#include <boost/limits.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>
#ifndef BOOST_NO_STD_LOCALE
# include <locale>
#else
# ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
// Getting error at this point means, that your STL library is old/lame/misconfigured.
// If nothing can be done with STL library, define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE,
// but beware: lexical_cast will understand only 'C' locale delimeters and thousands
// separators.
# error "Unable to use <locale> header. Define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE to force "
# error "boost::lexical_cast to use only 'C' locale during conversions."
# endif
#endif
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
#else
#include <sstream>
#endif
#include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
#include <boost/lexical_cast/detail/lcast_unsigned_converters.hpp>
#include <boost/lexical_cast/detail/lcast_basic_unlockedbuf.hpp>
#include <boost/lexical_cast/detail/inf_nan.hpp>
#include <istream>
#include <array>
#include <boost/container/container_fwd.hpp>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
// Forward declarations
namespace boost {
template<class T, std::size_t N>
class array;
template<class IteratorT>
class iterator_range;
// forward declaration of boost::basic_string_view from Utility
template<class Ch, class Tr> class basic_string_view;
}
namespace boost { namespace detail { namespace lcast {
template <typename T>
struct exact {
static_assert(!std::is_const<T>::value, "");
static_assert(!std::is_reference<T>::value, "");
const T& payload;
};
template< class CharT // a result of widest_char transformation
, class Traits
, std::size_t CharacterBufferSize
>
class optimized_src_stream {
CharT buffer[CharacterBufferSize];
// After the `stream_in(` finishes, `[start, finish)` is
// the range to output by `operator >>`
const CharT* start;
const CharT* finish;
public:
optimized_src_stream(optimized_src_stream&&) = delete;
optimized_src_stream(const optimized_src_stream&) = delete;
optimized_src_stream& operator=(optimized_src_stream&&) = delete;
optimized_src_stream& operator=(const optimized_src_stream&) = delete;
optimized_src_stream() noexcept
: start(buffer)
, finish(buffer + CharacterBufferSize)
{}
const CharT* cbegin() const noexcept {
return start;
}
const CharT* cend() const noexcept {
return finish;
}
private:
bool shl_char(CharT ch) noexcept {
Traits::assign(buffer[0], ch);
finish = start + 1;
return true;
}
#ifndef BOOST_LCAST_NO_WCHAR_T
template <class T>
bool shl_char(T ch) {
static_assert(sizeof(T) <= sizeof(CharT),
"boost::lexical_cast does not support narrowing of char types."
"Use boost::locale instead" );
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
std::locale loc;
CharT const w = BOOST_USE_FACET(std::ctype<CharT>, loc).widen(ch);
#else
CharT const w = static_cast<CharT>(ch);
#endif
Traits::assign(buffer[0], w);
finish = start + 1;
return true;
}
#endif
bool shl_char_array(CharT const* str_value) noexcept {
start = str_value;
finish = start + Traits::length(str_value);
return true;
}
bool shl_char_array_limited(CharT const* str, std::size_t max_size) noexcept {
start = str;
finish = start;
const auto zero = Traits::to_char_type(0);
while (finish < start + max_size && zero != *finish) {
++ finish;
}
return true;
}
template <class T>
inline bool shl_unsigned(const T n) {
CharT* tmp_finish = buffer + CharacterBufferSize;
start = lcast_put_unsigned<Traits, T, CharT>(n, tmp_finish).convert();
finish = tmp_finish;
return true;
}
template <class T>
inline bool shl_signed(const T n) {
CharT* tmp_finish = buffer + CharacterBufferSize;
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;
CharT const minus = lcast_char_constants<CharT>::minus;
Traits::assign(*tmp_start, minus);
}
start = tmp_start;
finish = tmp_finish;
return true;
}
bool shl_real_type(lcast::exact<float> val, char* begin) {
const double val_as_double = static_cast<double>(val.payload);
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*g", static_cast<int>(boost::detail::lcast_precision<float>::value), val_as_double);
return finish > start;
}
bool shl_real_type(lcast::exact<double> val, char* begin) {
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*g", static_cast<int>(boost::detail::lcast_precision<double>::value), val.payload);
return finish > start;
}
#ifndef __MINGW32__
bool shl_real_type(lcast::exact<long double> val, char* begin) {
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*Lg", static_cast<int>(boost::detail::lcast_precision<long double>::value), val.payload );
return finish > start;
}
#else
bool shl_real_type(lcast::exact<long double> val, char* begin) {
return shl_real_type(lcast::exact<double>{static_cast<double>(val.payload)}, begin);
}
#endif
#if !defined(BOOST_LCAST_NO_WCHAR_T)
bool shl_real_type(lcast::exact<float> val, wchar_t* begin) {
const double val_as_double = static_cast<double>(val.payload);
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*g",
static_cast<int>(boost::detail::lcast_precision<float>::value),
val_as_double
);
return finish > start;
}
bool shl_real_type(lcast::exact<double> val, wchar_t* begin) {
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*g",
static_cast<int>(boost::detail::lcast_precision<double>::value),
val.payload
);
return finish > start;
}
bool shl_real_type(lcast::exact<long double> val, wchar_t* begin) {
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*Lg",
static_cast<int>(boost::detail::lcast_precision<long double>::value),
val.payload
);
return finish > start;
}
#endif
public:
template <class C>
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;
template<class CharTraits, class Alloc>
bool stream_in(lcast::exact<std::basic_string<CharT,CharTraits,Alloc>> x) noexcept {
start = x.payload.data();
finish = start + x.payload.length();
return true;
}
template<class CharTraits, class Alloc>
bool stream_in(lcast::exact<boost::container::basic_string<CharT,CharTraits,Alloc>> x) noexcept {
start = x.payload.data();
finish = start + x.payload.length();
return true;
}
bool stream_in(lcast::exact<bool> x) noexcept {
CharT const czero = lcast_char_constants<CharT>::zero;
Traits::assign(buffer[0], Traits::to_char_type(czero + x.payload));
finish = start + 1;
return true;
}
bool stream_in(lcast::exact<boost::conversion::detail::buffer_view<CharT>> x) noexcept {
start = x.payload.begin;
finish = x.payload.end;
return true;
}
template <class C>
enable_if_compatible_char_t<C>
stream_in(lcast::exact<boost::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});
}
bool stream_in(lcast::exact<char> x) { return shl_char(x.payload); }
bool stream_in(lcast::exact<unsigned char> x) { return shl_char(static_cast<char>(x.payload)); }
bool stream_in(lcast::exact<signed char> x) { return shl_char(static_cast<char>(x.payload)); }
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
template <class C>
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<C> x) { return shl_char(x.payload); }
#endif
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 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 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>
auto stream_in(lcast::exact<Type> x) -> decltype(shl_real_type(x, buffer)) {
const CharT* inf_nan = detail::get_inf_nan(x.payload, CharT());
if (inf_nan) {
start = inf_nan;
finish = start + Traits::length(inf_nan);
return true;
}
return shl_real_type(x, buffer);
}
template <class C, std::size_t N>
enable_if_compatible_char_t<C>
stream_in(lcast::exact<boost::array<C, N>> x) noexcept {
return shl_char_array_limited(reinterpret_cast<const CharT*>(x.payload.data()), N);
}
template <class C, std::size_t N>
enable_if_compatible_char_t<C>
stream_in(lcast::exact<std::array<C, N>> x) noexcept {
return shl_char_array_limited(reinterpret_cast<const CharT*>(x.payload.data()), N);
}
#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
template <class C, class CharTraits>
enable_if_compatible_char_t<C>
stream_in(lcast::exact<std::basic_string_view<C, CharTraits>> x) noexcept {
start = reinterpret_cast<const CharT*>(x.payload.data());
finish = start + x.payload.size();
return true;
}
#endif
template <class C, class CharTraits>
enable_if_compatible_char_t<C>
stream_in(lcast::exact<boost::basic_string_view<C, CharTraits>> x) noexcept {
start = reinterpret_cast<const CharT*>(x.payload.data());
finish = start + x.payload.size();
return true;
}
};
template <class CharT, class Traits>
class ios_src_stream {
typedef detail::lcast::out_stream_t<CharT, Traits> deduced_out_stream_t;
typedef detail::lcast::stringbuffer_t<CharT, Traits> deduced_out_buffer_t;
deduced_out_buffer_t out_buffer;
deduced_out_stream_t out_stream;
const CharT* start = nullptr;
const CharT* finish = nullptr;
public:
ios_src_stream(ios_src_stream&&) = delete;
ios_src_stream(const ios_src_stream&) = delete;
ios_src_stream& operator=(ios_src_stream&&) = delete;
ios_src_stream& operator=(const ios_src_stream&) = delete;
ios_src_stream(): out_buffer(), out_stream(&out_buffer) {}
const CharT* cbegin() const noexcept {
return start;
}
const CharT* cend() const noexcept {
return finish;
}
private:
const deduced_out_buffer_t* get_rdbuf() const {
return static_cast<deduced_out_buffer_t*>(
out_stream.rdbuf()
);
}
template<typename InputStreamable>
bool shl_input_streamable(InputStreamable& input) {
#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(std::is_same<char, CharT>::value, "");
#endif
#ifndef BOOST_NO_EXCEPTIONS
out_stream.exceptions(std::ios::badbit);
try {
#endif
bool const result = !(out_stream << input).fail();
const auto* const p = get_rdbuf();
start = p->pbase();
finish = p->pptr();
return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch (const ::std::ios_base::failure& /*f*/) {
return false;
}
#endif
}
template <class T>
bool shl_char_array(T const* str_value) {
static_assert(sizeof(T) <= sizeof(CharT),
"boost::lexical_cast does not support narrowing of char types."
"Use boost::locale instead" );
return shl_input_streamable(str_value);
}
template <class T>
bool shl_real(T val) {
const CharT* inf_nan = detail::get_inf_nan(val, CharT());
if (inf_nan) {
start = inf_nan;
finish = start + Traits::length(inf_nan);
return true;
}
boost::detail::lcast_set_precision(out_stream, &val);
return shl_input_streamable(val);
}
public:
template <class 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 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); }
bool stream_in(lcast::exact<double> x) { return shl_real(x.payload); }
bool stream_in(lcast::exact<long double> x) {
#ifndef __MINGW32__
return shl_real(x.payload);
#else
return shl_real(static_cast<double>(x.payload));
#endif
}
template <class C>
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 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});
}
template <class InStreamable>
bool stream_in(lcast::exact<InStreamable> x) { return shl_input_streamable(x.payload); }
};
template <class CharT, class Traits>
class to_target_stream {
//`[start, finish)` is the range to output by `operator >>`
const CharT* start;
const CharT* const finish;
public:
to_target_stream(to_target_stream&&) = delete;
to_target_stream(const to_target_stream&) = delete;
to_target_stream& operator=(to_target_stream&&) = delete;
to_target_stream& operator=(const to_target_stream&) = delete;
to_target_stream(const CharT* begin, const CharT* end) noexcept
: start(begin)
, finish(end)
{}
private:
template <typename Type>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
bool shr_unsigned(Type& output) {
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
bool const has_minus = Traits::eq(minus, *start);
/* We won`t use `start' any more, so no need in decrementing it after */
if (has_minus || Traits::eq(plus, *start)) {
++start;
}
bool const succeed = lcast_ret_unsigned<Traits, Type, CharT>(output, start, finish).convert();
if (has_minus) {
output = static_cast<Type>(0u - output);
}
return succeed;
}
template <typename Type>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
bool shr_signed(Type& output) {
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
typedef typename boost::detail::lcast::make_unsigned<Type>::type utype;
utype out_tmp = 0;
bool const has_minus = Traits::eq(minus, *start);
/* We won`t use `start' any more, so no need in decrementing it after */
if (has_minus || Traits::eq(plus, *start)) {
++start;
}
bool succeed = lcast_ret_unsigned<Traits, utype, CharT>(out_tmp, start, finish).convert();
if (has_minus) {
utype const comp_val = (static_cast<utype>(1) << std::numeric_limits<Type>::digits);
succeed = succeed && out_tmp<=comp_val;
output = static_cast<Type>(0u - out_tmp);
} else {
utype const comp_val = static_cast<utype>((std::numeric_limits<Type>::max)());
succeed = succeed && out_tmp<=comp_val;
output = static_cast<Type>(out_tmp);
}
return succeed;
}
template<typename InputStreamable>
bool shr_using_base_class(InputStreamable& output)
{
static_assert(
!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(std::is_same<char, CharT>::value,
"boost::lexical_cast can not convert, because your STL library does not "
"support such conversions. Try updating it."
);
#endif
#if defined(BOOST_NO_STRINGSTREAM)
std::istrstream stream(start, static_cast<std::istrstream::streamsize>(finish - start));
#else
typedef detail::lcast::buffer_t<CharT, Traits> buffer_t;
buffer_t buf;
// Usually `istream` and `basic_istream` do not modify
// content of buffer; `buffer_t` assures that this is true
buf.setbuf(const_cast<CharT*>(start), static_cast<typename buffer_t::streamsize>(finish - start));
#if defined(BOOST_NO_STD_LOCALE)
std::istream stream(&buf);
#else
std::basic_istream<CharT, Traits> stream(&buf);
#endif // BOOST_NO_STD_LOCALE
#endif // BOOST_NO_STRINGSTREAM
#ifndef BOOST_NO_EXCEPTIONS
stream.exceptions(std::ios::badbit);
try {
#endif
stream.unsetf(std::ios::skipws);
boost::detail::lcast_set_precision(stream, static_cast<InputStreamable*>(0));
return (stream >> output)
&& (stream.get() == Traits::eof());
#ifndef BOOST_NO_EXCEPTIONS
} catch (const ::std::ios_base::failure& /*f*/) {
return false;
}
#endif
}
template<class T>
inline bool shr_xchar(T& output) noexcept {
static_assert(sizeof(CharT) == sizeof(T),
"boost::lexical_cast does not support narrowing of character types."
"Use boost::locale instead" );
bool const ok = (finish - start == 1);
if (ok) {
CharT out;
Traits::assign(out, *start);
output = static_cast<T>(out);
}
return ok;
}
template <std::size_t N, class ArrayT>
bool shr_std_array(ArrayT& output) noexcept {
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
return false;
}
std::memcpy(&output[0], start, size * sizeof(CharT));
output[size] = Traits::to_char_type(0);
return true;
}
public:
bool stream_out(unsigned short& output) { return shr_unsigned(output); }
bool stream_out(unsigned int& output) { return shr_unsigned(output); }
bool stream_out(unsigned long int& output) { return shr_unsigned(output); }
bool stream_out(short& output) { return shr_signed(output); }
bool stream_out(int& output) { return shr_signed(output); }
bool stream_out(long int& output) { return shr_signed(output); }
#if defined(BOOST_HAS_LONG_LONG)
bool stream_out(boost::ulong_long_type& output) { return shr_unsigned(output); }
bool stream_out(boost::long_long_type& output) { return shr_signed(output); }
#elif defined(BOOST_HAS_MS_INT64)
bool stream_out(unsigned __int64& output) { return shr_unsigned(output); }
bool stream_out(__int64& output) { return shr_signed(output); }
#endif
#ifdef BOOST_HAS_INT128
bool stream_out(boost::uint128_type& output) { return shr_unsigned(output); }
bool stream_out(boost::int128_type& output) { return shr_signed(output); }
#endif
bool stream_out(char& output) { return shr_xchar(output); }
bool stream_out(unsigned char& output) { return shr_xchar(output); }
bool stream_out(signed char& output) { return shr_xchar(output); }
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
bool stream_out(wchar_t& output) { return shr_xchar(output); }
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
bool stream_out(char16_t& output) { return shr_xchar(output); }
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
bool stream_out(char32_t& output) { return shr_xchar(output); }
#endif
template<class CharTraits, class Alloc>
bool stream_out(std::basic_string<CharT,CharTraits,Alloc>& str) {
str.assign(start, finish); return true;
}
template<class CharTraits, class Alloc>
bool stream_out(boost::container::basic_string<CharT,CharTraits,Alloc>& str) {
str.assign(start, finish); return true;
}
template <class C, std::size_t N>
bool stream_out(std::array<C, N>& output) noexcept {
static_assert(sizeof(C) == sizeof(CharT), "");
return shr_std_array<N>(output);
}
template <class C, std::size_t N>
bool stream_out(boost::array<C, N>& output) noexcept {
static_assert(sizeof(C) == sizeof(CharT), "");
return shr_std_array<N>(output);
}
bool stream_out(bool& output) noexcept {
output = false; // Suppress warning about uninitalized variable
if (start == finish) return false;
CharT const zero = lcast_char_constants<CharT>::zero;
CharT const plus = lcast_char_constants<CharT>::plus;
CharT const minus = lcast_char_constants<CharT>::minus;
const CharT* const dec_finish = finish - 1;
output = Traits::eq(*dec_finish, zero + 1);
if (!output && !Traits::eq(*dec_finish, zero)) {
return false; // Does not ends on '0' or '1'
}
if (start == dec_finish) return true;
// We may have sign at the beginning
if (Traits::eq(plus, *start) || (Traits::eq(minus, *start) && !output)) {
++ start;
}
// Skipping zeros
while (start != dec_finish) {
if (!Traits::eq(zero, *start)) {
return false; // Not a zero => error
}
++ start;
}
return true;
}
private:
// Not optimised converter
template <class T>
bool float_types_converter_internal(T& output) {
if (parse_inf_nan(start, finish, output)) return true;
bool const return_value = shr_using_base_class(output);
/* Some compilers and libraries successfully
* parse 'inf', 'INFINITY', '1.0E', '1.0E-'...
* We are trying to provide a unified behaviour,
* so we just forbid such conversions (as some
* of the most popular compilers/libraries do)
* */
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
CharT const capital_e = lcast_char_constants<CharT>::capital_e;
CharT const lowercase_e = lcast_char_constants<CharT>::lowercase_e;
if ( return_value &&
(
Traits::eq(*(finish-1), lowercase_e) // 1.0e
|| Traits::eq(*(finish-1), capital_e) // 1.0E
|| Traits::eq(*(finish-1), minus) // 1.0e- or 1.0E-
|| Traits::eq(*(finish-1), plus) // 1.0e+ or 1.0E+
)
) return false;
return return_value;
}
public:
bool stream_out(float& output) { return float_types_converter_internal(output); }
bool stream_out(double& output) { return float_types_converter_internal(output); }
bool stream_out(long double& output) { return float_types_converter_internal(output); }
// Generic istream-based algorithm.
// lcast_streambuf_for_target<InputStreamable>::value is true.
template <typename InputStreamable>
bool stream_out(InputStreamable& output) {
return shr_using_base_class(output);
}
};
}}} // namespace boost::detail::lcast
#undef BOOST_LCAST_NO_WCHAR_T
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP

View File

@@ -0,0 +1,180 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2016
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_NUMERIC_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_NUMERIC_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <type_traits>
#include <boost/core/cmath.hpp>
#include <boost/limits.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>
namespace boost { namespace detail {
template <class Source, class Target>
bool ios_numeric_comparer_float(Source x, Source y) noexcept {
return x == y
|| (boost::core::isnan(x) && boost::core::isnan(y))
|| (x < (std::numeric_limits<Target>::min)())
;
}
template <class RangeType, class T>
constexpr bool is_out_of_range_for(T value) noexcept {
return value > static_cast<T>((std::numeric_limits<RangeType>::max)())
|| value < static_cast<T>((std::numeric_limits<RangeType>::min)())
|| boost::core::isnan(value);
}
// integral -> integral
template <typename Target, typename Source>
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);
if (arg == arg_restored) {
result = target_tmp;
return true;
}
return false;
}
// integral -> floating point
template <typename Target, typename Source>
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;
return true;
}
// floating point -> floating point
template <typename Target, typename Source>
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);
if (detail::ios_numeric_comparer_float<Source, Target>(arg, arg_restored)) {
result = target_tmp;
return true;
}
return false;
}
// floating point -> integral
template <typename Target, typename Source>
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;
}
const Target target_tmp = static_cast<Target>(arg);
const Source arg_restored = static_cast<Source>(target_tmp);
if (arg == arg_restored /* special values are handled in detail::is_out_of_range_for */) {
result = target_tmp;
return true;
}
return false;
}
struct lexical_cast_dynamic_num_not_ignoring_minus
{
template <typename Target, typename Source>
static inline bool try_convert(Source arg, Target& result) noexcept {
return boost::detail::noexcept_numeric_convert<Target, Source >(arg, result);
}
};
struct lexical_cast_dynamic_num_ignoring_minus
{
template <typename Target, typename Source>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
static inline bool try_convert(Source arg, Target& result) noexcept {
typedef typename std::conditional<
std::is_floating_point<Source>::value,
std::conditional<true, Source, Source>, // std::type_identity emulation
boost::detail::lcast::make_unsigned<Source>
>::type usource_lazy_t;
typedef typename usource_lazy_t::type usource_t;
if (arg < 0) {
const bool res = boost::detail::noexcept_numeric_convert<Target, usource_t>(
static_cast<usource_t>(0u - static_cast<usource_t>(arg)), result
);
result = static_cast<Target>(0u - result);
return res;
} else {
return boost::detail::noexcept_numeric_convert<Target, usource_t>(arg, result);
}
}
};
/*
* dynamic_num_converter_impl follows the rules:
* 1) If Source can be converted to Target without precision loss and
* without overflows, then assign Source to Target and return
*
* 2) If Source is less than 0 and Target is an unsigned integer,
* then negate Source, check the requirements of rule 1) and if
* successful, assign static_casted Source to Target and return
*
* 3) Otherwise throw a bad_lexical_cast exception
*
*
* Rule 2) required because boost::lexical_cast has the behavior of
* stringstream, which uses the rules of scanf for conversions. And
* in the C99 standard for unsigned input value minus sign is
* optional, so if a negative number is read, no errors will arise
* and the result will be the two's complement.
*/
template <typename Target, typename Source>
struct dynamic_num_converter_impl
{
static inline bool try_convert(Source arg, Target& result) noexcept {
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;
return caster_type::try_convert(arg, result);
}
};
}} // namespace boost::detail
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_NUMERIC_HPP

View File

@@ -0,0 +1,187 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
#ifndef BOOST_LEXICAL_CAST_DETAIL_INF_NAN_HPP
#define BOOST_LEXICAL_CAST_DETAIL_INF_NAN_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
#include <boost/limits.hpp>
#include <boost/config/workaround.hpp>
#include <boost/core/cmath.hpp>
#include <cstddef>
#include <cstring>
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
namespace boost {
namespace detail
{
template <class CharT>
bool lc_iequal(const CharT* val, const CharT* lcase, const CharT* ucase, unsigned int len) noexcept {
for( unsigned int i=0; i < len; ++i ) {
if ( val[i] != lcase[i] && val[i] != ucase[i] ) return false;
}
return true;
}
/* Returns true and sets the correct value if found NaN or Inf. */
template <class CharT, class T>
inline bool parse_inf_nan_impl(const CharT* begin, const CharT* end, T& value
, const CharT* lc_NAN, const CharT* lc_nan
, const CharT* lc_INFINITY, const CharT* lc_infinity
, const CharT opening_brace, const CharT closing_brace) noexcept
{
if (begin == end) return false;
const CharT minus = lcast_char_constants<CharT>::minus;
const CharT plus = lcast_char_constants<CharT>::plus;
const int inifinity_size = 8; // == sizeof("infinity") - 1
/* Parsing +/- */
bool const has_minus = (*begin == minus);
if (has_minus || *begin == plus) {
++ begin;
}
if (end - begin < 3) return false;
if (lc_iequal(begin, lc_nan, lc_NAN, 3)) {
begin += 3;
if (end != begin) {
/* It is 'nan(...)' or some bad input*/
if (end - begin < 2) return false; // bad input
-- end;
if (*begin != opening_brace || *end != closing_brace) return false; // bad input
}
if( !has_minus ) value = std::numeric_limits<T>::quiet_NaN();
else value = boost::core::copysign(std::numeric_limits<T>::quiet_NaN(), static_cast<T>(-1));
return true;
} else if (
( /* 'INF' or 'inf' */
end - begin == 3 // 3 == sizeof('inf') - 1
&& lc_iequal(begin, lc_infinity, lc_INFINITY, 3)
)
||
( /* 'INFINITY' or 'infinity' */
end - begin == inifinity_size
&& lc_iequal(begin, lc_infinity, lc_INFINITY, inifinity_size)
)
)
{
if( !has_minus ) value = std::numeric_limits<T>::infinity();
else value = -std::numeric_limits<T>::infinity();
return true;
}
return false;
}
template <class CharT, class T>
const CharT* get_inf_nan_impl(T value
, const CharT* lc_nan
, const CharT* lc_minus_nan
, const CharT* lc_infinity
, const CharT* lc_minus_infinity) noexcept
{
if (boost::core::isnan(value)) {
if (boost::core::signbit(value)) {
return lc_minus_nan;
}
return lc_nan;
} else if (boost::core::isinf(value)) {
if (boost::core::signbit(value)) {
return lc_minus_infinity;
}
return lc_infinity;
}
return nullptr;
}
#ifndef BOOST_LCAST_NO_WCHAR_T
template <class T>
bool parse_inf_nan(const wchar_t* begin, const wchar_t* end, T& value) noexcept {
return parse_inf_nan_impl(begin, end, value
, L"NAN", L"nan"
, L"INFINITY", L"infinity"
, L'(', L')');
}
template <class T>
const wchar_t* get_inf_nan(T value, wchar_t) noexcept {
return detail::get_inf_nan_impl(value, L"nan", L"-nan", L"inf", L"-inf");
}
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
template <class T>
bool parse_inf_nan(const char16_t* begin, const char16_t* end, T& value) noexcept {
return parse_inf_nan_impl(begin, end, value
, u"NAN", u"nan"
, u"INFINITY", u"infinity"
, u'(', u')');
}
template <class T>
const char16_t* get_inf_nan(T value, char16_t) noexcept {
return detail::get_inf_nan_impl(value, u"nan", u"-nan", u"inf", u"-inf");
}
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
template <class T>
bool parse_inf_nan(const char32_t* begin, const char32_t* end, T& value) noexcept {
return parse_inf_nan_impl(begin, end, value
, U"NAN", U"nan"
, U"INFINITY", U"infinity"
, U'(', U')');
}
template <class T>
const char32_t* get_inf_nan(T value, char32_t) noexcept {
return detail::get_inf_nan_impl(value, U"nan", U"-nan", U"inf", U"-inf");
}
#endif
template <class CharT, class T>
bool parse_inf_nan(const CharT* begin, const CharT* end, T& value) noexcept {
return parse_inf_nan_impl(begin, end, value
, "NAN", "nan"
, "INFINITY", "infinity"
, '(', ')');
}
template <class T>
const char* get_inf_nan(T value, char) noexcept {
return detail::get_inf_nan_impl(value, "nan", "-nan", "inf", "-inf");
}
}
} // namespace boost
#undef BOOST_LCAST_NO_WCHAR_T
#endif // BOOST_LEXICAL_CAST_DETAIL_INF_NAN_HPP

View File

@@ -0,0 +1,51 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
#ifndef BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
#define BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
#include <type_traits>
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
namespace boost { namespace detail {
// returns true, if T is one of the character types
template < typename T >
using is_character = std::integral_constant<
bool,
std::is_same< T, char >::value ||
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING)
std::is_same< T, wchar_t >::value ||
#endif
#ifndef BOOST_NO_CXX11_CHAR16_T
std::is_same< T, char16_t >::value ||
#endif
#ifndef BOOST_NO_CXX11_CHAR32_T
std::is_same< T, char32_t >::value ||
#endif
std::is_same< T, unsigned char >::value ||
std::is_same< T, signed char >::value
>;
}}
#endif // BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP

View File

@@ -0,0 +1,73 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_BASIC_UNLOCKEDBUF_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_BASIC_UNLOCKEDBUF_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
#else
#include <sstream>
#endif
#include <boost/detail/basic_pointerbuf.hpp>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
namespace boost { namespace detail { namespace lcast {
// acts as a stream buffer which wraps around a pair of pointers
// and gives acces to internals
template <class BufferType, class CharT>
class basic_unlockedbuf : public basic_pointerbuf<CharT, BufferType> {
public:
typedef basic_pointerbuf<CharT, BufferType> base_type;
typedef typename base_type::streamsize streamsize;
using base_type::pptr;
using base_type::pbase;
using base_type::setbuf;
};
#if defined(BOOST_NO_STRINGSTREAM)
template <class CharT, class Traits>
using out_stream_t = std::ostream;
template <class CharT, class Traits>
using stringbuffer_t = basic_unlockedbuf<std::strstreambuf, char>;
#elif defined(BOOST_NO_STD_LOCALE)
template <class CharT, class Traits>
using out_stream_t = std::ostream;
template <class CharT, class Traits>
using stringbuffer_t = basic_unlockedbuf<std::stringbuf, char>;
template <class CharT, class Traits>
using buffer_t = basic_unlockedbuf<std::streambuf, char>;
#else
template <class CharT, class Traits>
using out_stream_t = std::basic_ostream<CharT, Traits>;
template <class CharT, class Traits>
using stringbuffer_t = basic_unlockedbuf<std::basic_stringbuf<CharT, Traits>, CharT>;
template <class CharT, class Traits>
using buffer_t = basic_unlockedbuf<std::basic_streambuf<CharT, Traits>, CharT>;
#endif
}}} // namespace boost::detail::lcast
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_BASIC_UNLOCKEDBUF_HPP

View File

@@ -0,0 +1,46 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
#ifndef BOOST_LEXICAL_CAST_DETAIL_LCAST_CHAR_CONSTANTS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_LCAST_CHAR_CONSTANTS_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
namespace boost
{
namespace detail // '0', '-', '+', 'e', 'E' and '.' constants
{
template < typename Char >
struct lcast_char_constants {
// We check in tests assumption that static casted character is
// equal to correctly written C++ literal: U'0' == static_cast<char32_t>('0')
BOOST_STATIC_CONSTANT(Char, zero = static_cast<Char>('0'));
BOOST_STATIC_CONSTANT(Char, minus = static_cast<Char>('-'));
BOOST_STATIC_CONSTANT(Char, plus = static_cast<Char>('+'));
BOOST_STATIC_CONSTANT(Char, lowercase_e = static_cast<Char>('e'));
BOOST_STATIC_CONSTANT(Char, capital_e = static_cast<Char>('E'));
BOOST_STATIC_CONSTANT(Char, c_decimal_separator = static_cast<Char>('.'));
};
}
} // namespace boost
#endif // BOOST_LEXICAL_CAST_DETAIL_LCAST_CHAR_CONSTANTS_HPP

View File

@@ -0,0 +1,298 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
#ifndef BOOST_LEXICAL_CAST_DETAIL_LCAST_UNSIGNED_CONVERTERS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_LCAST_UNSIGNED_CONVERTERS_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <climits>
#include <cstddef>
#include <string>
#include <cstring>
#include <cstdio>
#include <type_traits>
#include <boost/limits.hpp>
#include <boost/config/workaround.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>
#ifndef BOOST_NO_STD_LOCALE
# include <locale>
#else
# ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
// Getting error at this point means, that your STL library is old/lame/misconfigured.
// If nothing can be done with STL library, define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE,
// but beware: lexical_cast will understand only 'C' locale delimeters and thousands
// separators.
# error "Unable to use <locale> header. Define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE to force "
# error "boost::lexical_cast to use only 'C' locale during conversions."
# endif
#endif
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
#include <boost/core/noncopyable.hpp>
namespace boost
{
namespace detail // lcast_to_unsigned
{
template<class T>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
inline
typename boost::detail::lcast::make_unsigned<T>::type lcast_to_unsigned(const T value) noexcept {
typedef typename boost::detail::lcast::make_unsigned<T>::type result_type;
return value < 0
? static_cast<result_type>(0u - static_cast<result_type>(value))
: static_cast<result_type>(value);
}
}
namespace detail // lcast_put_unsigned
{
template <class Traits, class T, class CharT>
class lcast_put_unsigned: boost::noncopyable {
typedef typename Traits::int_type int_type;
typename std::conditional<
(sizeof(unsigned) > sizeof(T))
, unsigned
, T
>::type m_value;
CharT* m_finish;
CharT const m_czero;
int_type const m_zero;
public:
lcast_put_unsigned(const T n_param, CharT* finish) noexcept
: m_value(n_param), m_finish(finish)
, m_czero(lcast_char_constants<CharT>::zero), m_zero(Traits::to_int_type(m_czero))
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
static_assert(!std::numeric_limits<T>::is_signed, "");
#endif
}
CharT* convert() {
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
std::locale loc;
if (loc == std::locale::classic()) {
return main_convert_loop();
}
typedef std::numpunct<CharT> numpunct;
numpunct const& np = BOOST_USE_FACET(numpunct, loc);
std::string const grouping = np.grouping();
std::string::size_type const grouping_size = grouping.size();
if (!grouping_size || grouping[0] <= 0) {
return main_convert_loop();
}
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
// Check that ulimited group is unreachable:
static_assert(std::numeric_limits<T>::digits10 < CHAR_MAX, "");
#endif
CharT const thousands_sep = np.thousands_sep();
std::string::size_type group = 0; // current group number
char last_grp_size = grouping[0];
char left = last_grp_size;
do {
if (left == 0) {
++group;
if (group < grouping_size) {
char const grp_size = grouping[group];
last_grp_size = (grp_size <= 0 ? static_cast<char>(CHAR_MAX) : grp_size);
}
left = last_grp_size;
--m_finish;
Traits::assign(*m_finish, thousands_sep);
}
--left;
} while (main_convert_iteration());
return m_finish;
#else
return main_convert_loop();
#endif
}
private:
inline bool main_convert_iteration() noexcept {
--m_finish;
int_type const digit = static_cast<int_type>(m_value % 10U);
Traits::assign(*m_finish, Traits::to_char_type(m_zero + digit));
m_value /= 10;
return !!m_value; // suppressing warnings
}
inline CharT* main_convert_loop() noexcept {
while (main_convert_iteration());
return m_finish;
}
};
}
namespace detail // lcast_ret_unsigned
{
template <class Traits, class T, class CharT>
class lcast_ret_unsigned: boost::noncopyable {
bool m_multiplier_overflowed;
T m_multiplier;
T& m_value;
const CharT* const m_begin;
const CharT* m_end;
public:
lcast_ret_unsigned(T& value, const CharT* const begin, const CharT* end) noexcept
: m_multiplier_overflowed(false), m_multiplier(1), m_value(value), m_begin(begin), m_end(end)
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
static_assert(!std::numeric_limits<T>::is_signed, "");
// GCC when used with flag -std=c++0x may not have std::numeric_limits
// specializations for __int128 and unsigned __int128 types.
// Try compilation with -std=gnu++0x or -std=gnu++11.
//
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40856
static_assert(std::numeric_limits<T>::is_specialized,
"std::numeric_limits are not specialized for integral type passed to boost::lexical_cast"
);
#endif
}
inline bool convert() {
CharT const czero = lcast_char_constants<CharT>::zero;
--m_end;
m_value = static_cast<T>(0);
if (m_begin > m_end || *m_end < czero || *m_end >= czero + 10)
return false;
m_value = static_cast<T>(*m_end - czero);
--m_end;
#ifdef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
return main_convert_loop();
#else
std::locale loc;
if (loc == std::locale::classic()) {
return main_convert_loop();
}
typedef std::numpunct<CharT> numpunct;
numpunct const& np = BOOST_USE_FACET(numpunct, loc);
std::string const& grouping = np.grouping();
std::string::size_type const grouping_size = grouping.size();
/* According to Programming languages - C++
* we MUST check for correct grouping
*/
if (!grouping_size || grouping[0] <= 0) {
return main_convert_loop();
}
unsigned char current_grouping = 0;
CharT const thousands_sep = np.thousands_sep();
char remained = static_cast<char>(grouping[current_grouping] - 1);
for (;m_end >= m_begin; --m_end)
{
if (remained) {
if (!main_convert_iteration()) {
return false;
}
--remained;
} else {
if ( !Traits::eq(*m_end, thousands_sep) ) //|| begin == end ) return false;
{
/*
* According to Programming languages - C++
* Digit grouping is checked. That is, the positions of discarded
* separators is examined for consistency with
* use_facet<numpunct<charT> >(loc ).grouping()
*
* BUT what if there is no separators at all and grouping()
* is not empty? Well, we have no extraced separators, so we
* won`t check them for consistency. This will allow us to
* work with "C" locale from other locales
*/
return main_convert_loop();
} else {
if (m_begin == m_end) return false;
if (current_grouping < grouping_size - 1) ++current_grouping;
remained = grouping[current_grouping];
}
}
} /*for*/
return true;
#endif
}
private:
// Iteration that does not care about grouping/separators and assumes that all
// input characters are digits
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
inline bool main_convert_iteration() noexcept {
CharT const czero = lcast_char_constants<CharT>::zero;
T const maxv = (std::numeric_limits<T>::max)();
m_multiplier_overflowed = m_multiplier_overflowed || (maxv/10 < m_multiplier);
m_multiplier = static_cast<T>(m_multiplier * 10);
T const dig_value = static_cast<T>(*m_end - czero);
T const new_sub_value = static_cast<T>(m_multiplier * dig_value);
// We must correctly handle situations like `000000000000000000000000000001`.
// So we take care of overflow only if `dig_value` is not '0'.
if (*m_end < czero || *m_end >= czero + 10 // checking for correct digit
|| (dig_value && ( // checking for overflow of ...
m_multiplier_overflowed // ... multiplier
|| static_cast<T>(maxv / dig_value) < m_multiplier // ... subvalue
|| static_cast<T>(maxv - new_sub_value) < m_value // ... whole expression
))
) return false;
m_value = static_cast<T>(m_value + new_sub_value);
return true;
}
bool main_convert_loop() noexcept {
for ( ; m_end >= m_begin; --m_end) {
if (!main_convert_iteration()) {
return false;
}
}
return true;
}
};
}
} // namespace boost
#endif // BOOST_LEXICAL_CAST_DETAIL_LCAST_UNSIGNED_CONVERTERS_HPP

View File

@@ -0,0 +1,81 @@
// Copyright Peter Dimov, 2025.
// Copyright Romain Geissler, 2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LEXICAL_CAST_DETAIL_TYPE_TRAITS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_TYPE_TRAITS_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <type_traits>
namespace boost { namespace detail { namespace lcast {
// libstdc++ from gcc <= 15 doesn't provide support for __int128 in the standard traits,
// so define them explicitly.
// This was fixed with gcc >= 16, so we may eventually remove this workaround and use
// directly the standard type_traits.
template<class T> struct is_integral: public std::is_integral<T>
{
};
template<class T> struct is_signed: public std::is_signed<T>
{
};
template<class T> struct is_unsigned: public std::is_unsigned<T>
{
};
template<class T> struct make_unsigned: public std::make_unsigned<T>
{
};
#if defined(__SIZEOF_INT128__)
template<> struct is_integral<__int128_t>: public std::true_type
{
};
template<> struct is_integral<__uint128_t>: public std::true_type
{
};
template<> struct is_signed<__int128_t>: public std::true_type
{
};
template<> struct is_signed<__uint128_t>: public std::false_type
{
};
template<> struct is_unsigned<__int128_t>: public std::false_type
{
};
template<> struct is_unsigned<__uint128_t>: public std::true_type
{
};
template<> struct make_unsigned<__int128_t>
{
typedef __uint128_t type;
};
template<> struct make_unsigned<__uint128_t>
{
typedef __uint128_t type;
};
#endif
}}} // namespace boost::detail::lcast
#endif // BOOST_LEXICAL_CAST_DETAIL_TYPE_TRAITS_HPP

View File

@@ -0,0 +1,41 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// what: lexical_cast custom keyword cast
// who: contributed by Kevlin Henney,
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
#ifndef BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
#define BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
#include <type_traits>
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
namespace boost { namespace detail {
template <typename TargetChar, typename SourceChar>
using widest_char = std::conditional<
(sizeof(TargetChar) > sizeof(SourceChar))
, TargetChar
, SourceChar
>;
}} // namespace boost::detail
#endif // BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP