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.
10 // Version : $Revision$
12 // Description : defines the is_cstring type trait
13 // ***************************************************************************
15 #ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP
16 #define BOOST_TEST_UTILS_IS_CSTRING_HPP
19 #include <boost/mpl/bool.hpp>
20 #include <boost/type_traits/is_same.hpp>
21 #include <boost/type_traits/decay.hpp>
22 #include <boost/type_traits/remove_pointer.hpp>
23 #include <boost/type_traits/remove_const.hpp>
24 #include <boost/type_traits/add_const.hpp>
26 #include <boost/test/utils/basic_cstring/basic_cstring_fwd.hpp>
29 //____________________________________________________________________________//
34 // ************************************************************************** //
35 // ************** is_cstring ************** //
36 // ************************************************************************** //
41 struct is_cstring_impl : public mpl::false_ {};
44 struct is_cstring_impl<T const*> : public is_cstring_impl<T*> {};
47 struct is_cstring_impl<T const* const> : public is_cstring_impl<T*> {};
50 struct is_cstring_impl<char*> : public mpl::true_ {};
53 struct is_cstring_impl<wchar_t*> : public mpl::true_ {};
55 template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value >
56 struct deduce_cstring_impl;
58 template <typename T, bool is_cstring >
59 struct deduce_cstring_impl<T&, is_cstring> : public deduce_cstring_impl<T, is_cstring>{};
61 template <typename T, bool is_cstring >
62 struct deduce_cstring_impl<T const, is_cstring> : public deduce_cstring_impl<T, is_cstring>{};
65 struct deduce_cstring_impl<T, true> {
66 typedef typename boost::add_const<
67 typename boost::remove_pointer<
68 typename boost::decay<T>::type
71 typedef boost::unit_test::basic_cstring<U> type;
75 struct deduce_cstring_impl< T, false > {
78 typename boost::remove_reference<T>::type
83 struct deduce_cstring_impl< std::basic_string<T, std::char_traits<T> >, false > {
84 typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type;
87 } // namespace ut_detail
90 struct is_cstring : public ut_detail::is_cstring_impl<typename decay<T>::type> {};
92 template<typename T, bool is_cstring = is_cstring<typename boost::decay<T>::type>::value >
93 struct is_cstring_comparable: public mpl::false_ {};
96 struct is_cstring_comparable< T, true > : public mpl::true_ {};
99 struct is_cstring_comparable< std::basic_string<T, std::char_traits<T> >, false > : public mpl::true_ {};
102 struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : public mpl::true_ {};
105 struct deduce_cstring {
108 typename boost::remove_reference<T>::type
110 typedef typename ut_detail::deduce_cstring_impl<typename boost::decay<U>::type>::type type;
113 } // namespace unit_test
116 #endif // BOOST_TEST_UTILS_IS_CSTRING_HPP