string_literal.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef STRING_LITERAL_DWA2002629_HPP
  6. # define STRING_LITERAL_DWA2002629_HPP
  7. # include <cstddef>
  8. # include <boost/type.hpp>
  9. # include <boost/type_traits/array_traits.hpp>
  10. # include <boost/type_traits/same_traits.hpp>
  11. # include <boost/mpl/bool.hpp>
  12. # include <boost/detail/workaround.hpp>
  13. namespace boost { namespace python { namespace detail {
  14. # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  15. template <class T>
  16. struct is_string_literal : mpl::false_
  17. {
  18. };
  19. # if !defined(__MWERKS__) || __MWERKS__ > 0x2407
  20. template <std::size_t n>
  21. struct is_string_literal<char const[n]> : mpl::true_
  22. {
  23. };
  24. # if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590040)) \
  25. || (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
  26. // This compiler mistakenly gets the type of string literals as char*
  27. // instead of char[NN].
  28. template <>
  29. struct is_string_literal<char* const> : mpl::true_
  30. {
  31. };
  32. # endif
  33. # else
  34. // CWPro7 has trouble with the array type deduction above
  35. template <class T, std::size_t n>
  36. struct is_string_literal<T[n]>
  37. : is_same<T, char const>
  38. {
  39. };
  40. # endif
  41. # else
  42. template <bool is_array = true>
  43. struct string_literal_helper
  44. {
  45. typedef char (&yes_string_literal)[1];
  46. typedef char (&no_string_literal)[2];
  47. template <class T>
  48. struct apply
  49. {
  50. typedef apply<T> self;
  51. static T x;
  52. static yes_string_literal check(char const*);
  53. static no_string_literal check(char*);
  54. static no_string_literal check(void const volatile*);
  55. BOOST_STATIC_CONSTANT(
  56. bool, value = sizeof(self::check(x)) == sizeof(yes_string_literal));
  57. typedef mpl::bool_<value> type;
  58. };
  59. };
  60. template <>
  61. struct string_literal_helper<false>
  62. {
  63. template <class T>
  64. struct apply : mpl::false_
  65. {
  66. };
  67. };
  68. template <class T>
  69. struct is_string_literal
  70. : string_literal_helper<is_array<T>::value>::apply<T>
  71. {
  72. };
  73. # endif
  74. }}} // namespace boost::python::detail
  75. #endif // STRING_LITERAL_DWA2002629_HPP