is_cstring.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision$
  10. //
  11. // Description : defines the is_cstring type trait
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP
  14. #define BOOST_TEST_UTILS_IS_CSTRING_HPP
  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. #include <boost/test/utils/basic_cstring/basic_cstring_fwd.hpp>
  23. #include <string>
  24. //____________________________________________________________________________//
  25. namespace boost {
  26. namespace unit_test {
  27. // ************************************************************************** //
  28. // ************** is_cstring ************** //
  29. // ************************************************************************** //
  30. namespace ut_detail {
  31. template<typename T>
  32. struct is_cstring_impl : public mpl::false_ {};
  33. template<typename T>
  34. struct is_cstring_impl<T const*> : public is_cstring_impl<T*> {};
  35. template<typename T>
  36. struct is_cstring_impl<T const* const> : public is_cstring_impl<T*> {};
  37. template<>
  38. struct is_cstring_impl<char*> : public mpl::true_ {};
  39. template<>
  40. struct is_cstring_impl<wchar_t*> : public mpl::true_ {};
  41. template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value >
  42. struct deduce_cstring_impl;
  43. template <typename T, bool is_cstring >
  44. struct deduce_cstring_impl<T&, is_cstring> : public deduce_cstring_impl<T, is_cstring>{};
  45. template <typename T, bool is_cstring >
  46. struct deduce_cstring_impl<T const, is_cstring> : public deduce_cstring_impl<T, is_cstring>{};
  47. template <typename T>
  48. struct deduce_cstring_impl<T, true> {
  49. typedef typename boost::add_const<
  50. typename boost::remove_pointer<
  51. typename boost::decay<T>::type
  52. >::type
  53. >::type U;
  54. typedef boost::unit_test::basic_cstring<U> type;
  55. };
  56. template <typename T>
  57. struct deduce_cstring_impl< T, false > {
  58. typedef typename
  59. boost::remove_const<
  60. typename boost::remove_reference<T>::type
  61. >::type type;
  62. };
  63. template <typename T>
  64. struct deduce_cstring_impl< std::basic_string<T, std::char_traits<T> >, false > {
  65. typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type;
  66. };
  67. } // namespace ut_detail
  68. template<typename T>
  69. struct is_cstring : public ut_detail::is_cstring_impl<typename decay<T>::type> {};
  70. template<typename T, bool is_cstring = is_cstring<typename boost::decay<T>::type>::value >
  71. struct is_cstring_comparable: public mpl::false_ {};
  72. template<typename T>
  73. struct is_cstring_comparable< T, true > : public mpl::true_ {};
  74. template<typename T>
  75. struct is_cstring_comparable< std::basic_string<T, std::char_traits<T> >, false > : public mpl::true_ {};
  76. template<typename T>
  77. struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : public mpl::true_ {};
  78. template <class T>
  79. struct deduce_cstring {
  80. typedef typename
  81. boost::remove_const<
  82. typename boost::remove_reference<T>::type
  83. >::type U;
  84. typedef typename ut_detail::deduce_cstring_impl<typename boost::decay<U>::type>::type type;
  85. };
  86. } // namespace unit_test
  87. } // namespace boost
  88. #endif // BOOST_TEST_UTILS_IS_CSTRING_HPP