File indexing completed on 2025-01-18 09:52:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP
0013 #define BOOST_TEST_UTILS_IS_CSTRING_HPP
0014
0015
0016 #include <boost/mpl/bool.hpp>
0017 #include <boost/type_traits/is_same.hpp>
0018 #include <boost/type_traits/decay.hpp>
0019 #include <boost/type_traits/remove_pointer.hpp>
0020 #include <boost/type_traits/remove_const.hpp>
0021 #include <boost/type_traits/add_const.hpp>
0022
0023 #include <boost/test/utils/basic_cstring/basic_cstring_fwd.hpp>
0024 #include <string>
0025
0026 #if defined(BOOST_TEST_STRING_VIEW)
0027 #include <string_view>
0028 #endif
0029
0030
0031
0032 namespace boost {
0033 namespace unit_test {
0034
0035
0036
0037
0038
0039 namespace ut_detail {
0040
0041 template<typename T>
0042 struct is_cstring_impl : public mpl::false_ {};
0043
0044 template<typename T>
0045 struct is_cstring_impl<T const*> : public is_cstring_impl<T*> {};
0046
0047 template<typename T>
0048 struct is_cstring_impl<T const* const> : public is_cstring_impl<T*> {};
0049
0050 template<>
0051 struct is_cstring_impl<char*> : public mpl::true_ {};
0052
0053 template<>
0054 struct is_cstring_impl<wchar_t*> : public mpl::true_ {};
0055
0056 template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value >
0057 struct deduce_cstring_transform_impl;
0058
0059 template <typename T, bool is_cstring >
0060 struct deduce_cstring_transform_impl<T&, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
0061
0062 template <typename T, bool is_cstring >
0063 struct deduce_cstring_transform_impl<T const, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
0064
0065 template <typename T>
0066 struct deduce_cstring_transform_impl<T, true> {
0067 typedef typename boost::add_const<
0068 typename boost::remove_pointer<
0069 typename boost::decay<T>::type
0070 >::type
0071 >::type U;
0072 typedef boost::unit_test::basic_cstring<U> type;
0073 };
0074
0075 template <typename T>
0076 struct deduce_cstring_transform_impl< T, false > {
0077 typedef typename
0078 boost::remove_const<
0079 typename boost::remove_reference<T>::type
0080 >::type type;
0081 };
0082
0083 template <typename T>
0084 struct deduce_cstring_transform_impl< std::basic_string<T, std::char_traits<T> >, false > {
0085 typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type;
0086 };
0087
0088 #if defined(BOOST_TEST_STRING_VIEW)
0089 template <typename T>
0090 struct deduce_cstring_transform_impl< std::basic_string_view<T, std::char_traits<T> >, false > {
0091 private:
0092 using sv_t = std::basic_string_view<T, std::char_traits<T> > ;
0093
0094 public:
0095 using type = stringview_cstring_helper<typename boost::add_const<T>::type, sv_t>;
0096 };
0097 #endif
0098
0099 }
0100
0101 template<typename T>
0102 struct is_cstring : public ut_detail::is_cstring_impl<typename decay<T>::type> {};
0103
0104 template<typename T, bool is_cstring = is_cstring<typename boost::decay<T>::type>::value >
0105 struct is_cstring_comparable: public mpl::false_ {};
0106
0107 template<typename T>
0108 struct is_cstring_comparable< T, true > : public mpl::true_ {};
0109
0110 template<typename T>
0111 struct is_cstring_comparable< std::basic_string<T, std::char_traits<T> >, false > : public mpl::true_ {};
0112
0113 #if defined(BOOST_TEST_STRING_VIEW)
0114 template<typename T>
0115 struct is_cstring_comparable< std::basic_string_view<T, std::char_traits<T> >, false > : public mpl::true_ {};
0116 #endif
0117
0118 template<typename T>
0119 struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : public mpl::true_ {};
0120
0121 template <class T>
0122 struct deduce_cstring_transform {
0123 typedef typename
0124 boost::remove_const<
0125 typename boost::remove_reference<T>::type
0126 >::type U;
0127 typedef typename ut_detail::deduce_cstring_transform_impl<typename boost::decay<U>::type>::type type;
0128 };
0129
0130 }
0131 }
0132
0133 #endif