feat():initial version

This commit is contained in:
2026-06-09 20:16:47 +08:00
commit 85fbb3188c
14809 changed files with 3044607 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
// 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_DETAIL_IS_CHAR_HPP
#define BOOST_CONVERT_DETAIL_IS_CHAR_HPP
#include <boost/convert/detail/config.hpp>
#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> 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 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

View File

@@ -0,0 +1,60 @@
// 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_FORWARD_HPP
#define BOOST_CONVERT_FORWARD_HPP
#include <boost/config.hpp>
#include <boost/version.hpp>
#include <boost/optional.hpp>
#include <type_traits>
#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)
//MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008)
//MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
//MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
//MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
//MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
//MSVC++ 15.0 _MSC_VER == 1910 (Visual Studio 2017)
# pragma warning(disable: 4100) // unreferenced formal parameter
# pragma warning(disable: 4146) // unary minus operator applied to unsigned type
# pragma warning(disable: 4180) // qualifier applied to function type has no meaning
# pragma warning(disable: 4224)
# pragma warning(disable: 4244)
# pragma warning(disable: 4800) // forcing value to bool
# pragma warning(disable: 4996)
#if _MSC_VER < 1900 /* MSVC-14 defines real snprintf()... just about time! */
# define snprintf _snprintf
#endif
#endif
#endif // BOOST_CONVERT_FORWARD_HPP

View File

@@ -0,0 +1,60 @@
// 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_HAS_MEMBER_HPP
#define BOOST_CONVERT_HAS_MEMBER_HPP
#include <boost/type_traits/detail/yes_no_type.hpp>
// This macro allows to check if a type has a member named "__member_name__"...
// ... regardless of the signature. If takes advantage of the following behavior related to
// function resolution. Say, both, foo and base, declare a method with the same name "func":
//
// struct foo { int func (int, int) { return 0; } };
// struct base { void func () {} };
// struct mixin : public foo, public base {};
//
// Now, if we inherit from both -- foo and base -- classes, then the following calls will fail
// mixin_ptr(0)->func();
// mixin_ptr(0)->func(5, 5);
// with the error message (gcc): request for member func is ambiguous
// regardless if we provide any arguments or not even though one might expect that
// arg-based signature resolution might kick in. The only way to deploy those methods is:
//
// mixin_ptr(0)->foo::func();
// mixin_ptr(0)->base::func(5, 5);
//
// C2. The actual signature of __member_name__ is not taken into account. If
// __T__::__member_name__(any-signature) exists, then the introduced base::__member_name__
// will cause mixin->__member_name__() call to fail to compile (due to ambiguity).
// C3. &U::__member_name__ (a.k.a. &mixin::__member_name__)
// has the type of func_type only if __T__::__member_name__ does not exist.
// If __T__::member_name does exist, then mixin::__member_name__ is ambiguous
// and "yes_type test (...)" kicks in instead.
// C4. Need to find some unique/ugly name so that it does not clash if this macro is
// used inside some other template class;
#define BOOST_DECLARE_HAS_MEMBER(__trait_name__, __member_name__) \
\
template <typename __boost_has_member_T__> /*C4*/ \
class __trait_name__ \
{ \
using check_type = typename boost::remove_const<__boost_has_member_T__>::type; \
using yes_type = ::boost::type_traits::yes_type; \
using no_type = ::boost::type_traits:: no_type; \
\
struct base { void __member_name__(/*C2*/) {}}; \
struct mixin : public base, public check_type {}; \
\
template <void (base::*)()> struct aux {}; \
\
template <typename U> static no_type test(aux<&U::__member_name__>*); /*C3*/ \
template <typename U> static yes_type test(...); \
\
public: \
\
BOOST_STATIC_CONSTANT(bool, value = (sizeof(yes_type) == sizeof(test<mixin>(0)))); \
}
#endif // BOOST_CONVERT_HAS_MEMBER_HPP

