annotate DEPENDENCIES/generic/include/boost/proto/generate.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 /// \file generate.hpp
Chris@16 3 /// Contains definition of generate\<\> class template, which end users can
Chris@16 4 /// specialize for generating domain-specific expression wrappers.
Chris@16 5 //
Chris@16 6 // Copyright 2008 Eric Niebler. Distributed under the Boost
Chris@16 7 // Software License, Version 1.0. (See accompanying file
Chris@16 8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9
Chris@16 10 #ifndef BOOST_PROTO_GENERATE_HPP_EAN_02_13_2007
Chris@16 11 #define BOOST_PROTO_GENERATE_HPP_EAN_02_13_2007
Chris@16 12
Chris@16 13 #include <boost/config.hpp>
Chris@16 14 #include <boost/version.hpp>
Chris@16 15 #include <boost/preprocessor/cat.hpp>
Chris@16 16 #include <boost/preprocessor/iteration/iterate.hpp>
Chris@16 17 #include <boost/preprocessor/facilities/intercept.hpp>
Chris@16 18 #include <boost/preprocessor/repetition/enum_params.hpp>
Chris@16 19 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
Chris@16 20 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
Chris@16 21 #include <boost/mpl/bool.hpp>
Chris@16 22 #include <boost/utility/enable_if.hpp>
Chris@16 23 #include <boost/utility/result_of.hpp>
Chris@16 24 #include <boost/proto/proto_fwd.hpp>
Chris@16 25 #include <boost/proto/args.hpp>
Chris@16 26
Chris@101 27 #if defined(_MSC_VER)
Chris@16 28 # pragma warning(push)
Chris@16 29 # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined
Chris@16 30 #endif
Chris@16 31
Chris@16 32 namespace boost { namespace proto
Chris@16 33 {
Chris@16 34
Chris@16 35 namespace detail
Chris@16 36 {
Chris@16 37 template<typename Expr>
Chris@16 38 struct by_value_generator_;
Chris@16 39
Chris@16 40 template<typename Tag, typename Arg>
Chris@16 41 struct by_value_generator_<proto::expr<Tag, term<Arg>, 0> >
Chris@16 42 {
Chris@16 43 typedef
Chris@16 44 proto::expr<
Chris@16 45 Tag
Chris@16 46 , term<typename detail::term_traits<Arg>::value_type>
Chris@16 47 , 0
Chris@16 48 >
Chris@16 49 type;
Chris@16 50
Chris@16 51 BOOST_FORCEINLINE
Chris@16 52 static type const call(proto::expr<Tag, term<Arg>, 0> const &e)
Chris@16 53 {
Chris@16 54 type that = {e.child0};
Chris@16 55 return that;
Chris@16 56 }
Chris@16 57 };
Chris@16 58
Chris@16 59 template<typename Tag, typename Arg>
Chris@16 60 struct by_value_generator_<proto::basic_expr<Tag, term<Arg>, 0> >
Chris@16 61 {
Chris@16 62 typedef
Chris@16 63 proto::basic_expr<
Chris@16 64 Tag
Chris@16 65 , term<typename detail::term_traits<Arg>::value_type>
Chris@16 66 , 0
Chris@16 67 >
Chris@16 68 type;
Chris@16 69
Chris@16 70 BOOST_FORCEINLINE
Chris@16 71 static type const call(proto::basic_expr<Tag, term<Arg>, 0> const &e)
Chris@16 72 {
Chris@16 73 type that = {e.child0};
Chris@16 74 return that;
Chris@16 75 }
Chris@16 76 };
Chris@16 77
Chris@16 78 // Include the other specializations of by_value_generator_
Chris@16 79 #include <boost/proto/detail/generate_by_value.hpp>
Chris@16 80 }
Chris@16 81
Chris@16 82 /// \brief Annotate a generator to indicate that it would
Chris@16 83 /// prefer to be passed instances of \c proto::basic_expr\<\> rather
Chris@16 84 /// than \c proto::expr\<\>. <tt>use_basic_expr\<Generator\></tt> is
Chris@16 85 /// itself a generator.
Chris@16 86 ///
Chris@16 87 template<typename Generator>
Chris@16 88 struct use_basic_expr
Chris@16 89 : Generator
Chris@16 90 {
Chris@16 91 BOOST_PROTO_USE_BASIC_EXPR()
Chris@16 92 };
Chris@16 93
Chris@16 94 /// \brief A simple generator that passes an expression
Chris@16 95 /// through unchanged.
Chris@16 96 ///
Chris@16 97 /// Generators are intended for use as the first template parameter
Chris@16 98 /// to the \c domain\<\> class template and control if and how
Chris@16 99 /// expressions within that domain are to be customized.
Chris@16 100 /// The \c default_generator makes no modifications to the expressions
Chris@16 101 /// passed to it.
Chris@16 102 struct default_generator
Chris@16 103 {
Chris@16 104 BOOST_PROTO_CALLABLE()
Chris@16 105
Chris@16 106 template<typename Sig>
Chris@16 107 struct result;
Chris@16 108
Chris@16 109 template<typename This, typename Expr>
Chris@16 110 struct result<This(Expr)>
Chris@16 111 {
Chris@16 112 typedef Expr type;
Chris@16 113 };
Chris@16 114
Chris@16 115 /// \param expr A Proto expression
Chris@16 116 /// \return expr
Chris@16 117 template<typename Expr>
Chris@16 118 BOOST_FORCEINLINE
Chris@16 119 BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(Expr, Expr const &)
Chris@16 120 operator ()(Expr const &e) const
Chris@16 121 {
Chris@16 122 return e;
Chris@16 123 }
Chris@16 124 };
Chris@16 125
Chris@16 126 /// \brief A simple generator that passes an expression
Chris@16 127 /// through unchanged and specifies a preference for
Chris@16 128 /// \c proto::basic_expr\<\> over \c proto::expr\<\>.
Chris@16 129 ///
Chris@16 130 /// Generators are intended for use as the first template parameter
Chris@16 131 /// to the \c domain\<\> class template and control if and how
Chris@16 132 /// expressions within that domain are to be customized.
Chris@16 133 /// The \c default_generator makes no modifications to the expressions
Chris@16 134 /// passed to it.
Chris@16 135 struct basic_default_generator
Chris@16 136 : proto::use_basic_expr<default_generator>
Chris@16 137 {};
Chris@16 138
Chris@16 139 /// \brief A generator that wraps expressions passed
Chris@16 140 /// to it in the specified extension wrapper.
Chris@16 141 ///
Chris@16 142 /// Generators are intended for use as the first template parameter
Chris@16 143 /// to the \c domain\<\> class template and control if and how
Chris@16 144 /// expressions within that domain are to be customized.
Chris@16 145 /// \c generator\<\> wraps each expression passed to it in
Chris@16 146 /// the \c Extends\<\> wrapper.
Chris@16 147 template<template<typename> class Extends>
Chris@16 148 struct generator
Chris@16 149 {
Chris@16 150 BOOST_PROTO_CALLABLE()
Chris@16 151 BOOST_PROTO_USE_BASIC_EXPR()
Chris@16 152
Chris@16 153 template<typename Sig>
Chris@16 154 struct result;
Chris@16 155
Chris@16 156 template<typename This, typename Expr>
Chris@16 157 struct result<This(Expr)>
Chris@16 158 {
Chris@16 159 typedef Extends<Expr> type;
Chris@16 160 };
Chris@16 161
Chris@16 162 template<typename This, typename Expr>
Chris@16 163 struct result<This(Expr &)>
Chris@16 164 {
Chris@16 165 typedef Extends<Expr> type;
Chris@16 166 };
Chris@16 167
Chris@16 168 template<typename This, typename Expr>
Chris@16 169 struct result<This(Expr const &)>
Chris@16 170 {
Chris@16 171 typedef Extends<Expr> type;
Chris@16 172 };
Chris@16 173
Chris@16 174 /// \param expr A Proto expression
Chris@16 175 /// \return Extends<Expr>(expr)
Chris@16 176 template<typename Expr>
Chris@16 177 BOOST_FORCEINLINE
Chris@16 178 Extends<Expr> operator ()(Expr const &e) const
Chris@16 179 {
Chris@16 180 return Extends<Expr>(e);
Chris@16 181 }
Chris@16 182 };
Chris@16 183
Chris@16 184 /// \brief A generator that wraps expressions passed
Chris@16 185 /// to it in the specified extension wrapper and uses
Chris@16 186 /// aggregate initialization for the wrapper.
Chris@16 187 ///
Chris@16 188 /// Generators are intended for use as the first template parameter
Chris@16 189 /// to the \c domain\<\> class template and control if and how
Chris@16 190 /// expressions within that domain are to be customized.
Chris@16 191 /// \c pod_generator\<\> wraps each expression passed to it in
Chris@16 192 /// the \c Extends\<\> wrapper, and uses aggregate initialzation
Chris@16 193 /// for the wrapped object.
Chris@16 194 template<template<typename> class Extends>
Chris@16 195 struct pod_generator
Chris@16 196 {
Chris@16 197 BOOST_PROTO_CALLABLE()
Chris@16 198 BOOST_PROTO_USE_BASIC_EXPR()
Chris@16 199
Chris@16 200 template<typename Sig>
Chris@16 201 struct result;
Chris@16 202
Chris@16 203 template<typename This, typename Expr>
Chris@16 204 struct result<This(Expr)>
Chris@16 205 {
Chris@16 206 typedef Extends<Expr> type;
Chris@16 207 };
Chris@16 208
Chris@16 209 template<typename This, typename Expr>
Chris@16 210 struct result<This(Expr &)>
Chris@16 211 {
Chris@16 212 typedef Extends<Expr> type;
Chris@16 213 };
Chris@16 214
Chris@16 215 template<typename This, typename Expr>
Chris@16 216 struct result<This(Expr const &)>
Chris@16 217 {
Chris@16 218 typedef Extends<Expr> type;
Chris@16 219 };
Chris@16 220
Chris@16 221 /// \param expr The expression to wrap
Chris@16 222 /// \return <tt>Extends\<Expr\> that = {expr}; return that;</tt>
Chris@16 223 template<typename Expr>
Chris@16 224 BOOST_FORCEINLINE
Chris@16 225 Extends<Expr> operator ()(Expr const &e) const
Chris@16 226 {
Chris@16 227 Extends<Expr> that = {e};
Chris@16 228 return that;
Chris@16 229 }
Chris@16 230
Chris@16 231 // Work-around for:
Chris@16 232 // https://connect.microsoft.com/VisualStudio/feedback/details/765449/codegen-stack-corruption-using-runtime-checks-when-aggregate-initializing-struct
Chris@16 233 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1700))
Chris@16 234 template<typename Class, typename Member>
Chris@16 235 BOOST_FORCEINLINE
Chris@16 236 Extends<expr<tag::terminal, proto::term<Member Class::*> > > operator ()(expr<tag::terminal, proto::term<Member Class::*> > const &e) const
Chris@16 237 {
Chris@16 238 Extends<expr<tag::terminal, proto::term<Member Class::*> > > that;
Chris@16 239 proto::value(that.proto_expr_) = proto::value(e);
Chris@16 240 return that;
Chris@16 241 }
Chris@16 242
Chris@16 243 template<typename Class, typename Member>
Chris@16 244 BOOST_FORCEINLINE
Chris@16 245 Extends<basic_expr<tag::terminal, proto::term<Member Class::*> > > operator ()(basic_expr<tag::terminal, proto::term<Member Class::*> > const &e) const
Chris@16 246 {
Chris@16 247 Extends<basic_expr<tag::terminal, proto::term<Member Class::*> > > that;
Chris@16 248 proto::value(that.proto_expr_) = proto::value(e);
Chris@16 249 return that;
Chris@16 250 }
Chris@16 251 #endif
Chris@16 252 };
Chris@16 253
Chris@16 254 /// \brief A generator that replaces child nodes held by
Chris@16 255 /// reference with ones held by value. Use with
Chris@16 256 /// \c compose_generators to forward that result to another
Chris@16 257 /// generator.
Chris@16 258 ///
Chris@16 259 /// Generators are intended for use as the first template parameter
Chris@16 260 /// to the \c domain\<\> class template and control if and how
Chris@16 261 /// expressions within that domain are to be customized.
Chris@16 262 /// \c by_value_generator ensures all child nodes are
Chris@16 263 /// held by value. This generator is typically composed with a
Chris@16 264 /// second generator for further processing, as
Chris@16 265 /// <tt>compose_generators\<by_value_generator, MyGenerator\></tt>.
Chris@16 266 struct by_value_generator
Chris@16 267 {
Chris@16 268 BOOST_PROTO_CALLABLE()
Chris@16 269
Chris@16 270 template<typename Sig>
Chris@16 271 struct result;
Chris@16 272
Chris@16 273 template<typename This, typename Expr>
Chris@16 274 struct result<This(Expr)>
Chris@16 275 {
Chris@16 276 typedef
Chris@16 277 typename detail::by_value_generator_<Expr>::type
Chris@16 278 type;
Chris@16 279 };
Chris@16 280
Chris@16 281 template<typename This, typename Expr>
Chris@16 282 struct result<This(Expr &)>
Chris@16 283 {
Chris@16 284 typedef
Chris@16 285 typename detail::by_value_generator_<Expr>::type
Chris@16 286 type;
Chris@16 287 };
Chris@16 288
Chris@16 289 template<typename This, typename Expr>
Chris@16 290 struct result<This(Expr const &)>
Chris@16 291 {
Chris@16 292 typedef
Chris@16 293 typename detail::by_value_generator_<Expr>::type
Chris@16 294 type;
Chris@16 295 };
Chris@16 296
Chris@16 297 /// \param expr The expression to modify.
Chris@16 298 /// \return <tt>deep_copy(expr)</tt>
Chris@16 299 template<typename Expr>
Chris@16 300 BOOST_FORCEINLINE
Chris@16 301 typename result<by_value_generator(Expr)>::type operator ()(Expr const &e) const
Chris@16 302 {
Chris@16 303 return detail::by_value_generator_<Expr>::call(e);
Chris@16 304 }
Chris@16 305 };
Chris@16 306
Chris@16 307 /// \brief A composite generator that first applies one
Chris@16 308 /// transform to an expression and then forwards the result
Chris@16 309 /// on to another generator for further transformation.
Chris@16 310 ///
Chris@16 311 /// Generators are intended for use as the first template parameter
Chris@16 312 /// to the \c domain\<\> class template and control if and how
Chris@16 313 /// expressions within that domain are to be customized.
Chris@16 314 /// \c compose_generators\<\> is a composite generator that first
Chris@16 315 /// applies one transform to an expression and then forwards the
Chris@16 316 /// result on to another generator for further transformation.
Chris@16 317 template<typename First, typename Second>
Chris@16 318 struct compose_generators
Chris@16 319 {
Chris@16 320 BOOST_PROTO_CALLABLE()
Chris@16 321
Chris@16 322 template<typename Sig>
Chris@16 323 struct result;
Chris@16 324
Chris@16 325 template<typename This, typename Expr>
Chris@16 326 struct result<This(Expr)>
Chris@16 327 {
Chris@16 328 typedef
Chris@16 329 typename Second::template result<
Chris@16 330 Second(typename First::template result<First(Expr)>::type)
Chris@16 331 >::type
Chris@16 332 type;
Chris@16 333 };
Chris@16 334
Chris@16 335 template<typename This, typename Expr>
Chris@16 336 struct result<This(Expr &)>
Chris@16 337 {
Chris@16 338 typedef
Chris@16 339 typename Second::template result<
Chris@16 340 Second(typename First::template result<First(Expr)>::type)
Chris@16 341 >::type
Chris@16 342 type;
Chris@16 343 };
Chris@16 344
Chris@16 345 template<typename This, typename Expr>
Chris@16 346 struct result<This(Expr const &)>
Chris@16 347 {
Chris@16 348 typedef
Chris@16 349 typename Second::template result<
Chris@16 350 Second(typename First::template result<First(Expr)>::type)
Chris@16 351 >::type
Chris@16 352 type;
Chris@16 353 };
Chris@16 354
Chris@16 355 /// \param expr The expression to modify.
Chris@16 356 /// \return Second()(First()(expr))
Chris@16 357 template<typename Expr>
Chris@16 358 BOOST_FORCEINLINE
Chris@16 359 typename result<compose_generators(Expr)>::type operator ()(Expr const &e) const
Chris@16 360 {
Chris@16 361 return Second()(First()(e));
Chris@16 362 }
Chris@16 363 };
Chris@16 364
Chris@16 365 /// \brief Tests a generator to see whether it would prefer
Chris@16 366 /// to be passed instances of \c proto::basic_expr\<\> rather than
Chris@16 367 /// \c proto::expr\<\>.
Chris@16 368 ///
Chris@16 369 template<typename Generator, typename Void>
Chris@16 370 struct wants_basic_expr
Chris@16 371 : mpl::false_
Chris@16 372 {};
Chris@16 373
Chris@16 374 template<typename Generator>
Chris@16 375 struct wants_basic_expr<Generator, typename Generator::proto_use_basic_expr_>
Chris@16 376 : mpl::true_
Chris@16 377 {};
Chris@16 378
Chris@16 379 /// INTERNAL ONLY
Chris@16 380 template<>
Chris@16 381 struct is_callable<default_generator>
Chris@16 382 : mpl::true_
Chris@16 383 {};
Chris@16 384
Chris@16 385 /// INTERNAL ONLY
Chris@16 386 template<template<typename> class Extends>
Chris@16 387 struct is_callable<generator<Extends> >
Chris@16 388 : mpl::true_
Chris@16 389 {};
Chris@16 390
Chris@16 391 /// INTERNAL ONLY
Chris@16 392 template<template<typename> class Extends>
Chris@16 393 struct is_callable<pod_generator<Extends> >
Chris@16 394 : mpl::true_
Chris@16 395 {};
Chris@16 396
Chris@16 397 /// INTERNAL ONLY
Chris@16 398 template<>
Chris@16 399 struct is_callable<by_value_generator>
Chris@16 400 : mpl::true_
Chris@16 401 {};
Chris@16 402
Chris@16 403 /// INTERNAL ONLY
Chris@16 404 template<typename First, typename Second>
Chris@16 405 struct is_callable<compose_generators<First, Second> >
Chris@16 406 : mpl::true_
Chris@16 407 {};
Chris@16 408
Chris@16 409 }}
Chris@16 410
Chris@16 411 // Specializations of boost::result_of and boost::tr1_result_of to eliminate
Chris@16 412 // some unnecessary template instantiations
Chris@16 413 namespace boost
Chris@16 414 {
Chris@16 415 template<typename Expr>
Chris@16 416 struct result_of<proto::default_domain(Expr)>
Chris@16 417 {
Chris@16 418 typedef Expr type;
Chris@16 419 };
Chris@16 420
Chris@16 421 template<typename Expr>
Chris@16 422 struct result_of<proto::basic_default_domain(Expr)>
Chris@16 423 {
Chris@16 424 typedef Expr type;
Chris@16 425 };
Chris@16 426
Chris@16 427 template<typename Expr>
Chris@16 428 struct result_of<proto::default_generator(Expr)>
Chris@16 429 {
Chris@16 430 typedef Expr type;
Chris@16 431 };
Chris@16 432
Chris@16 433 template<typename Expr>
Chris@16 434 struct result_of<proto::basic_default_generator(Expr)>
Chris@16 435 {
Chris@16 436 typedef Expr type;
Chris@16 437 };
Chris@16 438
Chris@16 439 #if BOOST_VERSION >= 104400
Chris@16 440 template<typename Expr>
Chris@16 441 struct tr1_result_of<proto::default_domain(Expr)>
Chris@16 442 {
Chris@16 443 typedef Expr type;
Chris@16 444 };
Chris@16 445
Chris@16 446 template<typename Expr>
Chris@16 447 struct tr1_result_of<proto::basic_default_domain(Expr)>
Chris@16 448 {
Chris@16 449 typedef Expr type;
Chris@16 450 };
Chris@16 451
Chris@16 452 template<typename Expr>
Chris@16 453 struct tr1_result_of<proto::default_generator(Expr)>
Chris@16 454 {
Chris@16 455 typedef Expr type;
Chris@16 456 };
Chris@16 457
Chris@16 458 template<typename Expr>
Chris@16 459 struct tr1_result_of<proto::basic_default_generator(Expr)>
Chris@16 460 {
Chris@16 461 typedef Expr type;
Chris@16 462 };
Chris@16 463 #endif
Chris@16 464 }
Chris@16 465
Chris@101 466 #if defined(_MSC_VER)
Chris@16 467 # pragma warning(pop)
Chris@16 468 #endif
Chris@16 469
Chris@16 470 #endif // BOOST_PROTO_GENERATE_HPP_EAN_02_13_2007