Release 1.39.0
[boost.git] / Boost_1_39_0 / boost / python / detail / string_literal.hpp
blob50193b643610a8796818e1b81a3d4f2646e6f40c
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
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>
15 namespace boost { namespace python { namespace detail {
17 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
18 template <class T>
19 struct is_string_literal : mpl::false_
23 # if !defined(__MWERKS__) || __MWERKS__ > 0x2407
24 template <std::size_t n>
25 struct is_string_literal<char const[n]> : mpl::true_
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_
37 # endif
39 # else
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>
47 # endif
48 # else
49 template <bool is_array = true>
50 struct string_literal_helper
52 typedef char (&yes_string_literal)[1];
53 typedef char (&no_string_literal)[2];
55 template <class T>
56 struct apply
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*);
64 BOOST_STATIC_CONSTANT(
65 bool, value = sizeof(self::check(x)) == sizeof(yes_string_literal));
66 typedef mpl::bool_<value> type;
70 template <>
71 struct string_literal_helper<false>
73 template <class T>
74 struct apply : mpl::false_
79 template <class T>
80 struct is_string_literal
81 : string_literal_helper<is_array<T>::value>::apply<T>
84 # endif
86 }}} // namespace boost::python::detail
88 #endif // STRING_LITERAL_DWA2002629_HPP