123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- // Copyright (C) 2016-2018 T. Zachary Laine
- //
- // Distributed under the Boost Software License, Version 1.0. (See
- // accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- #include <boost/yap/expression.hpp>
- #include <string>
- #include <vector>
- #define user_expr user_expr_1
- /// [USER_UNARY_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- // Operator overloads for operator!().
- BOOST_YAP_USER_UNARY_OPERATOR(logical_not, user_expr, user_expr)
- /// [USER_UNARY_OPERATOR]
- struct lazy_vector_1 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef user_expr
- #define user_expr user_expr_2
- /// [USER_BINARY_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- // Operator overloads for operator&&()
- BOOST_YAP_USER_BINARY_OPERATOR(logical_and, user_expr, user_expr)
- /// [USER_BINARY_OPERATOR]
- struct lazy_vector_2 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef user_expr
- #define user_expr user_expr_3
- /// [USER_CALL_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- // Member operator overloads for operator()(). These will match any
- // number of parameters. Each one can be any type, even another
- // expression.
- BOOST_YAP_USER_CALL_OPERATOR(::user_expr)
- };
- /// [USER_CALL_OPERATOR]
- struct lazy_vector_3 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef user_expr
- #define user_expr user_expr_4
- /// [USER_SUBSCRIPT_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- // Member operator overloads for operator[](). These will match any value
- // on the right-hand side, even another expression.
- BOOST_YAP_USER_SUBSCRIPT_OPERATOR(::user_expr)
- };
- /// [USER_SUBSCRIPT_OPERATOR]
- struct lazy_vector_4 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef user_expr
- #define user_expr user_expr_5
- /// [USER_EXPR_IF_ELSE]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- // Defines an overload of if_else() that returns expressions instantiated from
- // user_expr.
- BOOST_YAP_USER_EXPR_IF_ELSE(::user_expr)
- /// [USER_EXPR_IF_ELSE]
- struct lazy_vector_5 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef user_expr
- #define user_expr user_expr_6
- #define is_vector is_vector_1
- /// [USER_UDT_ANY_IF_ELSE]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- template <typename T>
- struct is_vector : std::false_type {};
- template <typename T, typename A>
- struct is_vector<std::vector<T, A>> : std::true_type {};
- // Defines an overload of if_else() that returns expressions instantiated from
- // user_expr.
- BOOST_YAP_USER_UDT_ANY_IF_ELSE(::user_expr, is_vector)
- /// [USER_UDT_ANY_IF_ELSE]
- struct lazy_vector_6 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef is_vector
- #undef user_expr
- #define user_expr user_expr_7
- #define is_vector is_vector_2
- /// [USER_UDT_UNARY_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- template <typename T>
- struct is_vector : std::false_type {};
- template <typename T, typename A>
- struct is_vector<std::vector<T, A>> : std::true_type {};
- // Defines an overload of operator!() that applies to vectors and returns
- // expressions instantiated from user_expr.
- BOOST_YAP_USER_UDT_UNARY_OPERATOR(logical_not, ::user_expr, is_vector)
- /// [USER_UDT_UNARY_OPERATOR]
- struct lazy_vector_7 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef is_vector
- #undef user_expr
- #define user_expr user_expr_8
- #define is_vector is_vector_3
- /// [USER_UDT_UDT_BINARY_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- template <typename T>
- struct is_vector : std::false_type {};
- template <typename T, typename A>
- struct is_vector<std::vector<T, A>> : std::true_type {};
- template <typename T>
- struct is_string : std::false_type {};
- template <>
- struct is_string<std::string> : std::true_type {};
- // Defines an overload of operator||() that applies to vectors on the left and
- // strings on the right, and returns expressions instantiated from user_expr.
- BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR(logical_or, ::user_expr, is_vector, is_string)
- // Defines an overload of operator&&() that applies to strings and returns
- // expressions instantiated from user_expr.
- BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR(logical_and, ::user_expr, is_string, is_string)
- /// [USER_UDT_UDT_BINARY_OPERATOR]
- struct lazy_vector_8 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef is_vector
- #undef user_expr
- #define user_expr user_expr_9
- #define is_vector is_vector_4
- /// [USER_UDT_ANY_BINARY_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- template <typename T>
- struct is_vector : std::false_type {};
- template <typename T, typename A>
- struct is_vector<std::vector<T, A>> : std::true_type {};
- // Defines an overload of operator&&() that matches a vector on either side,
- // and any type (possibly a vector) on the other.
- BOOST_YAP_USER_UDT_ANY_BINARY_OPERATOR(logical_and, ::user_expr, is_vector)
- /// [USER_UDT_ANY_BINARY_OPERATOR]
- struct lazy_vector_9 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef is_vector
- #undef user_expr
- #define user_expr user_expr_10
- /// [USER_LITERAL_PLACEHOLDER_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- };
- namespace literals {
- // Defines a user literal operator that makes placeholders; 2_p will be a
- // 2-placeholder instantiated from the user_expr template.
- BOOST_YAP_USER_LITERAL_PLACEHOLDER_OPERATOR(user_expr)
- }
- /// [USER_LITERAL_PLACEHOLDER_OPERATOR]
- struct lazy_vector_10 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef user_expr
- #define user_expr user_expr_11
- /// [USER_ASSIGN_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- // Member operator overloads for operator=(). These will match any value
- // on the right-hand side, even another expression, except that it will
- // not conflict with the asignment or move assignment operators.
- BOOST_YAP_USER_ASSIGN_OPERATOR(user_expr, ::user_expr)
- };
- /// [USER_ASSIGN_OPERATOR]
- struct lazy_vector_11 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- #undef user_expr
- #undef user_expr
- #define user_expr user_expr_12
- /// [USER_CALL_OPERATOR]
- template <boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static const boost::yap::expr_kind kind = Kind;
- Tuple elements;
- // Member operator overloads for operator()(). These will take exactly N
- // parameters. Each one can be any type, even another expression.
- BOOST_YAP_USER_CALL_OPERATOR(::user_expr)
- };
- /// [USER_CALL_OPERATOR]
- struct lazy_vector_12 :
- user_expr<
- boost::yap::expr_kind::terminal,
- boost::hana::tuple<std::vector<double>>
- >
- {};
- int main ()
- {
- lazy_vector_1 v1;
- lazy_vector_2 v2;
- lazy_vector_3 v3;
- lazy_vector_4 v4;
- lazy_vector_5 v5;
- lazy_vector_6 v6;
- lazy_vector_7 v7;
- lazy_vector_8 v8;
- lazy_vector_9 v9;
- lazy_vector_10 v10;
- lazy_vector_11 v11;
- lazy_vector_12 v12;
- return 0;
- }
|