[857] | 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 |
|
---|
| 8 | # include <cstddef>
|
---|
| 9 | # include <boost/type.hpp>
|
---|
| 10 | # include <boost/type_traits/array_traits.hpp>
|
---|
| 11 | # include <boost/type_traits/same_traits.hpp>
|
---|
| 12 | # include <boost/mpl/bool.hpp>
|
---|
| 13 | # include <boost/detail/workaround.hpp>
|
---|
| 14 |
|
---|
| 15 | namespace boost { namespace python { namespace detail {
|
---|
| 16 |
|
---|
| 17 | # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
| 18 | template <class T>
|
---|
| 19 | struct is_string_literal : mpl::false_
|
---|
| 20 | {
|
---|
| 21 | };
|
---|
| 22 |
|
---|
| 23 | # if !defined(__MWERKS__) || __MWERKS__ > 0x2407
|
---|
| 24 | template <std::size_t n>
|
---|
| 25 | struct is_string_literal<char const[n]> : mpl::true_
|
---|
| 26 | {
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | # if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590040)) \
|
---|
| 30 | || (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
|
---|
| 31 | // This compiler mistakenly gets the type of string literals as char*
|
---|
| 32 | // instead of char[NN].
|
---|
| 33 | template <>
|
---|
| 34 | struct is_string_literal<char* const> : mpl::true_
|
---|
| 35 | {
|
---|
| 36 | };
|
---|
| 37 | # endif
|
---|
| 38 |
|
---|
| 39 | # else
|
---|
| 40 |
|
---|
| 41 | // CWPro7 has trouble with the array type deduction above
|
---|
| 42 | template <class T, std::size_t n>
|
---|
| 43 | struct is_string_literal<T[n]>
|
---|
| 44 | : is_same<T, char const>
|
---|
| 45 | {
|
---|
| 46 | };
|
---|
| 47 | # endif
|
---|
| 48 | # else
|
---|
| 49 | template <bool is_array = true>
|
---|
| 50 | struct string_literal_helper
|
---|
| 51 | {
|
---|
| 52 | typedef char (&yes_string_literal)[1];
|
---|
| 53 | typedef char (&no_string_literal)[2];
|
---|
| 54 |
|
---|
| 55 | template <class T>
|
---|
| 56 | struct apply
|
---|
| 57 | {
|
---|
| 58 | typedef apply<T> self;
|
---|
| 59 | static T x;
|
---|
| 60 | static yes_string_literal check(char const*);
|
---|
| 61 | static no_string_literal check(char*);
|
---|
| 62 | static no_string_literal check(void const volatile*);
|
---|
| 63 |
|
---|
| 64 | BOOST_STATIC_CONSTANT(
|
---|
| 65 | bool, value = sizeof(self::check(x)) == sizeof(yes_string_literal));
|
---|
| 66 | typedef mpl::bool_<value> type;
|
---|
| 67 | };
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | template <>
|
---|
| 71 | struct string_literal_helper<false>
|
---|
| 72 | {
|
---|
| 73 | template <class T>
|
---|
| 74 | struct apply : mpl::false_
|
---|
| 75 | {
|
---|
| 76 | };
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | template <class T>
|
---|
| 80 | struct is_string_literal
|
---|
| 81 | : string_literal_helper<is_array<T>::value>::apply<T>
|
---|
| 82 | {
|
---|
| 83 | };
|
---|
| 84 | # endif
|
---|
| 85 |
|
---|
| 86 | }}} // namespace boost::python::detail
|
---|
| 87 |
|
---|
| 88 | #endif // STRING_LITERAL_DWA2002629_HPP
|
---|