1 // This file has been generated by Py++. 2 3 // Header file suite_utils.hpp 4 // 5 // Shared utilities for the indexing suite. 6 // 7 // Copyright (c) 2003 Raoul M. Gough 8 // 9 // Use, modification and distribution is subject to the Boost Software 10 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy 11 // at http://www.boost.org/LICENSE_1_0.txt) 12 // 13 // History 14 // ======= 15 // 2003/ 8/23 rmg File creation 16 // 2008/12/08 Roman Change indexing suite layout 17 // 18 // $Id: suite_utils.hpp,v 1.1.2.7 2003/11/24 14:28:31 raoulgough Exp $ 19 // 20 21 #ifndef BOOST_PYTHON_INDEXING_SUITE_UTILS_HPP 22 #define BOOST_PYTHON_INDEXING_SUITE_UTILS_HPP 23 24 #include <boost/type_traits.hpp> 25 26 namespace boost { namespace python { namespace indexing { 27 #if BOOST_WORKAROUND (BOOST_MSVC, BOOST_TESTED_AT (1310)) || (defined (__GNUC__) && (__GNUC__ < 3)) 28 // MSVC and GCC 2.96 seem to have problems comparing enumerated 29 // values in a static constant expression, and don't believe that an 30 // expression like (traits::index_style >= index_style_nonlinear) is 31 // a compile-time constant. However, the problem doesn't exist for 32 // int. 33 typedef int index_style_t; 34 index_style_t const index_style_none = 0; 35 index_style_t const index_style_nonlinear = 1; 36 index_style_t const index_style_linear = 2; 37 #else 38 enum index_style_t { 39 index_style_none, // No random access (iteration only) 40 index_style_nonlinear, // Random access by key (no slicing) 41 index_style_linear // Random access by integer index (allows slicing) 42 }; 43 #endif 44 45 template<typename T> 46 class is_mutable_ref 47 { 48 typedef typename boost::remove_reference<T>::type maybe_const; 49 50 public: 51 BOOST_STATIC_CONSTANT (bool, value = !boost::is_const<maybe_const>::value); 52 }; 53 54 // make_signed attempts to identify the signed version of any 55 // numeric type (useful in this case because Python container 56 // indexes can be negative). 57 template<typename T> struct make_signed { 58 typedef T type; 59 }; 60 61 template<> struct make_signed<char> { 62 // Raw "char" could be signed or unsigned. "signed char" 63 // guarantess signedness 64 typedef signed char type; 65 }; 66 67 template<> struct make_signed<unsigned char> { 68 typedef signed char type; 69 }; 70 71 template<> struct make_signed<unsigned short> { 72 typedef short type; 73 }; 74 75 template<> struct make_signed<unsigned int> { 76 typedef int type; 77 }; 78 79 template<> struct make_signed<unsigned long> { 80 typedef long type; 81 }; 82 83 #if defined (BOOST_HAS_LONG_LONG) 84 template<> struct make_signed<unsigned long long> { 85 typedef long long type; 86 }; 87 #elif defined (BOOST_HAS_MS_INT64) 88 template<> struct make_signed<unsigned __int64> { 89 typedef __int64 type; 90 }; 91 #endif 92 93 namespace detail { 94 struct no_override { }; 95 96 template<typename Base, typename Override> 97 struct maybe_override 98 { 99 // Probably need to disable this if there is no partial 100 // specialization support, because Override is almost certain to 101 // be an incomplete type. If that is right, the workaround 102 // version would just have to do "typedef Base type;" 103 104 typedef typename mpl::if_ 105 <is_same <Override, no_override>, Base, Override> 106 ::type type; 107 }; 108 } 109 110 } } } 111 112 #endif // BOOST_PYTHON_INDEXING_SUITE_UTILS_HPP 113 114 115 116