annotate DEPENDENCIES/generic/include/boost/proto/detail/poly_function.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 /// \file poly_function.hpp
Chris@16 3 /// A wrapper that makes a tr1-style function object that handles const
Chris@16 4 /// and non-const refs and reference_wrapper arguments, too, and forwards
Chris@16 5 /// the arguments on to the specified implementation.
Chris@16 6 //
Chris@16 7 // Copyright 2008 Eric Niebler. Distributed under the Boost
Chris@16 8 // Software License, Version 1.0. (See accompanying file
Chris@16 9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 10
Chris@16 11 #ifndef BOOST_PROTO_DETAIL_POLY_FUNCTION_EAN_2008_05_02
Chris@16 12 #define BOOST_PROTO_DETAIL_POLY_FUNCTION_EAN_2008_05_02
Chris@16 13
Chris@16 14 #include <boost/ref.hpp>
Chris@16 15 #include <boost/mpl/bool.hpp>
Chris@16 16 #include <boost/mpl/void.hpp>
Chris@16 17 #include <boost/mpl/size_t.hpp>
Chris@16 18 #include <boost/mpl/eval_if.hpp>
Chris@16 19 #include <boost/preprocessor/cat.hpp>
Chris@16 20 #include <boost/preprocessor/facilities/intercept.hpp>
Chris@16 21 #include <boost/preprocessor/iteration/iterate.hpp>
Chris@16 22 #include <boost/preprocessor/repetition/enum.hpp>
Chris@16 23 #include <boost/preprocessor/repetition/enum_params.hpp>
Chris@16 24 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
Chris@16 25 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
Chris@16 26 #include <boost/proto/proto_fwd.hpp>
Chris@16 27 #include <boost/proto/detail/is_noncopyable.hpp>
Chris@16 28
Chris@16 29 #ifdef _MSC_VER
Chris@16 30 # pragma warning(push)
Chris@16 31 # pragma warning(disable: 4181) // const applied to reference type
Chris@16 32 #endif
Chris@16 33
Chris@16 34 namespace boost { namespace proto { namespace detail
Chris@16 35 {
Chris@16 36
Chris@16 37 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 38 template<typename T>
Chris@16 39 struct normalize_arg
Chris@16 40 {
Chris@16 41 typedef typename mpl::if_c<is_noncopyable<T>::value, T &, T>::type type;
Chris@16 42 typedef T &reference;
Chris@16 43 };
Chris@16 44
Chris@16 45 template<typename T>
Chris@16 46 struct normalize_arg<T const>
Chris@16 47 {
Chris@16 48 typedef typename mpl::if_c<is_noncopyable<T>::value, T const &, T>::type type;
Chris@16 49 typedef T const &reference;
Chris@16 50 };
Chris@16 51
Chris@16 52 template<typename T>
Chris@16 53 struct normalize_arg<T &>
Chris@16 54 {
Chris@16 55 typedef typename mpl::if_c<is_noncopyable<T>::value, T &, T>::type type;
Chris@16 56 typedef T &reference;
Chris@16 57 };
Chris@16 58
Chris@16 59 template<typename T>
Chris@16 60 struct normalize_arg<T const &>
Chris@16 61 {
Chris@16 62 typedef typename mpl::if_c<is_noncopyable<T>::value, T const &, T>::type type;
Chris@16 63 typedef T const &reference;
Chris@16 64 };
Chris@16 65
Chris@16 66 template<typename T>
Chris@16 67 struct normalize_arg<boost::reference_wrapper<T> >
Chris@16 68 {
Chris@16 69 typedef T &type;
Chris@16 70 typedef T &reference;
Chris@16 71 };
Chris@16 72
Chris@16 73 template<typename T>
Chris@16 74 struct normalize_arg<boost::reference_wrapper<T> const>
Chris@16 75 {
Chris@16 76 typedef T &type;
Chris@16 77 typedef T &reference;
Chris@16 78 };
Chris@16 79
Chris@16 80 template<typename T>
Chris@16 81 struct normalize_arg<boost::reference_wrapper<T> &>
Chris@16 82 {
Chris@16 83 typedef T &type;
Chris@16 84 typedef T &reference;
Chris@16 85 };
Chris@16 86
Chris@16 87 template<typename T>
Chris@16 88 struct normalize_arg<boost::reference_wrapper<T> const &>
Chris@16 89 {
Chris@16 90 typedef T &type;
Chris@16 91 typedef T &reference;
Chris@16 92 };
Chris@16 93
Chris@16 94 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 95 template<typename T>
Chris@16 96 struct arg
Chris@16 97 {
Chris@16 98 typedef T const &type;
Chris@16 99
Chris@16 100 arg(type t)
Chris@16 101 : value(t)
Chris@16 102 {}
Chris@16 103
Chris@16 104 operator type() const
Chris@16 105 {
Chris@16 106 return this->value;
Chris@16 107 }
Chris@16 108
Chris@16 109 type operator()() const
Chris@16 110 {
Chris@16 111 return this->value;
Chris@16 112 }
Chris@16 113
Chris@16 114 private:
Chris@16 115 arg &operator =(arg const &);
Chris@16 116 type value;
Chris@16 117 };
Chris@16 118
Chris@16 119 template<typename T>
Chris@16 120 struct arg<T &>
Chris@16 121 {
Chris@16 122 typedef T &type;
Chris@16 123
Chris@16 124 arg(type t)
Chris@16 125 : value(t)
Chris@16 126 {}
Chris@16 127
Chris@16 128 operator type() const
Chris@16 129 {
Chris@16 130 return this->value;
Chris@16 131 }
Chris@16 132
Chris@16 133 type operator()() const
Chris@16 134 {
Chris@16 135 return this->value;
Chris@16 136 }
Chris@16 137
Chris@16 138 private:
Chris@16 139 arg &operator =(arg const &);
Chris@16 140 type value;
Chris@16 141 };
Chris@16 142
Chris@16 143 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 144 template<typename T, typename Void = void>
Chris@16 145 struct is_poly_function
Chris@16 146 : mpl::false_
Chris@16 147 {};
Chris@16 148
Chris@16 149 template<typename T>
Chris@16 150 struct is_poly_function<T, typename T::is_poly_function_base_>
Chris@16 151 : mpl::true_
Chris@16 152 {};
Chris@16 153
Chris@16 154 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 155 #define BOOST_PROTO_POLY_FUNCTION() \
Chris@16 156 typedef void is_poly_function_base_; \
Chris@16 157 /**/
Chris@16 158
Chris@16 159 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 160 struct poly_function_base
Chris@16 161 {
Chris@16 162 /// INTERNAL ONLY
Chris@16 163 BOOST_PROTO_POLY_FUNCTION()
Chris@16 164 };
Chris@16 165
Chris@16 166 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 167 template<typename Derived, typename NullaryResult = void>
Chris@16 168 struct poly_function
Chris@16 169 : poly_function_base
Chris@16 170 {
Chris@16 171 template<typename Sig>
Chris@16 172 struct result;
Chris@16 173
Chris@16 174 template<typename This>
Chris@16 175 struct result<This()>
Chris@16 176 : Derived::template impl<>
Chris@16 177 {
Chris@16 178 typedef typename result::result_type type;
Chris@16 179 };
Chris@16 180
Chris@16 181 NullaryResult operator()() const
Chris@16 182 {
Chris@16 183 result<Derived const()> impl;
Chris@16 184 return impl();
Chris@16 185 }
Chris@16 186
Chris@16 187 #include <boost/proto/detail/poly_function_funop.hpp>
Chris@16 188 };
Chris@16 189
Chris@16 190 template<typename T>
Chris@16 191 struct wrap_t;
Chris@16 192
Chris@16 193 typedef char poly_function_t;
Chris@16 194 typedef char (&mono_function_t)[2];
Chris@16 195 typedef char (&unknown_function_t)[3];
Chris@16 196
Chris@16 197 template<typename T> poly_function_t test_poly_function(T *, wrap_t<typename T::is_poly_function_base_> * = 0);
Chris@16 198 template<typename T> mono_function_t test_poly_function(T *, wrap_t<typename T::result_type> * = 0);
Chris@16 199 template<typename T> unknown_function_t test_poly_function(T *, ...);
Chris@16 200
Chris@16 201 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 202 template<typename Fun, typename Sig, typename Switch = mpl::size_t<sizeof(test_poly_function<Fun>(0,0))> >
Chris@16 203 struct poly_function_traits
Chris@16 204 {
Chris@16 205 typedef typename Fun::template result<Sig>::type result_type;
Chris@16 206 typedef Fun function_type;
Chris@16 207 };
Chris@16 208
Chris@16 209 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 210 template<typename Fun, typename Sig>
Chris@16 211 struct poly_function_traits<Fun, Sig, mpl::size_t<sizeof(mono_function_t)> >
Chris@16 212 {
Chris@16 213 typedef typename Fun::result_type result_type;
Chris@16 214 typedef Fun function_type;
Chris@16 215 };
Chris@16 216
Chris@16 217 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 218 template<typename PolyFunSig, bool IsPolyFunction>
Chris@16 219 struct as_mono_function_impl;
Chris@16 220
Chris@16 221 ////////////////////////////////////////////////////////////////////////////////////////////////
Chris@16 222 template<typename PolyFunSig>
Chris@16 223 struct as_mono_function;
Chris@16 224
Chris@16 225 #include <boost/proto/detail/poly_function_traits.hpp>
Chris@16 226
Chris@16 227 }}} // namespace boost::proto::detail
Chris@16 228
Chris@16 229 #ifdef _MSC_VER
Chris@16 230 # pragma warning(pop)
Chris@16 231 #endif
Chris@16 232
Chris@16 233 #endif
Chris@16 234