| 1 | // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000. |
|---|
| 2 | // Use, modification and distribution are subject to the Boost Software License, |
|---|
| 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 4 | // http://www.boost.org/LICENSE_1_0.txt). |
|---|
| 5 | // |
|---|
| 6 | // See http://www.boost.org/libs/utility for most recent version including documentation. |
|---|
| 7 | |
|---|
| 8 | // call_traits: defines typedefs for function usage |
|---|
| 9 | // (see libs/utility/call_traits.htm) |
|---|
| 10 | |
|---|
| 11 | /* Release notes: |
|---|
| 12 | 23rd July 2000: |
|---|
| 13 | Fixed array specialization. (JM) |
|---|
| 14 | Added Borland specific fixes for reference types |
|---|
| 15 | (issue raised by Steve Cleary). |
|---|
| 16 | */ |
|---|
| 17 | |
|---|
| 18 | #ifndef BOOST_DETAIL_CALL_TRAITS_HPP |
|---|
| 19 | #define BOOST_DETAIL_CALL_TRAITS_HPP |
|---|
| 20 | |
|---|
| 21 | #ifndef BOOST_CONFIG_HPP |
|---|
| 22 | #include <boost/config.hpp> |
|---|
| 23 | #endif |
|---|
| 24 | #include <cstddef> |
|---|
| 25 | |
|---|
| 26 | #include <boost/type_traits/is_arithmetic.hpp> |
|---|
| 27 | #include <boost/type_traits/is_pointer.hpp> |
|---|
| 28 | #include <boost/detail/workaround.hpp> |
|---|
| 29 | |
|---|
| 30 | namespace boost{ |
|---|
| 31 | |
|---|
| 32 | namespace detail{ |
|---|
| 33 | |
|---|
| 34 | template <typename T, bool small_> |
|---|
| 35 | struct ct_imp2 |
|---|
| 36 | { |
|---|
| 37 | typedef const T& param_type; |
|---|
| 38 | }; |
|---|
| 39 | |
|---|
| 40 | template <typename T> |
|---|
| 41 | struct ct_imp2<T, true> |
|---|
| 42 | { |
|---|
| 43 | typedef const T param_type; |
|---|
| 44 | }; |
|---|
| 45 | |
|---|
| 46 | template <typename T, bool isp, bool b1> |
|---|
| 47 | struct ct_imp |
|---|
| 48 | { |
|---|
| 49 | typedef const T& param_type; |
|---|
| 50 | }; |
|---|
| 51 | |
|---|
| 52 | template <typename T, bool isp> |
|---|
| 53 | struct ct_imp<T, isp, true> |
|---|
| 54 | { |
|---|
| 55 | typedef typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type param_type; |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | template <typename T, bool b1> |
|---|
| 59 | struct ct_imp<T, true, b1> |
|---|
| 60 | { |
|---|
| 61 | typedef T const param_type; |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | template <typename T> |
|---|
| 67 | struct call_traits |
|---|
| 68 | { |
|---|
| 69 | public: |
|---|
| 70 | typedef T value_type; |
|---|
| 71 | typedef T& reference; |
|---|
| 72 | typedef const T& const_reference; |
|---|
| 73 | // |
|---|
| 74 | // C++ Builder workaround: we should be able to define a compile time |
|---|
| 75 | // constant and pass that as a single template parameter to ct_imp<T,bool>, |
|---|
| 76 | // however compiler bugs prevent this - instead pass three bool's to |
|---|
| 77 | // ct_imp<T,bool,bool,bool> and add an extra partial specialisation |
|---|
| 78 | // of ct_imp to handle the logic. (JM) |
|---|
| 79 | typedef typename detail::ct_imp< |
|---|
| 80 | T, |
|---|
| 81 | ::boost::is_pointer<T>::value, |
|---|
| 82 | ::boost::is_arithmetic<T>::value |
|---|
| 83 | >::param_type param_type; |
|---|
| 84 | }; |
|---|
| 85 | |
|---|
| 86 | template <typename T> |
|---|
| 87 | struct call_traits<T&> |
|---|
| 88 | { |
|---|
| 89 | typedef T& value_type; |
|---|
| 90 | typedef T& reference; |
|---|
| 91 | typedef const T& const_reference; |
|---|
| 92 | typedef T& param_type; // hh removed const |
|---|
| 93 | }; |
|---|
| 94 | |
|---|
| 95 | #if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x570 ) ) |
|---|
| 96 | // these are illegal specialisations; cv-qualifies applied to |
|---|
| 97 | // references have no effect according to [8.3.2p1], |
|---|
| 98 | // C++ Builder requires them though as it treats cv-qualified |
|---|
| 99 | // references as distinct types... |
|---|
| 100 | template <typename T> |
|---|
| 101 | struct call_traits<T&const> |
|---|
| 102 | { |
|---|
| 103 | typedef T& value_type; |
|---|
| 104 | typedef T& reference; |
|---|
| 105 | typedef const T& const_reference; |
|---|
| 106 | typedef T& param_type; // hh removed const |
|---|
| 107 | }; |
|---|
| 108 | template <typename T> |
|---|
| 109 | struct call_traits<T&volatile> |
|---|
| 110 | { |
|---|
| 111 | typedef T& value_type; |
|---|
| 112 | typedef T& reference; |
|---|
| 113 | typedef const T& const_reference; |
|---|
| 114 | typedef T& param_type; // hh removed const |
|---|
| 115 | }; |
|---|
| 116 | template <typename T> |
|---|
| 117 | struct call_traits<T&const volatile> |
|---|
| 118 | { |
|---|
| 119 | typedef T& value_type; |
|---|
| 120 | typedef T& reference; |
|---|
| 121 | typedef const T& const_reference; |
|---|
| 122 | typedef T& param_type; // hh removed const |
|---|
| 123 | }; |
|---|
| 124 | #endif |
|---|
| 125 | #if !defined(BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS) |
|---|
| 126 | template <typename T, std::size_t N> |
|---|
| 127 | struct call_traits<T [N]> |
|---|
| 128 | { |
|---|
| 129 | private: |
|---|
| 130 | typedef T array_type[N]; |
|---|
| 131 | public: |
|---|
| 132 | // degrades array to pointer: |
|---|
| 133 | typedef const T* value_type; |
|---|
| 134 | typedef array_type& reference; |
|---|
| 135 | typedef const array_type& const_reference; |
|---|
| 136 | typedef const T* const param_type; |
|---|
| 137 | }; |
|---|
| 138 | |
|---|
| 139 | template <typename T, std::size_t N> |
|---|
| 140 | struct call_traits<const T [N]> |
|---|
| 141 | { |
|---|
| 142 | private: |
|---|
| 143 | typedef const T array_type[N]; |
|---|
| 144 | public: |
|---|
| 145 | // degrades array to pointer: |
|---|
| 146 | typedef const T* value_type; |
|---|
| 147 | typedef array_type& reference; |
|---|
| 148 | typedef const array_type& const_reference; |
|---|
| 149 | typedef const T* const param_type; |
|---|
| 150 | }; |
|---|
| 151 | #endif |
|---|
| 152 | |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | #endif // BOOST_DETAIL_CALL_TRAITS_HPP |
|---|