os/ossrv/ossrv_pub/boost_apis/boost/lambda/casts.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/lambda/casts.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,219 @@
     1.4 +// - casts.hpp -- BLambda Library -------------
     1.5 +//
     1.6 +// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
     1.7 +// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
     1.8 +//
     1.9 +// Distributed under the Boost Software License, Version 1.0. (See
    1.10 +// accompanying file LICENSE_1_0.txt or copy at
    1.11 +// http://www.boost.org/LICENSE_1_0.txt)
    1.12 +//
    1.13 +// For more information, see http://www.boost.org
    1.14 +
    1.15 +// -----------------------------------------------
    1.16 +
    1.17 +#if !defined(BOOST_LAMBDA_CASTS_HPP)
    1.18 +#define BOOST_LAMBDA_CASTS_HPP
    1.19 +
    1.20 +#include <typeinfo>
    1.21 +
    1.22 +namespace boost { 
    1.23 +namespace lambda {
    1.24 +
    1.25 +template<class T> class cast_action;
    1.26 +
    1.27 +template<class T> class static_cast_action;
    1.28 +template<class T> class dynamic_cast_action;
    1.29 +template<class T> class const_cast_action;
    1.30 +template<class T> class reinterpret_cast_action;
    1.31 +
    1.32 +class typeid_action;
    1.33 +class sizeof_action;
    1.34 +
    1.35 +// Cast actions
    1.36 +
    1.37 +template<class T> class cast_action<static_cast_action<T> > 
    1.38 +{
    1.39 +public:
    1.40 +  template<class RET, class Arg1>
    1.41 +  static RET apply(Arg1 &a1) {
    1.42 +    return static_cast<RET>(a1);
    1.43 +  }
    1.44 +};
    1.45 +
    1.46 +template<class T> class cast_action<dynamic_cast_action<T> > {
    1.47 +public:
    1.48 +  template<class RET, class Arg1>
    1.49 +  static RET apply(Arg1 &a1) {
    1.50 +    return dynamic_cast<RET>(a1);
    1.51 +  }
    1.52 +};
    1.53 +
    1.54 +template<class T> class cast_action<const_cast_action<T> > {
    1.55 +public:
    1.56 +  template<class RET, class Arg1>
    1.57 +  static RET apply(Arg1 &a1) {
    1.58 +    return const_cast<RET>(a1);
    1.59 +  }
    1.60 +};
    1.61 +
    1.62 +template<class T> class cast_action<reinterpret_cast_action<T> > {
    1.63 +public:
    1.64 +  template<class RET, class Arg1>
    1.65 +  static RET apply(Arg1 &a1) {
    1.66 +    return reinterpret_cast<RET>(a1);
    1.67 +  }
    1.68 +};
    1.69 +
    1.70 +  // typedid action
    1.71 +class typeid_action {
    1.72 +public:
    1.73 +  template<class RET, class Arg1>
    1.74 +  static RET apply(Arg1 &a1) {
    1.75 +    return typeid(a1);
    1.76 +  }
    1.77 +};
    1.78 +
    1.79 +// sizeof action
    1.80 +class sizeof_action
    1.81 +{
    1.82 +public:
    1.83 +  template<class RET, class Arg1>
    1.84 +  static RET apply(Arg1 &a1) {
    1.85 +    return sizeof(a1);
    1.86 +  }
    1.87 +};
    1.88 +
    1.89 +
    1.90 +// return types of casting lambda_functors (all "T" type.)
    1.91 +
    1.92 +template<template <class> class cast_type, class T, class A>
    1.93 +struct return_type_N<cast_action< cast_type<T> >, A> { 
    1.94 +  typedef T type;
    1.95 +};
    1.96 +
    1.97 +// return type of typeid_action
    1.98 +template<class A>
    1.99 +struct return_type_N<typeid_action, A> { 
   1.100 +  typedef std::type_info const & type;
   1.101 +};
   1.102 +
   1.103 +// return type of sizeof_action
   1.104 +
   1.105 +template<class A>
   1.106 +struct return_type_N<sizeof_action, A> { 
   1.107 +  typedef std::size_t type;
   1.108 +};
   1.109 +
   1.110 +
   1.111 +// the four cast & typeid overloads.
   1.112 +// casts can take ordinary variables (not just lambda functors)
   1.113 +
   1.114 +// static_cast 
   1.115 +template <class T, class Arg1>
   1.116 +inline const lambda_functor<
   1.117 +  lambda_functor_base<
   1.118 +    action<1, cast_action<static_cast_action<T> > >, 
   1.119 +    tuple<typename const_copy_argument <const Arg1>::type>
   1.120 +  > 
   1.121 +>
   1.122 +ll_static_cast(const Arg1& a1) { 
   1.123 +  return 
   1.124 +    lambda_functor_base<
   1.125 +      action<1, cast_action<static_cast_action<T> > >, 
   1.126 +      tuple<typename const_copy_argument <const Arg1>::type> 
   1.127 +    >
   1.128 +  ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
   1.129 +}
   1.130 +
   1.131 +// dynamic_cast
   1.132 +template <class T, class Arg1>
   1.133 +inline const lambda_functor<
   1.134 +  lambda_functor_base<
   1.135 +    action<1, cast_action<dynamic_cast_action<T> > >, 
   1.136 +    tuple<typename const_copy_argument <const Arg1>::type>
   1.137 +  > 
   1.138 +>
   1.139 +ll_dynamic_cast(const Arg1& a1) { 
   1.140 +  return 
   1.141 +    lambda_functor_base<
   1.142 +      action<1, cast_action<dynamic_cast_action<T> > >, 
   1.143 +      tuple<typename const_copy_argument <const Arg1>::type>
   1.144 +    > 
   1.145 +  ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
   1.146 +}
   1.147 +
   1.148 +// const_cast
   1.149 +template <class T, class Arg1>
   1.150 +inline const lambda_functor<
   1.151 +  lambda_functor_base<
   1.152 +    action<1, cast_action<const_cast_action<T> > >, 
   1.153 +    tuple<typename const_copy_argument <const Arg1>::type>
   1.154 +  > 
   1.155 +>
   1.156 +ll_const_cast(const Arg1& a1) { 
   1.157 +  return 
   1.158 +      lambda_functor_base<
   1.159 +        action<1, cast_action<const_cast_action<T> > >, 
   1.160 +        tuple<typename const_copy_argument <const Arg1>::type>
   1.161 +      > 
   1.162 +      ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
   1.163 +}
   1.164 +
   1.165 +// reinterpret_cast
   1.166 +template <class T, class Arg1>
   1.167 +inline const lambda_functor<
   1.168 +  lambda_functor_base<
   1.169 +    action<1, cast_action<reinterpret_cast_action<T> > >, 
   1.170 +    tuple<typename const_copy_argument <const Arg1>::type>
   1.171 +  > 
   1.172 +>
   1.173 +ll_reinterpret_cast(const Arg1& a1) { 
   1.174 +  return 
   1.175 +      lambda_functor_base<
   1.176 +        action<1, cast_action<reinterpret_cast_action<T> > >, 
   1.177 +        tuple<typename const_copy_argument <const Arg1>::type> 
   1.178 +      > 
   1.179 +      ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
   1.180 +}
   1.181 +
   1.182 +// typeid
   1.183 +// can be applied to a normal variable as well (can refer to a polymorphic
   1.184 +// class object)
   1.185 +template <class Arg1>
   1.186 +inline const lambda_functor<
   1.187 +  lambda_functor_base<
   1.188 +    action<1, typeid_action>, 
   1.189 +    tuple<typename const_copy_argument <const Arg1>::type>
   1.190 +  > 
   1.191 +>
   1.192 +ll_typeid(const Arg1& a1) { 
   1.193 +  return 
   1.194 +      lambda_functor_base<
   1.195 +        action<1, typeid_action>, 
   1.196 +        tuple<typename const_copy_argument <const Arg1>::type>
   1.197 +      > 
   1.198 +      ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
   1.199 +}
   1.200 +
   1.201 +// sizeof(expression)
   1.202 +// Always takes a lambda expression (if not, built in sizeof will do)
   1.203 +template <class Arg1>
   1.204 +inline const lambda_functor<
   1.205 +  lambda_functor_base<
   1.206 +    action<1, sizeof_action>, 
   1.207 +    tuple<lambda_functor<Arg1> >
   1.208 +  > 
   1.209 +>
   1.210 +ll_sizeof(const lambda_functor<Arg1>& a1) { 
   1.211 +  return 
   1.212 +      lambda_functor_base<
   1.213 +        action<1, sizeof_action>, 
   1.214 +        tuple<lambda_functor<Arg1> >
   1.215 +      > 
   1.216 +      ( tuple<lambda_functor<Arg1> >(a1));
   1.217 +}
   1.218 +
   1.219 +} // namespace lambda 
   1.220 +} // namespace boost
   1.221 +
   1.222 +#endif