Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/parameter/aux_/cast.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Copyright Daniel Wallin 2006. Use, modification and distribution is | |
2 // subject to the Boost Software License, Version 1.0. (See accompanying | |
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
4 | |
5 #ifndef BOOST_PARAMETER_CAST_060902_HPP | |
6 # define BOOST_PARAMETER_CAST_060902_HPP | |
7 | |
8 # include <boost/detail/workaround.hpp> | |
9 | |
10 # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ | |
11 && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) | |
12 # include <boost/type_traits/add_reference.hpp> | |
13 # include <boost/type_traits/remove_const.hpp> | |
14 # endif | |
15 | |
16 namespace boost { namespace parameter { namespace aux { | |
17 | |
18 struct use_default_tag {}; | |
19 | |
20 # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ | |
21 || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) | |
22 | |
23 # define BOOST_PARAMETER_FUNCTION_CAST(value, predicate) value | |
24 | |
25 # else | |
26 | |
27 // Handles possible implicit casts. Used by preprocessor.hpp to | |
28 // normalize user input. | |
29 // | |
30 // cast<void*>::execute() is identity | |
31 // cast<void*(X)>::execute() is identity | |
32 // cast<void(X)>::execute() casts to X | |
33 // | |
34 // preprocessor.hpp uses this like this: | |
35 // | |
36 // #define X(value, predicate) | |
37 // cast<void predicate>::execute(value) | |
38 // | |
39 // X(something, *) | |
40 // X(something, *(predicate)) | |
41 // X(something, (int)) | |
42 | |
43 template <class T, class Args> | |
44 struct cast; | |
45 | |
46 template <class Args> | |
47 struct cast<void*, Args> | |
48 { | |
49 static use_default_tag execute(use_default_tag) | |
50 { | |
51 return use_default_tag(); | |
52 } | |
53 | |
54 static use_default_tag remove_const(use_default_tag) | |
55 { | |
56 return use_default_tag(); | |
57 } | |
58 | |
59 template <class U> | |
60 static U& execute(U& value) | |
61 { | |
62 return value; | |
63 } | |
64 | |
65 template <class U> | |
66 static U& remove_const(U& x) | |
67 { | |
68 return x; | |
69 } | |
70 }; | |
71 | |
72 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) | |
73 | |
74 typedef void* voidstar; | |
75 | |
76 template <class T, class Args> | |
77 struct cast<voidstar(T), Args> | |
78 : cast<void*, Args> | |
79 { | |
80 }; | |
81 | |
82 #else | |
83 | |
84 template <class T, class Args> | |
85 struct cast<void*(T), Args> | |
86 : cast<void*, Args> | |
87 { | |
88 }; | |
89 | |
90 #endif | |
91 | |
92 // This is a hack used in cast<> to turn the user supplied type, | |
93 // which may or may not be a placeholder expression into one, so | |
94 // that it will be properly evaluated by mpl::apply. | |
95 template <class T, class Dummy = mpl::_1> | |
96 struct as_placeholder_expr | |
97 { | |
98 typedef T type; | |
99 }; | |
100 | |
101 template <class T, class Args> | |
102 struct cast<void(T), Args> | |
103 { | |
104 typedef typename mpl::apply2< | |
105 as_placeholder_expr<T>, Args, Args>::type type0; | |
106 | |
107 typedef typename boost::add_reference< | |
108 typename boost::remove_const<type0>::type | |
109 >::type reference; | |
110 | |
111 static use_default_tag execute(use_default_tag) | |
112 { | |
113 return use_default_tag(); | |
114 } | |
115 | |
116 static use_default_tag remove_const(use_default_tag) | |
117 { | |
118 return use_default_tag(); | |
119 } | |
120 | |
121 static type0 execute(type0 value) | |
122 { | |
123 return value; | |
124 } | |
125 | |
126 template <class U> | |
127 static reference remove_const(U const& x) | |
128 { | |
129 return const_cast<reference>(x); | |
130 } | |
131 }; | |
132 | |
133 # define BOOST_PARAMETER_FUNCTION_CAST(value, predicate, args) \ | |
134 boost::parameter::aux::cast<void predicate, args>::remove_const( \ | |
135 boost::parameter::aux::cast<void predicate, args>::execute(value) \ | |
136 ) | |
137 | |
138 # endif | |
139 | |
140 }}} // namespace boost::parameter::aux | |
141 | |
142 #endif // BOOST_PARAMETER_CAST_060902_HPP | |
143 |