Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:56

0001 // Copyright (C) 2016-2018 T. Zachary Laine
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See
0004 // accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 #ifndef BOOST_YAP_ALGORITHM_FWD_HPP_INCLUDED
0007 #define BOOST_YAP_ALGORITHM_FWD_HPP_INCLUDED
0008 
0009 #include <boost/yap/config.hpp>
0010 
0011 #include <boost/hana/integral_constant.hpp>
0012 #include <boost/hana/tuple.hpp>
0013 #include <boost/hana/core/is_a.hpp>
0014 
0015 
0016 namespace boost { namespace yap {
0017 
0018     /** The enumeration representing all the kinds of expressions supported in
0019         YAP.
0020     */
0021     enum class expr_kind {
0022         expr_ref =
0023             0, ///< A (possibly \c const) reference to another expression.
0024 
0025         terminal = 1, ///< A terminal expression.
0026 
0027         // unary
0028         unary_plus = 2,  ///< \c +
0029         negate = 3,      ///< \c -
0030         dereference = 4, ///< \c *
0031         complement = 5,  ///< \c ~
0032         address_of = 6,  ///< \c &
0033         logical_not = 7, ///< \c !
0034         pre_inc = 8,     ///< \c ++
0035         pre_dec = 9,     ///< \c \-\-
0036         post_inc = 10,   ///< \c ++(int)
0037         post_dec = 11,   ///< \c \-\-(int)
0038 
0039         // binary
0040         shift_left = 12,         ///< \c <<
0041         shift_right = 13,        ///< \c >>
0042         multiplies = 14,         ///< \c *
0043         divides = 15,            ///< \c /
0044         modulus = 16,            ///< \c %
0045         plus = 17,               ///< \c +
0046         minus = 18,              ///< \c -
0047         less = 19,               ///< \c <
0048         greater = 20,            ///< \c >
0049         less_equal = 21,         ///< \c <=
0050         greater_equal = 22,      ///< \c >=
0051         equal_to = 23,           ///< \c ==
0052         not_equal_to = 24,       ///< \c !=
0053         logical_or = 25,         ///< \c ||
0054         logical_and = 26,        ///< \c &&
0055         bitwise_and = 27,        ///< \c &
0056         bitwise_or = 28,         ///< \c |
0057         bitwise_xor = 29,        ///< \c ^
0058         comma = 30,              ///< \c ,
0059         mem_ptr = 31,            ///< \c ->*
0060         assign = 32,             ///< \c =
0061         shift_left_assign = 33,  ///< \c <<=
0062         shift_right_assign = 34, ///< \c >>=
0063         multiplies_assign = 35,  ///< \c *=
0064         divides_assign = 36,     ///< \c /=
0065         modulus_assign = 37,     ///< \c %=
0066         plus_assign = 38,        ///< \c +=
0067         minus_assign = 39,       ///< \c -=
0068         bitwise_and_assign = 40, ///< \c &=
0069         bitwise_or_assign = 41,  ///< \c |=
0070         bitwise_xor_assign = 42, ///< \c ^=
0071         subscript = 43,          ///< \c []
0072 
0073         // ternary
0074         if_else = 44, ///< Analogous to \c ?: .
0075 
0076         // n-ary
0077         call = 45 ///< \c ()
0078     };
0079 
0080     /** The type used to represent the index of a placeholder terminal. */
0081     template<long long I>
0082     struct placeholder : hana::llong<I>
0083     {
0084     };
0085 
0086 #ifdef BOOST_YAP_DOXYGEN
0087 
0088     /** A metafunction that evaluates to std::true_type if \a Expr is an
0089         Expression, and std::false_type otherwise. */
0090     template<typename Expr>
0091     struct is_expr;
0092 
0093 #else
0094 
0095     template<expr_kind Kind, typename Tuple>
0096     struct expression;
0097 
0098     namespace detail {
0099 
0100         // void_t
0101 
0102         template<class...>
0103         using void_t = void;
0104 
0105         // remove_cv_ref
0106 
0107         template<typename T>
0108         struct remove_cv_ref : std::remove_cv<std::remove_reference_t<T>>
0109         {
0110         };
0111 
0112         template<typename T>
0113         using remove_cv_ref_t = typename remove_cv_ref<T>::type;
0114     }
0115 
0116     template<
0117         typename Expr,
0118         typename = detail::void_t<>,
0119         typename = detail::void_t<>>
0120     struct is_expr : std::false_type
0121     {
0122     };
0123 
0124     template<typename Expr>
0125     struct is_expr<
0126         Expr,
0127         detail::void_t<decltype(detail::remove_cv_ref_t<Expr>::kind)>,
0128         detail::void_t<decltype(std::declval<Expr>().elements)>>
0129         : std::integral_constant<
0130               bool,
0131               std::is_same<
0132                   std::remove_cv_t<decltype(
0133                       detail::remove_cv_ref_t<Expr>::kind)>,
0134                   expr_kind>::value &&
0135                   hana::is_a<
0136                       hana::tuple_tag,
0137                       decltype(std::declval<Expr>().elements)>>
0138     {
0139     };
0140 
0141 #endif // BOOST_YAP_DOXYGEN
0142 
0143     /** A convenience alias for a terminal expression holding a \a T,
0144         instantiated from expression template \a expr_template. */
0145     template<template<expr_kind, class> class expr_template, typename T>
0146     using terminal = expr_template<expr_kind::terminal, hana::tuple<T>>;
0147 
0148     /** A convenience alias for a reference expression holding an expression
0149         \a T, instantiated from expression template \a expr_template. */
0150     template<template<expr_kind, class> class expr_template, typename T>
0151     using expression_ref = expr_template<
0152         expr_kind::expr_ref,
0153         hana::tuple<std::remove_reference_t<T> *>>;
0154 
0155 #ifndef BOOST_YAP_DOXYGEN
0156 
0157     template<typename Expr, typename... T>
0158     constexpr decltype(auto) evaluate(Expr && expr, T &&... t);
0159 
0160     template<typename Expr, typename Transform, typename... Transforms>
0161     constexpr decltype(auto) transform(
0162         Expr && expr, Transform && transform, Transforms &&... transforms);
0163 
0164     template<typename Expr, typename Transform, typename... Transforms>
0165     constexpr decltype(auto) transform_strict(
0166         Expr && expr, Transform && transform, Transforms &&... transforms);
0167 
0168     template<typename T>
0169     constexpr decltype(auto) deref(T && x);
0170 
0171     template<typename Expr>
0172     constexpr decltype(auto) value(Expr && expr);
0173 
0174 #endif // BOOST_YAP_DOXYGEN
0175 
0176     namespace literals {
0177 
0178         /** Creates literal placeholders.  Placeholder indices are 1-based. */
0179         template<char... c>
0180         constexpr auto operator"" _p()
0181         {
0182             using i = hana::llong<hana::ic_detail::parse<sizeof...(c)>({c...})>;
0183             static_assert(1 <= i::value, "Placeholders must be >= 1.");
0184             return expression<
0185                 expr_kind::terminal,
0186                 hana::tuple<placeholder<i::value>>>{};
0187         }
0188     }
0189 
0190     /** Used as the tag-type passed to a transform function written in the
0191         tag-transform form. */
0192     template<expr_kind Kind>
0193     struct expr_tag
0194     {
0195         static const expr_kind kind = Kind;
0196     };
0197 
0198     /** Used as the expression template returned by some operations inside YAP
0199         when YAP does not have an expression template it was told to use.  For
0200         instance, if transform() creates a new expression by transforming an
0201         existing expression's elements, it will attempt to create the new
0202         expression using the existing one's expression template.  If no such
0203         template exists because the existing expression was not made from an
0204         expression template, minimal_expr is used. */
0205     template<expr_kind Kind, typename Tuple>
0206     struct minimal_expr
0207     {
0208         static expr_kind const kind = Kind;
0209         Tuple elements;
0210     };
0211 
0212 }}
0213 
0214 #endif