]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
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) | |
5 | ||
6 | // See http://www.boost.org/libs/test for the library home page. | |
7 | // | |
92f5a8d4 TL |
8 | //! @file |
9 | //! Defines the is_cstring type trait | |
b32b8144 FG |
10 | // *************************************************************************** |
11 | ||
12 | #ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP | |
13 | #define BOOST_TEST_UTILS_IS_CSTRING_HPP | |
14 | ||
15 | // Boost | |
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> | |
22 | ||
23 | #include <boost/test/utils/basic_cstring/basic_cstring_fwd.hpp> | |
24 | #include <string> | |
25 | ||
92f5a8d4 TL |
26 | #if defined(BOOST_TEST_STRING_VIEW) |
27 | #include <string_view> | |
28 | #endif | |
29 | ||
b32b8144 FG |
30 | //____________________________________________________________________________// |
31 | ||
32 | namespace boost { | |
33 | namespace unit_test { | |
34 | ||
35 | // ************************************************************************** // | |
36 | // ************** is_cstring ************** // | |
37 | // ************************************************************************** // | |
38 | ||
39 | namespace ut_detail { | |
40 | ||
41 | template<typename T> | |
42 | struct is_cstring_impl : public mpl::false_ {}; | |
43 | ||
44 | template<typename T> | |
45 | struct is_cstring_impl<T const*> : public is_cstring_impl<T*> {}; | |
46 | ||
47 | template<typename T> | |
48 | struct is_cstring_impl<T const* const> : public is_cstring_impl<T*> {}; | |
49 | ||
50 | template<> | |
51 | struct is_cstring_impl<char*> : public mpl::true_ {}; | |
52 | ||
53 | template<> | |
54 | struct is_cstring_impl<wchar_t*> : public mpl::true_ {}; | |
55 | ||
56 | template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value > | |
92f5a8d4 | 57 | struct deduce_cstring_transform_impl; |
b32b8144 FG |
58 | |
59 | template <typename T, bool is_cstring > | |
92f5a8d4 | 60 | struct deduce_cstring_transform_impl<T&, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{}; |
b32b8144 FG |
61 | |
62 | template <typename T, bool is_cstring > | |
92f5a8d4 | 63 | struct deduce_cstring_transform_impl<T const, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{}; |
b32b8144 FG |
64 | |
65 | template <typename T> | |
92f5a8d4 | 66 | struct deduce_cstring_transform_impl<T, true> { |
b32b8144 FG |
67 | typedef typename boost::add_const< |
68 | typename boost::remove_pointer< | |
69 | typename boost::decay<T>::type | |
70 | >::type | |
71 | >::type U; | |
72 | typedef boost::unit_test::basic_cstring<U> type; | |
73 | }; | |
74 | ||
75 | template <typename T> | |
92f5a8d4 | 76 | struct deduce_cstring_transform_impl< T, false > { |
b32b8144 FG |
77 | typedef typename |
78 | boost::remove_const< | |
79 | typename boost::remove_reference<T>::type | |
80 | >::type type; | |
81 | }; | |
82 | ||
83 | template <typename T> | |
92f5a8d4 | 84 | struct deduce_cstring_transform_impl< std::basic_string<T, std::char_traits<T> >, false > { |
b32b8144 FG |
85 | typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type; |
86 | }; | |
87 | ||
92f5a8d4 TL |
88 | #if defined(BOOST_TEST_STRING_VIEW) |
89 | template <typename T> | |
90 | struct deduce_cstring_transform_impl< std::basic_string_view<T, std::char_traits<T> >, false > { | |
91 | private: | |
92 | using sv_t = std::basic_string_view<T, std::char_traits<T> > ; | |
93 | ||
94 | public: | |
95 | using type = stringview_cstring_helper<typename boost::add_const<T>::type, sv_t>; | |
96 | }; | |
97 | #endif | |
98 | ||
b32b8144 FG |
99 | } // namespace ut_detail |
100 | ||
101 | template<typename T> | |
102 | struct is_cstring : public ut_detail::is_cstring_impl<typename decay<T>::type> {}; | |
103 | ||
104 | template<typename T, bool is_cstring = is_cstring<typename boost::decay<T>::type>::value > | |
105 | struct is_cstring_comparable: public mpl::false_ {}; | |
106 | ||
107 | template<typename T> | |
108 | struct is_cstring_comparable< T, true > : public mpl::true_ {}; | |
109 | ||
110 | template<typename T> | |
111 | struct is_cstring_comparable< std::basic_string<T, std::char_traits<T> >, false > : public mpl::true_ {}; | |
112 | ||
92f5a8d4 TL |
113 | #if defined(BOOST_TEST_STRING_VIEW) |
114 | template<typename T> | |
115 | struct is_cstring_comparable< std::basic_string_view<T, std::char_traits<T> >, false > : public mpl::true_ {}; | |
116 | #endif | |
117 | ||
b32b8144 FG |
118 | template<typename T> |
119 | struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : public mpl::true_ {}; | |
120 | ||
121 | template <class T> | |
92f5a8d4 | 122 | struct deduce_cstring_transform { |
b32b8144 FG |
123 | typedef typename |
124 | boost::remove_const< | |
125 | typename boost::remove_reference<T>::type | |
126 | >::type U; | |
92f5a8d4 | 127 | typedef typename ut_detail::deduce_cstring_transform_impl<typename boost::decay<U>::type>::type type; |
b32b8144 FG |
128 | }; |
129 | ||
130 | } // namespace unit_test | |
131 | } // namespace boost | |
132 | ||
133 | #endif // BOOST_TEST_UTILS_IS_CSTRING_HPP |