update boost on linux
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <boost/convert/parameters.hpp>
|
||||
#include <boost/convert/detail/is_string.hpp>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost { namespace cnv
|
||||
@@ -79,26 +78,26 @@ struct boost::cnv::cnvbase
|
||||
BOOST_CNV_STRING_TO (string_type const& s, optional< dbl_type>& r) const { str_to_(s, r); }
|
||||
BOOST_CNV_STRING_TO (string_type const& s, optional< ldbl_type>& r) const { str_to_(s, r); }
|
||||
// Formatters
|
||||
// BOOST_CNV_PARAM (locale, std::locale const) { locale_ = arg[ARG:: locale]; return dncast(); }
|
||||
BOOST_CNV_PARAM (base, base::type const) { base_ = arg[ARG:: base]; return dncast(); }
|
||||
BOOST_CNV_PARAM (adjust, adjust::type const) { adjust_ = arg[ARG:: adjust]; return dncast(); }
|
||||
BOOST_CNV_PARAM (precision, int const) { precision_ = arg[ARG::precision]; return dncast(); }
|
||||
BOOST_CNV_PARAM (precision, int) { precision_ = arg[ARG::precision]; return dncast(); }
|
||||
BOOST_CNV_PARAM (uppercase, bool const) { uppercase_ = arg[ARG::uppercase]; return dncast(); }
|
||||
BOOST_CNV_PARAM (skipws, bool const) { skipws_ = arg[ARG:: skipws]; return dncast(); }
|
||||
BOOST_CNV_PARAM (width, int const) { width_ = arg[ARG:: width]; return dncast(); }
|
||||
BOOST_CNV_PARAM (fill, char const) { fill_ = arg[ARG:: fill]; return dncast(); }
|
||||
// BOOST_CNV_PARAM (locale, std::locale const) { locale_ = arg[ARG:: locale]; return dncast(); }
|
||||
BOOST_CNV_PARAM (base, cnv::base const) { base_ = arg[ARG:: base]; return dncast(); }
|
||||
BOOST_CNV_PARAM (adjust, cnv::adjust const) { adjust_ = arg[ARG:: adjust]; return dncast(); }
|
||||
BOOST_CNV_PARAM (precision, int const) { precision_ = arg[ARG::precision]; return dncast(); }
|
||||
BOOST_CNV_PARAM (precision, int) { precision_ = arg[ARG::precision]; return dncast(); }
|
||||
BOOST_CNV_PARAM (uppercase, bool const) { uppercase_ = arg[ARG::uppercase]; return dncast(); }
|
||||
BOOST_CNV_PARAM (skipws, bool const) { skipws_ = arg[ARG:: skipws]; return dncast(); }
|
||||
BOOST_CNV_PARAM (width, int const) { width_ = arg[ARG:: width]; return dncast(); }
|
||||
BOOST_CNV_PARAM (fill, char const) { fill_ = arg[ARG:: fill]; return dncast(); }
|
||||
|
||||
protected:
|
||||
|
||||
cnvbase()
|
||||
:
|
||||
base_ (10),
|
||||
skipws_ (false),
|
||||
precision_ (0),
|
||||
uppercase_ (false),
|
||||
width_ (0),
|
||||
fill_ (' '),
|
||||
base_ (boost::cnv::base::dec),
|
||||
adjust_ (boost::cnv::adjust::right)
|
||||
{}
|
||||
|
||||
@@ -106,19 +105,13 @@ struct boost::cnv::cnvbase
|
||||
void
|
||||
str_to_(string_type const& str, optional<out_type>& result_out) const
|
||||
{
|
||||
using range_type = cnv::range<string_type const>;
|
||||
using char_type = typename range_type::value_type;
|
||||
cnv::range<string_type const> range (str);
|
||||
|
||||
range_type range (str);
|
||||
auto is_space = [](char_type ch)
|
||||
{
|
||||
return std::isspace(static_cast<unsigned char>(ch));
|
||||
};
|
||||
if (skipws_)
|
||||
for (; !range.empty() && is_space(*range.begin()); ++range);
|
||||
for (; !range.empty() && cnv::is_space(*range.begin()); ++range);
|
||||
|
||||
if (range.empty()) return;
|
||||
if (is_space(*range.begin())) return;
|
||||
if (range.empty()) return;
|
||||
if (cnv::is_space(*range.begin())) return;
|
||||
|
||||
dncast().str_to(range, result_out);
|
||||
}
|
||||
@@ -126,35 +119,31 @@ struct boost::cnv::cnvbase
|
||||
void
|
||||
to_str_(in_type value_in, optional<string_type>& result_out) const
|
||||
{
|
||||
using range_type = cnv::range<string_type>;
|
||||
using char_type = typename range_type::value_type;
|
||||
using char_type = typename cnv::range<string_type>::value_type;
|
||||
using range_type = cnv::range<char_type*>;
|
||||
using buf_type = char_type[bufsize_];
|
||||
|
||||
char_type buf[bufsize_];
|
||||
cnv::range<char_type*> range = dncast().to_str(value_in, buf);
|
||||
char_type* beg = range.begin();
|
||||
char_type* end = range.end();
|
||||
buf_type buf;
|
||||
range_type range = dncast().to_str(value_in, buf);
|
||||
char_type* beg = range.begin();
|
||||
char_type* end = range.end();
|
||||
int str_size = end - beg;
|
||||
|
||||
if (beg < end)
|
||||
format_(buf, beg, end), result_out = string_type(beg, end);
|
||||
}
|
||||
if (str_size <= 0)
|
||||
return;
|
||||
|
||||
template<typename char_type>
|
||||
void
|
||||
format_(char_type* buf, char_type*& beg, char_type*& end) const
|
||||
{
|
||||
if (uppercase_)
|
||||
for (char_type* p = beg; p < end; ++p) *p = std::toupper(*p);
|
||||
for (char_type* p = beg; p < end; ++p) *p = cnv::to_upper(*p);
|
||||
|
||||
if (width_)
|
||||
{
|
||||
int num_fillers = (std::max)(0, int(width_ - (end - beg)));
|
||||
int num_left = adjust_ == boost::cnv::adjust::left ? 0
|
||||
: adjust_ == boost::cnv::adjust::right ? num_fillers
|
||||
: (num_fillers / 2);
|
||||
int num_right = num_fillers - num_left;
|
||||
int str_size = end - beg;
|
||||
bool move = (beg < buf + num_left) // No room for left fillers
|
||||
|| (buf + bufsize_ < end + num_right); // No room for right fillers
|
||||
int num_fill = (std::max)(0, int(width_ - (end - beg)));
|
||||
int num_left = adjust_ == cnv::adjust::left ? 0
|
||||
: adjust_ == cnv::adjust::right ? num_fill
|
||||
: (num_fill / 2);
|
||||
int num_right = num_fill - num_left;
|
||||
bool move = (beg < buf + num_left) // No room for left fillers
|
||||
|| (buf + bufsize_ < end + num_right); // No room for right fillers
|
||||
if (move)
|
||||
{
|
||||
std::memmove(buf + num_left, beg, str_size * sizeof(char_type));
|
||||
@@ -164,6 +153,7 @@ struct boost::cnv::cnvbase
|
||||
for (int k = 0; k < num_left; *(--beg) = fill_, ++k);
|
||||
for (int k = 0; k < num_right; *(end++) = fill_, ++k);
|
||||
}
|
||||
result_out = string_type(beg, end);
|
||||
}
|
||||
|
||||
derived_type const& dncast () const { return *static_cast<derived_type const*>(this); }
|
||||
@@ -172,13 +162,13 @@ struct boost::cnv::cnvbase
|
||||
// ULONG_MAX(8 bytes) = 18446744073709551615 (20(10) or 32(2) characters)
|
||||
// double (8 bytes) max is 316 chars
|
||||
static int const bufsize_ = 512;
|
||||
int base_;
|
||||
bool skipws_;
|
||||
int precision_;
|
||||
bool uppercase_;
|
||||
int width_;
|
||||
int fill_;
|
||||
adjust::type adjust_;
|
||||
cnv::base base_;
|
||||
cnv::adjust adjust_;
|
||||
// std::locale locale_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
// Copyright (c) 2009-2016 Vladimir Batov.
|
||||
// Use, modification and distribution are subject to the Boost Software License,
|
||||
// Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
|
||||
|
||||
#ifndef BOOST_PARAMETER_EXT_PRIVATE_HPP
|
||||
#define BOOST_PARAMETER_EXT_PRIVATE_HPP
|
||||
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
|
||||
// A Boost.Parameter extension by Andrey Semashev.
|
||||
// This should really go to Boost.Parameter in the end.
|
||||
|
||||
namespace boost { namespace parameter {
|
||||
|
||||
// The metafunction, given the type of the arguments pack and the keyword tag,
|
||||
// returns the corresponding parameter type
|
||||
template< typename ArgsT, typename KeywordTagT >
|
||||
struct parameter_type
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template< typename ArgT, typename KeywordTagT >
|
||||
struct parameter_type<aux::tagged_argument<KeywordTagT, ArgT>, KeywordTagT>
|
||||
{
|
||||
typedef typename aux::tagged_argument< KeywordTagT, ArgT >::value_type type;
|
||||
};
|
||||
|
||||
template< typename KeywordTagT1, typename ArgT, typename KeywordTagT2 >
|
||||
struct parameter_type< aux::tagged_argument< KeywordTagT1, ArgT >, KeywordTagT2 >
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template< typename ArgT, typename TailT, typename KeywordTagT >
|
||||
struct parameter_type<
|
||||
aux::arg_list<
|
||||
aux::tagged_argument< KeywordTagT, ArgT >,
|
||||
TailT
|
||||
>,
|
||||
KeywordTagT
|
||||
>
|
||||
{
|
||||
typedef typename aux::tagged_argument< KeywordTagT, ArgT >::value_type type;
|
||||
};
|
||||
|
||||
template< typename KeywordTagT1, typename ArgT, typename TailT, typename KeywordTagT2 >
|
||||
struct parameter_type<
|
||||
aux::arg_list<
|
||||
aux::tagged_argument< KeywordTagT1, ArgT >,
|
||||
TailT
|
||||
>,
|
||||
KeywordTagT2
|
||||
> :
|
||||
public parameter_type< TailT, KeywordTagT2 >
|
||||
{
|
||||
};
|
||||
|
||||
}} // boost::parameter
|
||||
|
||||
#endif // BOOST_PARAMETER_EXT_PRIVATE_HPP
|
||||
|
||||
@@ -5,18 +5,34 @@
|
||||
#ifndef BOOST_CONVERT_DETAIL_IS_CHAR_HPP
|
||||
#define BOOST_CONVERT_DETAIL_IS_CHAR_HPP
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/convert/detail/config.hpp>
|
||||
#include <type_traits>
|
||||
#include <cctype>
|
||||
#include <cwctype>
|
||||
|
||||
namespace boost { namespace cnv
|
||||
{
|
||||
using char_type = char;
|
||||
using uchar_type = unsigned char;
|
||||
using wchar_type = wchar_t;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename T> struct is_char : mpl::false_ {};
|
||||
template<> struct is_char<char> : mpl:: true_ {};
|
||||
template<> struct is_char<wchar_t> : mpl:: true_ {};
|
||||
template<typename> struct is_char : std::false_type {};
|
||||
template<> struct is_char< char_type> : std:: true_type {};
|
||||
template<> struct is_char<wchar_type> : std:: true_type {};
|
||||
}
|
||||
template <typename T> struct is_char : detail::is_char<typename remove_const<T>::type> {};
|
||||
template <typename T> struct is_char : detail::is_char<typename boost::remove_const<T>::type> {};
|
||||
|
||||
template<typename char_type> inline bool is_space(char_type);
|
||||
template<typename char_type> inline char_type to_upper(char_type);
|
||||
|
||||
template<> inline bool is_space ( char_type c) { return bool(std::isspace(static_cast<uchar_type>(c))); }
|
||||
template<> inline bool is_space (uchar_type c) { return bool(std::isspace(c)); }
|
||||
template<> inline bool is_space (wchar_type c) { return bool(std::iswspace(c)); }
|
||||
template<> inline char_type to_upper ( char_type c) { return std::toupper(static_cast<uchar_type>(c)); }
|
||||
template<> inline uchar_type to_upper (uchar_type c) { return std::toupper(c); }
|
||||
template<> inline wchar_type to_upper (wchar_type c) { return std::towupper(c); }
|
||||
}}
|
||||
|
||||
#endif // BOOST_CONVERT_DETAIL_IS_CHAR_HPP
|
||||
|
||||
@@ -5,7 +5,33 @@
|
||||
#ifndef BOOST_CONVERT_FORWARD_HPP
|
||||
#define BOOST_CONVERT_FORWARD_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#undef BOOST_CONVERT_CXX11
|
||||
#else
|
||||
#define BOOST_CONVERT_CXX11
|
||||
#endif
|
||||
|
||||
// Intel 12.0 and lower have broken SFINAE
|
||||
#if defined(BOOST_INTEL) && (BOOST_INTEL <= 1200)
|
||||
# define BOOST_CONVERT_IS_NOT_SUPPORTED
|
||||
#endif
|
||||
|
||||
// No C++11 support
|
||||
#if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION <= 40600)
|
||||
# define BOOST_CONVERT_IS_NOT_SUPPORTED
|
||||
#endif
|
||||
|
||||
// MSVC-11 and lower have broken SFINAE
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1800)
|
||||
# define BOOST_CONVERT_IS_NOT_SUPPORTED
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
//MSVC++ 7.0 _MSC_VER == 1300
|
||||
//MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio 2003)
|
||||
//MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005)
|
||||
@@ -29,23 +55,4 @@
|
||||
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#undef BOOST_CONVERT_CXX11
|
||||
#else
|
||||
#define BOOST_CONVERT_CXX11
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_INTEL) && (BOOST_INTEL <= 1200) /* Intel 12.0 and lower have broken SFINAE */
|
||||
#error "Boost.Convert is not supported on this platform due to broken SFINAE."
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1800) /* MSVC-11 and lower have broken SFINAE */
|
||||
//# error "Boost.Convert is not supported on this platform due to broken SFINAE."
|
||||
# define BOOST_CONVERT_MSVC_SFINAE_BROKEN
|
||||
#endif
|
||||
|
||||
#endif // BOOST_CONVERT_FORWARD_HPP
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef BOOST_CONVERT_HAS_MEMBER_HPP
|
||||
#define BOOST_CONVERT_HAS_MEMBER_HPP
|
||||
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/detail/yes_no_type.hpp>
|
||||
|
||||
// This macro allows to check if a type has a member named "__member_name__"...
|
||||
@@ -41,7 +40,7 @@
|
||||
template <typename __boost_has_member_T__> /*C4*/ \
|
||||
class __trait_name__ \
|
||||
{ \
|
||||
typedef typename ::boost::remove_const<__boost_has_member_T__>::type check_type; \
|
||||
typedef typename boost::remove_const<__boost_has_member_T__>::type check_type; \
|
||||
typedef ::boost::type_traits::yes_type yes_type; \
|
||||
typedef ::boost::type_traits:: no_type no_type; \
|
||||
\
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef BOOST_CONVERT_IS_CONVERTER_HPP
|
||||
#define BOOST_CONVERT_IS_CONVERTER_HPP
|
||||
|
||||
#include <boost/convert/detail/forward.hpp>
|
||||
#include <boost/convert/detail/config.hpp>
|
||||
#include <boost/convert/detail/is_callable.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef BOOST_CONVERT_IS_FUNCTION_HPP
|
||||
#define BOOST_CONVERT_IS_FUNCTION_HPP
|
||||
|
||||
#include <boost/convert/detail/forward.hpp>
|
||||
#include <boost/convert/detail/config.hpp>
|
||||
#include <boost/convert/detail/has_member.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace boost { namespace cnv
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename T, bool is_range_class> struct is_string : mpl::false_ {};
|
||||
template<typename T, bool is_range_class> struct is_string : std::false_type {};
|
||||
|
||||
template<typename T> struct is_string<T*, false>
|
||||
{
|
||||
@@ -27,7 +27,7 @@ namespace boost { namespace cnv
|
||||
};
|
||||
}
|
||||
template<typename T> struct is_string : detail::is_string<
|
||||
typename remove_const<T>::type,
|
||||
typename boost::remove_const<T>::type,
|
||||
boost::is_class<T>::value && boost::cnv::is_range<T>::value> {};
|
||||
}}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace boost { namespace cnv
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename T, bool is_class> struct is_range : mpl::false_ {};
|
||||
template<typename T, bool is_class> struct is_range : std::false_type {};
|
||||
|
||||
template<typename T> struct is_range<T, /*is_class=*/true>
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace boost { namespace cnv
|
||||
static bool const value = has_begin<T>::value && has_end<T>::value;
|
||||
};
|
||||
}
|
||||
template<typename T> struct is_range : detail::is_range<typename remove_const<T>::type, boost::is_class<T>::value> {};
|
||||
template<typename T> struct is_range : detail::is_range<typename boost::remove_const<T>::type, boost::is_class<T>::value> {};
|
||||
template<typename T, typename enable =void> struct range;
|
||||
template<typename T, typename enable =void> struct iterator;
|
||||
|
||||
@@ -38,9 +38,9 @@ namespace boost { namespace cnv
|
||||
template<typename T>
|
||||
struct iterator<T*, void>
|
||||
{
|
||||
typedef typename remove_const<T>::type value_type;
|
||||
typedef T* type;
|
||||
typedef value_type const* const_type;
|
||||
typedef typename boost::remove_const<T>::type value_type;
|
||||
typedef T* type;
|
||||
typedef value_type const* const_type;
|
||||
};
|
||||
template<typename T>
|
||||
struct range_base
|
||||
@@ -74,20 +74,21 @@ namespace boost { namespace cnv
|
||||
|
||||
range (T& r) : base_type(r.begin(), r.end()) {}
|
||||
|
||||
iterator end () { return base_type::end_; }
|
||||
const_iterator end () const { return base_type::end_; }
|
||||
sentry_type sentry () const { return base_type::end_; }
|
||||
bool empty () const { return base_type::begin_ == base_type::end_; }
|
||||
iterator end () { return base_type::end_; }
|
||||
const_iterator end () const { return base_type::end_; }
|
||||
sentry_type sentry () const { return base_type::end_; }
|
||||
std::size_t size () const { return base_type::end_ - base_type::begin_; }
|
||||
bool empty () const { return base_type::begin_ == base_type::end_; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct range<T*, typename enable_if<cnv::is_char<T> >::type> : public range_base<T*>
|
||||
{
|
||||
typedef range this_type;
|
||||
typedef range_base<T*> base_type;
|
||||
typedef typename remove_const<T>::type value_type;
|
||||
typedef T* iterator;
|
||||
typedef value_type const* const_iterator;
|
||||
using this_type = range;
|
||||
using base_type = range_base<T*>;
|
||||
using value_type = typename boost::remove_const<T>::type;
|
||||
using iterator = T*;
|
||||
using const_iterator = value_type const*;
|
||||
|
||||
struct sentry_type
|
||||
{
|
||||
|
||||
@@ -5,29 +5,26 @@
|
||||
#ifndef BOOST_CONVERT_PARAMETERS_HPP
|
||||
#define BOOST_CONVERT_PARAMETERS_HPP
|
||||
|
||||
#include <boost/convert/detail/boost_parameter_ext.hpp>
|
||||
#include <boost/parameter/name.hpp>
|
||||
|
||||
namespace boost
|
||||
namespace boost { namespace cnv
|
||||
{
|
||||
namespace cnv
|
||||
{
|
||||
struct adjust { enum type { left, right, center };};
|
||||
struct base { enum type { bin =2, dec =10, hex =16, oct =8 };};
|
||||
struct notation { enum type { fixed, scientific };};
|
||||
enum class adjust { left, right, center };
|
||||
enum class base { bin =2, oct =8, dec =10, hex =16 };
|
||||
enum class notation { fixed, scientific };
|
||||
|
||||
namespace parameter
|
||||
{
|
||||
BOOST_PARAMETER_KEYWORD(type, adjust)
|
||||
BOOST_PARAMETER_KEYWORD(type, base)
|
||||
BOOST_PARAMETER_KEYWORD(type, fill)
|
||||
BOOST_PARAMETER_KEYWORD(type, locale)
|
||||
BOOST_PARAMETER_KEYWORD(type, notation)
|
||||
BOOST_PARAMETER_KEYWORD(type, precision)
|
||||
BOOST_PARAMETER_KEYWORD(type, skipws)
|
||||
BOOST_PARAMETER_KEYWORD(type, uppercase)
|
||||
BOOST_PARAMETER_KEYWORD(type, width)
|
||||
}
|
||||
namespace parameter
|
||||
{
|
||||
BOOST_PARAMETER_NAME(( adjust, type) adjust)
|
||||
BOOST_PARAMETER_NAME(( base, type) base)
|
||||
BOOST_PARAMETER_NAME(( fill, type) fill)
|
||||
BOOST_PARAMETER_NAME(( locale, type) locale)
|
||||
BOOST_PARAMETER_NAME(( notation, type) notation)
|
||||
BOOST_PARAMETER_NAME((precision, type) precision)
|
||||
BOOST_PARAMETER_NAME(( skipws, type) skipws)
|
||||
BOOST_PARAMETER_NAME((uppercase, type) uppercase)
|
||||
BOOST_PARAMETER_NAME(( width, type) width)
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
#endif // BOOST_CONVERT_PARAMETERS_HPP
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace boost { namespace cnv
|
||||
struct printf;
|
||||
}}
|
||||
|
||||
struct boost::cnv::printf : public boost::cnv::cnvbase<boost::cnv::printf>
|
||||
struct boost::cnv::printf : boost::cnv::cnvbase<boost::cnv::printf>
|
||||
{
|
||||
typedef boost::cnv::printf this_type;
|
||||
typedef boost::cnv::cnvbase<this_type> base_type;
|
||||
using this_type = boost::cnv::printf;
|
||||
using base_type = boost::cnv::cnvbase<this_type>;
|
||||
|
||||
using base_type::operator();
|
||||
|
||||
@@ -50,39 +50,37 @@ struct boost::cnv::printf : public boost::cnv::cnvbase<boost::cnv::printf>
|
||||
|
||||
template<typename Type> int pos() const
|
||||
{
|
||||
typedef boost::mpl::vector<double, float,
|
||||
int, unsigned int,
|
||||
short int, unsigned short int,
|
||||
long int, unsigned long int
|
||||
> managed_types;
|
||||
|
||||
typedef typename boost::mpl::find<managed_types, Type>::type type_iterator;
|
||||
typedef typename type_iterator::pos type_pos;
|
||||
using managed_types = boost::mpl::vector<double, float,
|
||||
int, unsigned int,
|
||||
short int, unsigned short int,
|
||||
long int, unsigned long int>;
|
||||
using type_iterator = typename boost::mpl::find<managed_types, Type>::type;
|
||||
using type_pos = typename type_iterator::pos;
|
||||
|
||||
return type_pos::value;
|
||||
}
|
||||
|
||||
char const* pformat(int pos) const
|
||||
{
|
||||
static char const* d_format[] = { "%.*f", "%.*f", "%.*d", "%.*u", "%.*hd", "%.*hu", "%.*ld", "%.*lu" }; // Must match managed_types
|
||||
static char const* x_format[] = { "%.*f", "%.*f", "%.*x", "%.*x", "%.*hx", "%.*hx", "%.*lx", "%.*lx" }; // Must match managed_types
|
||||
static char const* o_format[] = { "%.*f", "%.*f", "%.*o", "%.*o", "%.*ho", "%.*ho", "%.*lo", "%.*lo" }; // Must match managed_types
|
||||
char const* format = base_ == 10 ? d_format[pos]
|
||||
: base_ == 16 ? x_format[pos]
|
||||
: base_ == 8 ? o_format[pos]
|
||||
: (BOOST_ASSERT(0), (char const*) 0);
|
||||
return format;
|
||||
static char const* d_fmt[] = { "%.*f", "%.*f", "%.*d", "%.*u", "%.*hd", "%.*hu", "%.*ld", "%.*lu" }; // Must match managed_types
|
||||
static char const* x_fmt[] = { "%.*f", "%.*f", "%.*x", "%.*x", "%.*hx", "%.*hx", "%.*lx", "%.*lx" }; // Must match managed_types
|
||||
static char const* o_fmt[] = { "%.*f", "%.*f", "%.*o", "%.*o", "%.*ho", "%.*ho", "%.*lo", "%.*lo" }; // Must match managed_types
|
||||
char const* fmt = base_ == boost::cnv::base::dec ? d_fmt[pos]
|
||||
: base_ == boost::cnv::base::hex ? x_fmt[pos]
|
||||
: base_ == boost::cnv::base::oct ? o_fmt[pos]
|
||||
: (BOOST_ASSERT(0), nullptr);
|
||||
return fmt;
|
||||
}
|
||||
char const* format(int pos) const
|
||||
{
|
||||
static char const* d_format[] = { "%f", "%f", "%d", "%u", "%hd", "%hu", "%ld", "%lu" }; // Must match managed_types
|
||||
static char const* x_format[] = { "%f", "%f", "%x", "%x", "%hx", "%hx", "%lx", "%lx" }; // Must match managed_types
|
||||
static char const* o_format[] = { "%f", "%f", "%o", "%o", "%ho", "%ho", "%lo", "%lo" }; // Must match managed_types
|
||||
char const* format = base_ == 10 ? d_format[pos]
|
||||
: base_ == 16 ? x_format[pos]
|
||||
: base_ == 8 ? o_format[pos]
|
||||
: (BOOST_ASSERT(0), (char const*) 0);
|
||||
return format;
|
||||
static char const* d_fmt[] = { "%f", "%f", "%d", "%u", "%hd", "%hu", "%ld", "%lu" }; // Must match managed_types
|
||||
static char const* x_fmt[] = { "%f", "%f", "%x", "%x", "%hx", "%hx", "%lx", "%lx" }; // Must match managed_types
|
||||
static char const* o_fmt[] = { "%f", "%f", "%o", "%o", "%ho", "%ho", "%lo", "%lo" }; // Must match managed_types
|
||||
char const* fmt = base_ == boost::cnv::base::dec ? d_fmt[pos]
|
||||
: base_ == boost::cnv::base::hex ? x_fmt[pos]
|
||||
: base_ == boost::cnv::base::oct ? o_fmt[pos]
|
||||
: (BOOST_ASSERT(0), nullptr);
|
||||
return fmt;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define BOOST_CONVERT_SPIRIT_BASED_CONVERTER_HPP
|
||||
|
||||
#include <boost/convert/base.hpp>
|
||||
#include <boost/convert/detail/forward.hpp>
|
||||
#include <boost/convert/detail/config.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <boost/convert/parameters.hpp>
|
||||
#include <boost/convert/detail/is_string.hpp>
|
||||
#include <boost/make_default.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
@@ -24,8 +25,8 @@ namespace boost { namespace cnv
|
||||
{
|
||||
template<class Char> struct basic_stream;
|
||||
|
||||
typedef boost::cnv::basic_stream<char> cstream;
|
||||
typedef boost::cnv::basic_stream<wchar_t> wstream;
|
||||
using cstream = boost::cnv::basic_stream<char>;
|
||||
using wstream = boost::cnv::basic_stream<wchar_t>;
|
||||
}}
|
||||
|
||||
template<class Char>
|
||||
@@ -41,15 +42,15 @@ struct boost::cnv::basic_stream : boost::noncopyable
|
||||
// to "bool" with std::boolalpha set. Seems that istream state gets unsynced compared
|
||||
// to the actual underlying buffer.
|
||||
|
||||
typedef Char char_type;
|
||||
typedef boost::cnv::basic_stream<char_type> this_type;
|
||||
typedef std::basic_stringstream<char_type> stream_type;
|
||||
typedef std::basic_istream<char_type> istream_type;
|
||||
typedef std::basic_streambuf<char_type> buffer_type;
|
||||
typedef std::basic_string<char_type> stdstr_type;
|
||||
typedef std::ios_base& (*manipulator_type)(std::ios_base&);
|
||||
using char_type = Char;
|
||||
using this_type = boost::cnv::basic_stream<char_type>;
|
||||
using stream_type = std::basic_stringstream<char_type>;
|
||||
using istream_type = std::basic_istream<char_type>;
|
||||
using buffer_type = std::basic_streambuf<char_type>;
|
||||
using stdstr_type = std::basic_string<char_type>;
|
||||
using manipulator_type = std::ios_base& (*)(std::ios_base&);
|
||||
|
||||
struct ibuffer_type : public buffer_type
|
||||
struct ibuffer_type : buffer_type
|
||||
{
|
||||
using buffer_type::eback;
|
||||
using buffer_type::gptr;
|
||||
@@ -62,7 +63,7 @@ struct boost::cnv::basic_stream : boost::noncopyable
|
||||
buffer_type::setg(b, b, b + sz);
|
||||
}
|
||||
};
|
||||
struct obuffer_type : public buffer_type
|
||||
struct obuffer_type : buffer_type
|
||||
{
|
||||
using buffer_type::pbase;
|
||||
using buffer_type::pptr;
|
||||
@@ -103,9 +104,9 @@ struct boost::cnv::basic_stream : boost::noncopyable
|
||||
skipws ? (void) stream_.setf(std::ios::skipws) : stream_.unsetf(std::ios::skipws);
|
||||
return *this;
|
||||
}
|
||||
BOOST_CNV_PARAM(adjust, boost::cnv::adjust::type const)
|
||||
BOOST_CNV_PARAM(adjust, boost::cnv::adjust const)
|
||||
{
|
||||
cnv::adjust::type adjust = arg[cnv::parameter::adjust];
|
||||
cnv::adjust adjust = arg[cnv::parameter::adjust];
|
||||
|
||||
/**/ if (adjust == cnv::adjust:: left) stream_.setf(std::ios::adjustfield, std::ios:: left);
|
||||
else if (adjust == cnv::adjust::right) stream_.setf(std::ios::adjustfield, std::ios::right);
|
||||
@@ -113,25 +114,25 @@ struct boost::cnv::basic_stream : boost::noncopyable
|
||||
|
||||
return *this;
|
||||
}
|
||||
BOOST_CNV_PARAM(base, boost::cnv::base::type const)
|
||||
BOOST_CNV_PARAM(base, boost::cnv::base const)
|
||||
{
|
||||
cnv::base::type base = arg[cnv::parameter::base];
|
||||
|
||||
cnv::base base = arg[cnv::parameter::base];
|
||||
|
||||
/**/ if (base == cnv::base::dec) std::dec(stream_);
|
||||
else if (base == cnv::base::hex) std::hex(stream_);
|
||||
else if (base == cnv::base::oct) std::oct(stream_);
|
||||
else BOOST_ASSERT(!"Not implemented");
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
BOOST_CNV_PARAM(notation, boost::cnv::notation::type const)
|
||||
BOOST_CNV_PARAM(notation, boost::cnv::notation const)
|
||||
{
|
||||
cnv::notation::type notation = arg[cnv::parameter::notation];
|
||||
|
||||
cnv::notation notation = arg[cnv::parameter::notation];
|
||||
|
||||
/**/ if (notation == cnv::notation:: fixed) std::fixed(stream_);
|
||||
else if (notation == cnv::notation::scientific) std::scientific(stream_);
|
||||
else BOOST_ASSERT(!"Not implemented");
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,16 +76,17 @@ boost::cnv::strtol::i_to_str(Type in_value, char_type* buf) const
|
||||
|
||||
typedef typename boost::make_unsigned<Type>::type unsigned_type;
|
||||
|
||||
char_type* beg = buf + bufsize_ / 2;
|
||||
char_type* end = beg;
|
||||
bool const is_negative = in_value < 0;
|
||||
unsigned_type value = static_cast<unsigned_type>(is_negative ? -in_value : in_value);
|
||||
char_type* beg = buf + bufsize_ / 2;
|
||||
char_type* end = beg;
|
||||
bool const is_neg = std::is_signed<Type>::value && in_value < 0;
|
||||
unsigned_type value = static_cast<unsigned_type>(is_neg ? -in_value : in_value);
|
||||
int base = int(base_);
|
||||
|
||||
if (base_ == 10) for (; value; *(--beg) = int(value % 10) + '0', value /= 10); //C1
|
||||
else for (; value; *(--beg) = get_char(value % base_), value /= base_);
|
||||
if (base == 10) for (; value; *(--beg) = int(value % 10) + '0', value /= 10); //C1
|
||||
else for (; value; *(--beg) = get_char(value % base), value /= base);
|
||||
|
||||
if (beg == end) *(--beg) = '0';
|
||||
if (is_negative) *(--beg) = '-';
|
||||
if (beg == end) *(--beg) = '0';
|
||||
if (is_neg) *(--beg) = '-';
|
||||
|
||||
return cnv::range<char_type*>(beg, end);
|
||||
}
|
||||
@@ -165,7 +166,7 @@ boost::cnv::strtol::str_to_i(cnv::range<string_type> range, boost::optional<out_
|
||||
unsigned int ch = *s;
|
||||
bool const is_negative = ch == '-' ? (ch = *++s, true) : ch == '+' ? (ch = *++s, false) : false;
|
||||
bool const is_unsigned = boost::is_same<out_type, unsigned_type>::value;
|
||||
unsigned int base = base_;
|
||||
int base = int(base_);
|
||||
|
||||
/**/ if (is_negative && is_unsigned) return;
|
||||
else if ((base == 0 || base == 16) && ch == '0' && (*++s == 'x' || *s == 'X')) ++s, base = 16;
|
||||
@@ -197,20 +198,20 @@ template<typename string_type, typename out_type>
|
||||
void
|
||||
boost::cnv::strtol::str_to_d(cnv::range<string_type> range, optional<out_type>& result_out) const
|
||||
{
|
||||
// C2. Simply check if the end-of-string was reached -- *cnv_end == 0
|
||||
// instead of traversing once with strlen() to find the end iterator
|
||||
// and then comparing to it as in
|
||||
// char const* end = str + strlen(str); // Unnecessary traversal!
|
||||
// bool const good = ... && cnv_end == end;
|
||||
// C1. Because of strtold() currently only works with 'char'
|
||||
// C2. strtold() does not work with ranges.
|
||||
// Consequently, we have to copy the supplied range into a string for strtold().
|
||||
// C3. Check if the end-of-string was reached -- *cnv_end == 0.
|
||||
|
||||
typedef cnv::range<string_type> range_type;
|
||||
typedef typename range_type::value_type ch_type;
|
||||
|
||||
ch_type const* str = &*range.begin(); // Currently only works with 'char'
|
||||
char* cnv_end = 0;
|
||||
ldbl_type result = strtold(str, &cnv_end);
|
||||
bool good = result != -HUGE_VALL && result != HUGE_VALL && *cnv_end == 0/*C2*/;
|
||||
out_type max = (std::numeric_limits<out_type>::max)();
|
||||
size_t const sz = 128;
|
||||
ch_type str[sz] = {0}; std::strncpy(str, &*range.begin(), (std::min)(sz - 1, range.size()));
|
||||
char* cnv_end = 0;
|
||||
ldbl_type result = strtold(str, &cnv_end);
|
||||
bool good = result != -HUGE_VALL && result != HUGE_VALL && *cnv_end == 0; //C3
|
||||
out_type max = (std::numeric_limits<out_type>::max)();
|
||||
|
||||
if (good && -max <= result && result <= max)
|
||||
result_out = out_type(result);
|
||||
|
||||
Reference in New Issue
Block a user