1 // - casts.hpp -- BLambda Library -------------
3 // Copyright (C) 2000 Gary Powell (powellg@amazon.com)
4 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // For more information, see http://www.boost.org
12 // -----------------------------------------------
14 #if !defined(BOOST_LAMBDA_CASTS_HPP)
15 #define BOOST_LAMBDA_CASTS_HPP
17 #include "boost/lambda/detail/suppress_unused.hpp"
18 #include "boost/lambda/core.hpp"
25 template<class Act, class Args>
28 template<class T> class cast_action;
30 template<class T> class static_cast_action;
31 template<class T> class dynamic_cast_action;
32 template<class T> class const_cast_action;
33 template<class T> class reinterpret_cast_action;
40 template<class T> class cast_action<static_cast_action<T> >
43 template<class RET, class Arg1>
44 static RET apply(Arg1 &a1) {
45 return static_cast<RET>(a1);
49 template<class T> class cast_action<dynamic_cast_action<T> > {
51 template<class RET, class Arg1>
52 static RET apply(Arg1 &a1) {
53 return dynamic_cast<RET>(a1);
57 template<class T> class cast_action<const_cast_action<T> > {
59 template<class RET, class Arg1>
60 static RET apply(Arg1 &a1) {
61 return const_cast<RET>(a1);
65 template<class T> class cast_action<reinterpret_cast_action<T> > {
67 template<class RET, class Arg1>
68 static RET apply(Arg1 &a1) {
69 return reinterpret_cast<RET>(a1);
76 template<class RET, class Arg1>
77 static RET apply(Arg1 &a1) {
78 detail::suppress_unused_variable_warnings(a1);
87 template<class RET, class Arg1>
88 static RET apply(Arg1 &a1) {
94 // return types of casting lambda_functors (all "T" type.)
96 template<template <class> class cast_type, class T, class A>
97 struct return_type_N<cast_action< cast_type<T> >, A> {
101 // return type of typeid_action
103 struct return_type_N<typeid_action, A> {
104 typedef std::type_info const & type;
107 // return type of sizeof_action
110 struct return_type_N<sizeof_action, A> {
111 typedef std::size_t type;
115 // the four cast & typeid overloads.
116 // casts can take ordinary variables (not just lambda functors)
119 template <class T, class Arg1>
120 inline const lambda_functor<
122 action<1, cast_action<static_cast_action<T> > >,
123 tuple<typename const_copy_argument <const Arg1>::type>
126 ll_static_cast(const Arg1& a1) {
129 action<1, cast_action<static_cast_action<T> > >,
130 tuple<typename const_copy_argument <const Arg1>::type>
132 ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
136 template <class T, class Arg1>
137 inline const lambda_functor<
139 action<1, cast_action<dynamic_cast_action<T> > >,
140 tuple<typename const_copy_argument <const Arg1>::type>
143 ll_dynamic_cast(const Arg1& a1) {
146 action<1, cast_action<dynamic_cast_action<T> > >,
147 tuple<typename const_copy_argument <const Arg1>::type>
149 ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
153 template <class T, class Arg1>
154 inline const lambda_functor<
156 action<1, cast_action<const_cast_action<T> > >,
157 tuple<typename const_copy_argument <const Arg1>::type>
160 ll_const_cast(const Arg1& a1) {
163 action<1, cast_action<const_cast_action<T> > >,
164 tuple<typename const_copy_argument <const Arg1>::type>
166 ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
170 template <class T, class Arg1>
171 inline const lambda_functor<
173 action<1, cast_action<reinterpret_cast_action<T> > >,
174 tuple<typename const_copy_argument <const Arg1>::type>
177 ll_reinterpret_cast(const Arg1& a1) {
180 action<1, cast_action<reinterpret_cast_action<T> > >,
181 tuple<typename const_copy_argument <const Arg1>::type>
183 ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
187 // can be applied to a normal variable as well (can refer to a polymorphic
189 template <class Arg1>
190 inline const lambda_functor<
192 action<1, typeid_action>,
193 tuple<typename const_copy_argument <const Arg1>::type>
196 ll_typeid(const Arg1& a1) {
199 action<1, typeid_action>,
200 tuple<typename const_copy_argument <const Arg1>::type>
202 ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
205 // sizeof(expression)
206 // Always takes a lambda expression (if not, built in sizeof will do)
207 template <class Arg1>
208 inline const lambda_functor<
210 action<1, sizeof_action>,
211 tuple<lambda_functor<Arg1> >
214 ll_sizeof(const lambda_functor<Arg1>& a1) {
217 action<1, sizeof_action>,
218 tuple<lambda_functor<Arg1> >
220 ( tuple<lambda_functor<Arg1> >(a1));
223 } // namespace lambda