blob: 410f4ae4e46daae0bddd74918df8efa2e29067ff [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001// (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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070018#ifndef NDNBOOST_DETAIL_CALL_TRAITS_HPP
19#define NDNBOOST_DETAIL_CALL_TRAITS_HPP
Jeff Thompsona28eed82013-08-22 16:21:10 -070020
Jeff Thompson3d613fd2013-10-15 15:39:04 -070021#ifndef NDNBOOST_CONFIG_HPP
Jeff Thompsona28eed82013-08-22 16:21:10 -070022#include <ndnboost/config.hpp>
23#endif
24#include <cstddef>
25
26#include <ndnboost/type_traits/is_arithmetic.hpp>
27#include <ndnboost/type_traits/is_enum.hpp>
28#include <ndnboost/type_traits/is_pointer.hpp>
29#include <ndnboost/detail/workaround.hpp>
30
31namespace ndnboost{
32
33namespace detail{
34
35template <typename T, bool small_>
36struct ct_imp2
37{
38 typedef const T& param_type;
39};
40
41template <typename T>
42struct ct_imp2<T, true>
43{
44 typedef const T param_type;
45};
46
47template <typename T, bool isp, bool b1, bool b2>
48struct ct_imp
49{
50 typedef const T& param_type;
51};
52
53template <typename T, bool isp, bool b2>
54struct ct_imp<T, isp, true, b2>
55{
56 typedef typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type param_type;
57};
58
59template <typename T, bool isp, bool b1>
60struct ct_imp<T, isp, b1, true>
61{
62 typedef typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type param_type;
63};
64
65template <typename T, bool b1, bool b2>
66struct ct_imp<T, true, b1, b2>
67{
68 typedef const T param_type;
69};
70
71}
72
73template <typename T>
74struct call_traits
75{
76public:
77 typedef T value_type;
78 typedef T& reference;
79 typedef const T& const_reference;
80 //
81 // C++ Builder workaround: we should be able to define a compile time
82 // constant and pass that as a single template parameter to ct_imp<T,bool>,
83 // however compiler bugs prevent this - instead pass three bool's to
84 // ct_imp<T,bool,bool,bool> and add an extra partial specialisation
85 // of ct_imp to handle the logic. (JM)
86 typedef typename ndnboost::detail::ct_imp<
87 T,
88 ::ndnboost::is_pointer<T>::value,
89 ::ndnboost::is_arithmetic<T>::value,
90 ::ndnboost::is_enum<T>::value
91 >::param_type param_type;
92};
93
94template <typename T>
95struct call_traits<T&>
96{
97 typedef T& value_type;
98 typedef T& reference;
99 typedef const T& const_reference;
100 typedef T& param_type; // hh removed const
101};
102
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700103#if NDNBOOST_WORKAROUND( __BORLANDC__, < 0x5A0 )
Jeff Thompsona28eed82013-08-22 16:21:10 -0700104// these are illegal specialisations; cv-qualifies applied to
105// references have no effect according to [8.3.2p1],
106// C++ Builder requires them though as it treats cv-qualified
107// references as distinct types...
108template <typename T>
109struct call_traits<T&const>
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};
116template <typename T>
117struct call_traits<T&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};
124template <typename T>
125struct call_traits<T&const volatile>
126{
127 typedef T& value_type;
128 typedef T& reference;
129 typedef const T& const_reference;
130 typedef T& param_type; // hh removed const
131};
132
133template <typename T>
134struct call_traits< T * >
135{
136 typedef T * value_type;
137 typedef T * & reference;
138 typedef T * const & const_reference;
139 typedef T * const param_type; // hh removed const
140};
141#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700142#if !defined(NDNBOOST_NO_ARRAY_TYPE_SPECIALIZATIONS)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700143template <typename T, std::size_t N>
144struct call_traits<T [N]>
145{
146private:
147 typedef T array_type[N];
148public:
149 // degrades array to pointer:
150 typedef const T* value_type;
151 typedef array_type& reference;
152 typedef const array_type& const_reference;
153 typedef const T* const param_type;
154};
155
156template <typename T, std::size_t N>
157struct call_traits<const T [N]>
158{
159private:
160 typedef const T array_type[N];
161public:
162 // degrades array to pointer:
163 typedef const T* value_type;
164 typedef array_type& reference;
165 typedef const array_type& const_reference;
166 typedef const T* const param_type;
167};
168#endif
169
170}
171
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700172#endif // NDNBOOST_DETAIL_CALL_TRAITS_HPP