View File

@@ -0,0 +1,100 @@
// 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_IS_CALLABLE_HPP
#define BOOST_CONVERT_IS_CALLABLE_HPP
#include <boost/convert/detail/has_member.hpp>
namespace boost { namespace cnv { namespace detail
{
using yes_type = ::boost::type_traits::yes_type;
using no_type = ::boost::type_traits:: no_type;
struct not_found {};
struct void_return_substitute {};
// The overloaded comma operator only kicks in for U != void essentially short-circuiting
// itself ineffective. Otherwise, when U=void, the standard op,() kicks in and returns
// 'void_return_substitute'.
template<typename U> U const& operator, (U const&, void_return_substitute);
template<typename U> U& operator, (U&, void_return_substitute);
template <typename src, typename dst> struct match_const { typedef dst type; };
template <typename src, typename dst> struct match_const<src const, dst> { typedef dst const type; };
template<typename T, typename return_type>
struct redirect
{
static no_type test (...);
static yes_type test (return_type);
};
template<typename T>
struct redirect<T, void>
{
static yes_type test (...);
static no_type test (not_found);
};
}}}
// No-args case needs to be implemented differently and has not been implemented yet.
// template <typename R>
// struct check<true, R ()>
// C1. Need to find some unique/ugly names so that they do not clash if this macro is
// used inside some other template class;
// C2. Body of the function is not actually used anywhere.
// However, Intel C++ compiler treats it as an error. So, we provide the body.
#define BOOST_DECLARE_IS_CALLABLE(__trait_name__, __member_name__) \
\
template <typename __boost_is_callable_T__, typename __boost_is_callable_signature__> \
class __trait_name__ \
{ \
typedef __boost_is_callable_T__ class_type; /*C1*/ \
typedef __boost_is_callable_signature__ signature; /*C1*/ \
typedef boost::cnv::detail::not_found not_found; \
\
BOOST_DECLARE_HAS_MEMBER(has_member, __member_name__); \
\
struct mixin : public class_type \
{ \
using class_type::__member_name__; \
not_found __member_name__(...) const { return not_found(); /*C2*/} \
}; \
\
typedef typename boost::cnv::detail::match_const<class_type, mixin>::type* mixin_ptr; \
\
template <bool has, typename F> struct check { static bool const value = false; }; \
\
template <typename Arg1, typename R> \
struct check<true, R (Arg1)> \
{ \
typedef typename boost::decay<Arg1>::type* a1; \
\
static bool const value = sizeof(boost::type_traits::yes_type) \
== sizeof(boost::cnv::detail::redirect<class_type, R>::test( \
(mixin_ptr(0)->__member_name__(*a1(0)), \
boost::cnv::detail::void_return_substitute()))); \
}; \
template <typename Arg1, typename Arg2, typename R> \
struct check<true, R (Arg1, Arg2)> \
{ \
typedef typename boost::decay<Arg1>::type* a1; \
typedef typename boost::decay<Arg2>::type* a2; \
\
static bool const value = sizeof(boost::type_traits::yes_type) \
== sizeof(boost::cnv::detail::redirect<class_type, R>::test( \
(mixin_ptr(0)->__member_name__(*a1(0), *a2(0)), \
boost::cnv::detail::void_return_substitute()))); \
}; \
\
public: \
\
/* Check the existence of __member_name__ first, then the signature. */ \
static bool const value = check<has_member<class_type>::value, signature>::value; \
}
#endif // BOOST_CONVERT_IS_CALLABLE_HPP

View File

