-// Copyright (c) 2009-2016 Vladimir Batov.
+// Copyright (c) 2009-2020 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_CONVERT_CONVERTER_BASE_HPP
-#define BOOST_CONVERT_CONVERTER_BASE_HPP
+#ifndef BOOST_CONVERT_BASE_HPP
+#define BOOST_CONVERT_BASE_HPP
#include <boost/convert/parameters.hpp>
#include <boost/convert/detail/is_string.hpp>
+#include <algorithm>
#include <cstring>
namespace boost { namespace cnv
{
- namespace ARG = boost::cnv::parameter;
-
template<typename> struct cnvbase;
}}
-#define BOOST_CNV_TO_STRING \
- template<typename string_type> \
- typename boost::enable_if<cnv::is_string<string_type>, void>::type \
+#define BOOST_CNV_TO_STRING \
+ template<typename string_type> \
+ typename std::enable_if<cnv::is_string<string_type>::value, void>::type \
operator()
-#define BOOST_CNV_STRING_TO \
- template<typename string_type> \
- typename boost::enable_if<cnv::is_string<string_type>, void>::type \
+#define BOOST_CNV_STRING_TO \
+ template<typename string_type> \
+ typename std::enable_if<cnv::is_string<string_type>::value, void>::type \
operator()
-#define BOOST_CNV_PARAM(param_name, param_type) \
- derived_type& operator()(boost::parameter::aux::tag<ARG::type::param_name, param_type const>::type const& arg)
+#define BOOST_CNV_PARAM_SET(param_name) \
+ template <typename argument_pack> \
+ void set_( \
+ argument_pack const& arg, \
+ cnv::parameter::type::param_name, \
+ mpl::true_)
+
+#define BOOST_CNV_PARAM_TRY(param_name) \
+ this->set_( \
+ arg, \
+ cnv::parameter::type::param_name(), \
+ typename mpl::has_key< \
+ argument_pack, cnv::parameter::type::param_name>::type());
template<typename derived_type>
struct boost::cnv::cnvbase
BOOST_CNV_STRING_TO (string_type const& s, optional< flt_type>& r) const { str_to_(s, r); }
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) { locale_ = arg[ARG:: locale]; return dncast(); }
- BOOST_CNV_PARAM (base, cnv::base) { base_ = arg[ARG:: base]; return dncast(); }
- BOOST_CNV_PARAM (adjust, cnv::adjust) { adjust_ = arg[ARG:: adjust]; return dncast(); }
- BOOST_CNV_PARAM (precision, int) { precision_ = arg[ARG::precision]; return dncast(); }
- BOOST_CNV_PARAM (uppercase, bool) { uppercase_ = arg[ARG::uppercase]; return dncast(); }
- BOOST_CNV_PARAM (skipws, bool) { skipws_ = arg[ARG:: skipws]; return dncast(); }
- BOOST_CNV_PARAM (width, int) { width_ = arg[ARG:: width]; return dncast(); }
- BOOST_CNV_PARAM (fill, char) { fill_ = arg[ARG:: fill]; return dncast(); }
+
+ template<typename argument_pack>
+ derived_type& operator()(argument_pack const& arg)
+ {
+ BOOST_CNV_PARAM_TRY(base);
+ BOOST_CNV_PARAM_TRY(adjust);
+ BOOST_CNV_PARAM_TRY(precision);
+ BOOST_CNV_PARAM_TRY(uppercase);
+ BOOST_CNV_PARAM_TRY(skipws);
+ BOOST_CNV_PARAM_TRY(width);
+ BOOST_CNV_PARAM_TRY(fill);
+// BOOST_CNV_PARAM_TRY(locale);
+
+ return this->dncast();
+ }
protected:
derived_type const& dncast () const { return *static_cast<derived_type const*>(this); }
derived_type& dncast () { return *static_cast<derived_type*>(this); }
+ template<typename argument_pack, typename keyword_tag>
+ void set_(argument_pack const&, keyword_tag, mpl::false_) {}
+
+ // Formatters
+ BOOST_CNV_PARAM_SET(base) { base_ = arg[cnv::parameter:: base]; }
+ BOOST_CNV_PARAM_SET(adjust) { adjust_ = arg[cnv::parameter:: adjust]; }
+ BOOST_CNV_PARAM_SET(precision) { precision_ = arg[cnv::parameter::precision]; }
+ BOOST_CNV_PARAM_SET(uppercase) { uppercase_ = arg[cnv::parameter::uppercase]; }
+ BOOST_CNV_PARAM_SET(skipws) { skipws_ = arg[cnv::parameter:: skipws]; }
+ BOOST_CNV_PARAM_SET(width) { width_ = arg[cnv::parameter:: width]; }
+ BOOST_CNV_PARAM_SET(fill) { fill_ = arg[cnv::parameter:: fill]; }
+// BOOST_CNV_PARAM_SET(locale) { locale_ = arg[cnv::parameter:: locale]; }
+
// ULONG_MAX(8 bytes) = 18446744073709551615 (20(10) or 32(2) characters)
// double (8 bytes) max is 316 chars
- static int const bufsize_ = 512;
- bool skipws_;
- int precision_;
- bool uppercase_;
- int width_;
- int fill_;
- cnv::base base_;
- cnv::adjust adjust_;
-// std::locale locale_;
+ static int BOOST_CONSTEXPR_OR_CONST bufsize_ = 512;
+
+ bool skipws_;
+ int precision_;
+ bool uppercase_;
+ int width_;
+ int fill_;
+ cnv::base base_;
+ cnv::adjust adjust_;
+// std::locale locale_;
};
#undef BOOST_CNV_TO_STRING
#undef BOOST_CNV_STRING_TO
-#undef BOOST_CNV_PARAM
+#undef BOOST_CNV_PARAM_SET
+#undef BOOST_CNV_PARAM_TRY
-#endif // BOOST_CONVERT_CONVERTER_BASE_HPP
+#endif // BOOST_CONVERT_BASE_HPP