1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
9 //! Defines the is_cstring type trait
10 // ***************************************************************************
12 #ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP
13 #define BOOST_TEST_UTILS_IS_CSTRING_HPP
16 #include <boost/mpl/bool.hpp>
17 #include <boost/type_traits/is_same.hpp>
18 #include <boost/type_traits/decay.hpp>
19 #include <boost/type_traits/remove_pointer.hpp>
20 #include <boost/type_traits/remove_const.hpp>
21 #include <boost/type_traits/add_const.hpp>
23 #include <boost/test/utils/basic_cstring/basic_cstring_fwd.hpp>
26 #if defined(BOOST_TEST_STRING_VIEW)
27 #include <string_view>
30 //____________________________________________________________________________//
35 // ************************************************************************** //
36 // ************** is_cstring ************** //
37 // ************************************************************************** //
42 struct is_cstring_impl : public mpl::false_ {};
45 struct is_cstring_impl<T const*> : public is_cstring_impl<T*> {};
48 struct is_cstring_impl<T const* const> : public is_cstring_impl<T*> {};
51 struct is_cstring_impl<char*> : public mpl::true_ {};
54 struct is_cstring_impl<wchar_t*> : public mpl::true_ {};
56 template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value >
57 struct deduce_cstring_transform_impl;
59 template <typename T, bool is_cstring >
60 struct deduce_cstring_transform_impl<T&, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
62 template <typename T, bool is_cstring >
63 struct deduce_cstring_transform_impl<T const, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
66 struct deduce_cstring_transform_impl<T, true> {
67 typedef typename boost::add_const<
68 typename boost::remove_pointer<
69 typename boost::decay<T>::type
72 typedef boost::unit_test::basic_cstring<U> type;
76 struct deduce_cstring_transform_impl< T, false > {
79 typename boost::remove_reference<T>::type
84 struct deduce_cstring_transform_impl< std::basic_string<T, std::char_traits<T> >, false > {
85 typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type;
88 #if defined(BOOST_TEST_STRING_VIEW)
90 struct deduce_cstring_transform_impl< std::basic_string_view<T, std::char_traits<T> >, false > {
92 using sv_t = std::basic_string_view<T, std::char_traits<T> > ;
95 using type = stringview_cstring_helper<typename boost::add_const<T>::type, sv_t>;
99 } // namespace ut_detail
102 struct is_cstring : public ut_detail::is_cstring_impl<typename decay<T>::type> {};
104 template<typename T, bool is_cstring = is_cstring<typename boost::decay<T>::type>::value >
105 struct is_cstring_comparable: public mpl::false_ {};
108 struct is_cstring_comparable< T, true > : public mpl::true_ {};
111 struct is_cstring_comparable< std::basic_string<T, std::char_traits<T> >, false > : public mpl::true_ {};
113 #if defined(BOOST_TEST_STRING_VIEW)
115 struct is_cstring_comparable< std::basic_string_view<T, std::char_traits<T> >, false > : public mpl::true_ {};
119 struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : public mpl::true_ {};
122 struct deduce_cstring_transform {
125 typename boost::remove_reference<T>::type
127 typedef typename ut_detail::deduce_cstring_transform_impl<typename boost::decay<U>::type>::type type;
130 } // namespace unit_test
133 #endif // BOOST_TEST_UTILS_IS_CSTRING_HPP