@@ -0,0 +1,46 @@
// 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_IS_CONVERTER_HPP
#define BOOST_CONVERT_IS_CONVERTER_HPP
#include <boost/convert/detail/config.hpp>
#include <boost/convert/detail/is_callable.hpp>
#include <boost/type_traits/function_traits.hpp>
#include <boost/core/ref.hpp>
namespace boost { namespace cnv
{
template<typename, typename, typename, typename =void>
struct is_cnv { BOOST_STATIC_CONSTANT(bool, value = false); };
template<typename Class, typename TypeIn, typename TypeOut>
struct is_cnv<Class, TypeIn, TypeOut, typename std::enable_if<is_class<Class>::value, void>::type>
{
typedef typename ::boost::unwrap_reference<Class>::type class_type;
typedef void signature_type(TypeIn const&, optional<TypeOut>&);
BOOST_DECLARE_IS_CALLABLE(is_callable, operator());
BOOST_STATIC_CONSTANT(bool, value = (is_callable<class_type, signature_type>::value));
};
template<typename Function, typename TypeIn, typename TypeOut>
struct is_cnv<Function, TypeIn, TypeOut,
typename enable_if_c<is_function<Function>::value && function_types::function_arity<Function>::value == 2,
void>::type>
{
using in_type = TypeIn;
using out_type = optional<TypeOut>&;
using func_in_type = typename function_traits<Function>::arg1_type;
using func_out_type = typename function_traits<Function>::arg2_type;
BOOST_STATIC_CONSTANT(bool, in_good = (is_convertible<in_type, func_in_type>::value));
BOOST_STATIC_CONSTANT(bool, out_good = (is_same<out_type, func_out_type>::value));
BOOST_STATIC_CONSTANT(bool, value = (in_good && out_good));
};
}}
#endif // BOOST_CONVERT_IS_CONVERTER_HPP

View File

@@ -0,0 +1,59 @@
// 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_IS_FUNCTION_HPP
#define BOOST_CONVERT_IS_FUNCTION_HPP
#include <boost/convert/detail/config.hpp>
#include <boost/convert/detail/has_member.hpp>
#include <boost/function_types/is_function_pointer.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/function_types/result_type.hpp>
namespace boost { namespace cnv
{
using yes_type = ::boost::type_traits::yes_type;
using no_type = ::boost::type_traits:: no_type;
template <bool has_operator, typename Functor, typename TypeOut>
struct check_functor { BOOST_STATIC_CONSTANT(bool, value = false); };
template<typename Func, typename TypeOut, class Enable =void>
struct is_fun { BOOST_STATIC_CONSTANT(bool, value = false); };
template <typename Functor, typename TypeOut>
struct check_functor<true, Functor, TypeOut>
{
static yes_type test (TypeOut const&);
static no_type test (...);
static bool BOOST_CONSTEXPR_OR_CONST value = sizeof(yes_type) == sizeof(test(((Functor*) 0)->operator()()));
};
template<typename Functor, typename TypeOut>
struct is_fun<Functor, TypeOut,
typename enable_if_c<is_class<Functor>::value && !is_convertible<Functor, TypeOut>::value, void>::type>
{
BOOST_DECLARE_HAS_MEMBER(has_funop, operator());
BOOST_STATIC_CONSTANT(bool, value = (check_functor<has_funop<Functor>::value, Functor, TypeOut>::value));
};
template<typename Function, typename TypeOut>
struct is_fun<Function, TypeOut,
typename enable_if_c<
function_types::is_function_pointer<Function>::value &&
function_types::function_arity<Function>::value == 0 &&
!is_same<Function, TypeOut>::value,
void>::type>
{
typedef TypeOut out_type;
typedef typename function_types::result_type<Function>::type func_out_type;
BOOST_STATIC_CONSTANT(bool, value = (is_convertible<func_out_type, out_type>::value));
};
}}
#endif // BOOST_CONVERT_IS_FUNCTION_HPP

View File

