]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/ob_call_traits.hpp
2002-05-24 Lars Gullik Bj�nnes <larsbj@birdstep.com>
[lyx.git] / boost / boost / detail / ob_call_traits.hpp
1 //  (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
2 //  Permission to copy, use, modify, sell and
3 //  distribute this software is granted provided this copyright notice appears
4 //  in all copies. This software is provided "as is" without express or implied
5 //  warranty, and with no claim as to its suitability for any purpose.
6
7 //  See http://www.boost.org for most recent version including documentation.
8 //
9 //  Crippled version for crippled compilers:
10 //  see libs/utility/call_traits.htm
11 //
12
13 /* Release notes:
14    01st October 2000:
15       Fixed call_traits on VC6, using "poor man's partial specialisation",
16       using ideas taken from "Generative programming" by Krzysztof Czarnecki 
17       & Ulrich Eisenecker.
18 */
19
20 #ifndef BOOST_OB_CALL_TRAITS_HPP
21 #define BOOST_OB_CALL_TRAITS_HPP
22
23 #ifndef BOOST_CONFIG_HPP
24 #include <boost/config.hpp>
25 #endif
26
27 #ifndef BOOST_ARITHMETIC_TYPE_TRAITS_HPP
28 #include <boost/type_traits/arithmetic_traits.hpp>
29 #endif
30 #ifndef BOOST_COMPOSITE_TYPE_TRAITS_HPP
31 #include <boost/type_traits/composite_traits.hpp>
32 #endif
33
34 namespace boost{
35
36 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
37 //
38 // use member templates to emulate
39 // partial specialisation:
40 //
41 namespace detail{
42
43 template <class T>
44 struct standard_call_traits
45 {
46    typedef T value_type;
47    typedef T& reference;
48    typedef const T& const_reference;
49    typedef const T& param_type;
50 };
51 template <class T>
52 struct simple_call_traits
53 {
54    typedef T value_type;
55    typedef T& reference;
56    typedef const T& const_reference;
57    typedef const T param_type;
58 };
59 template <class T>
60 struct reference_call_traits
61 {
62    typedef T value_type;
63    typedef T reference;
64    typedef T const_reference;
65    typedef T param_type;
66 };
67
68 template <bool pointer, bool arithmetic, bool reference>
69 struct call_traits_chooser
70 {
71    template <class T>
72    struct rebind
73    {
74       typedef standard_call_traits<T> type;
75    };
76 };
77
78 template <>
79 struct call_traits_chooser<true, false, false>
80 {
81    template <class T>
82    struct rebind
83    {
84       typedef simple_call_traits<T> type;
85    };
86 };
87
88 template <>
89 struct call_traits_chooser<false, false, true>
90 {
91    template <class T>
92    struct rebind
93    {
94       typedef reference_call_traits<T> type;
95    };
96 };
97
98 template <bool size_is_small> 
99 struct call_traits_sizeof_chooser2
100 {
101    template <class T>
102    struct small_rebind
103    {
104       typedef simple_call_traits<T> small_type;
105    };
106 };
107
108 template<> 
109 struct call_traits_sizeof_chooser2<false>
110 {
111    template <class T>
112    struct small_rebind
113    {
114       typedef standard_call_traits<T> small_type;
115    };
116 };
117
118 template <>
119 struct call_traits_chooser<false, true, false>
120 {
121    template <class T>
122    struct rebind
123    {
124       enum { sizeof_choice = (sizeof(T) <= sizeof(void*)) };
125       typedef call_traits_sizeof_chooser2<(sizeof(T) <= sizeof(void*))> chooser;
126       typedef typename chooser::template small_rebind<T> bound_type;
127       typedef typename bound_type::small_type type;
128    };
129 };
130
131 } // namespace detail
132 template <typename T>
133 struct call_traits
134 {
135 private:
136     typedef detail::call_traits_chooser<
137          ::boost::is_pointer<T>::value,
138          ::boost::is_arithmetic<T>::value, 
139          ::boost::is_reference<T>::value
140       > chooser;
141    typedef typename chooser::template rebind<T> bound_type;
142    typedef typename bound_type::type call_traits_type;
143 public:
144    typedef typename call_traits_type::value_type       value_type;
145    typedef typename call_traits_type::reference        reference;
146    typedef typename call_traits_type::const_reference  const_reference;
147    typedef typename call_traits_type::param_type       param_type;
148 };
149
150 #else
151 //
152 // sorry call_traits is completely non-functional
153 // blame your broken compiler:
154 //
155
156 template <typename T>
157 struct call_traits
158 {
159    typedef T value_type;
160    typedef T& reference;
161    typedef const T& const_reference;
162    typedef const T& param_type;
163 };
164
165 #endif // member templates
166
167 }
168
169 #endif // BOOST_OB_CALL_TRAITS_HPP