@@ -0,0 +1,36 @@
// 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_DETAIL_IS_STRING_HPP
#define BOOST_CONVERT_DETAIL_IS_STRING_HPP
#include <boost/convert/detail/range.hpp>
namespace boost { namespace cnv
{
namespace detail
{
template<typename T, bool is_range_class> struct is_string : std::false_type {};
template<typename T> struct is_string<T*, false>
{
static bool BOOST_CONSTEXPR_OR_CONST value = cnv::is_char<T>::value;
};
template <typename T, std::size_t N> struct is_string<T [N], false>
{
static bool BOOST_CONSTEXPR_OR_CONST value = cnv::is_char<T>::value;
};
template<typename T> struct is_string<T, /*is_range_class=*/true>
{
static bool BOOST_CONSTEXPR_OR_CONST value = cnv::is_char<typename T::value_type>::value;
};
}
template<typename T>
struct is_string : detail::is_string<
typename std::remove_const<T>::type,
std::is_class<T>::value && cnv::is_range<T>::value>
{};
}}
#endif // BOOST_CONVERT_DETAIL_IS_STRING_HPP

View File

@@ -0,0 +1,117 @@
// 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_DETAIL_RANGE_HPP
#define BOOST_CONVERT_DETAIL_RANGE_HPP
#include <boost/convert/detail/has_member.hpp>
#include <boost/convert/detail/char.hpp>
#include <boost/range/iterator.hpp>
namespace boost { namespace cnv
{
namespace detail
{
template<typename T, bool is_class> struct is_range : std::false_type {};
template<typename T> struct is_range<T, /*is_class=*/true>
{
BOOST_DECLARE_HAS_MEMBER(has_begin, begin);
BOOST_DECLARE_HAS_MEMBER( has_end, end);
static bool BOOST_CONSTEXPR_OR_CONST value = has_begin<T>::value && has_end<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;
template<typename T>
struct iterator<T, typename std::enable_if<is_range<T>::value>::type>
{
using type = typename boost::range_iterator<T>::type;
using const_type = typename boost::range_iterator<T const>::type;
using value_type = typename boost::iterator_value<type>::type;
};
template<typename T>
struct iterator<T*, void>
{
using value_type = typename boost::remove_const<T>::type;
using type = T*;
using const_type = value_type const*;
};
template<typename T>
struct range_base
{
using value_type = typename cnv::iterator<T>::value_type;
using iterator = typename cnv::iterator<T>::type;
using const_iterator = typename cnv::iterator<T>::const_type;
using sentry_type = const_iterator;
iterator begin () { return begin_; }
const_iterator begin () const { return begin_; }
void operator++ () { ++begin_; }
// void operator-- () { --end_; }
protected:
range_base (iterator b, iterator e) : begin_(b), end_(e) {}
iterator begin_;
iterator mutable end_;
};
template<typename T>
struct range<T, typename std::enable_if<is_range<T>::value>::type> : public range_base<T>
{
using this_type = range;
using base_type = range_base<T>;
using iterator = typename base_type::iterator;
using const_iterator = typename base_type::const_iterator;
using sentry_type = const_iterator;
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_; }
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 std::enable_if<cnv::is_char<T>::value>::type> : public range_base<T*>
{
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
{
friend bool operator!=(iterator it, sentry_type) { return !!*it; }
};
range (iterator b, iterator e =0) : base_type(b, e) {}
iterator end () { return base_type::end_ ? base_type::end_ : (base_type::end_ = base_type::begin_ + size()); }
const_iterator end () const { return base_type::end_ ? base_type::end_ : (base_type::end_ = base_type::begin_ + size()); }
sentry_type sentry () const { return sentry_type(); }
std::size_t size () const { return std::char_traits<value_type>::length(base_type::begin_); }
bool empty () const { return !*base_type::begin_; }
};
template<typename T>
struct range<T* const, void> : public range<T*>
{
range (T* b, T* e =0) : range<T*>(b, e) {}
};
template <typename T, std::size_t N>
struct range<T [N], void> : public range<T*>
{
range (T* b, T* e =0) : range<T*>(b, e) {}
};
}}
#endif // BOOST_CONVERT_DETAIL_RANGE_HPP