|
Boost : |
Subject: Re: [boost] Yap's formal review is starting now!
From: Zach Laine (whatwasthataddress_at_[hidden])
Date: 2018-02-15 20:37:26
On Thu, Feb 15, 2018 at 12:41 PM, Brook Milligan <brook_at_[hidden]> wrote:
>
> > On Feb 14, 2018, at 2:00 PM, Zach Laine via Boost <boost_at_[hidden]>
> wrote:
> >
> >> Actually, I think you need to define what an expression is in this
> >> context. In my book, expressions are not just made of operators, but can
> >> also include function calls. However, the implicit impression I get from
> >> the YAP documentation is that you only consider expressions based on
> >> operators, and not functions. For instance, I consider std::sqrt(x) an
> >> expression. However, looking at expr_kind (https://tzlaine.github.io/
> >> yap/doc/html/boost/yap/expr_kind.html) it seems that this kind
> expression
> >> is not supported, (but it could be as a Transform).
> >>
> >
> > That's supported. std::sqrt(x) would need to be Yap-ified if x is not
> > already Yap expression, perhaps by making a sqrt Yap terminal, or by
> > calling std::sqrt on a Yap expression. Assuming x is a Yap expression,
> the
> > entire expression "std::sqrt(x)" is a Yap expression whose kind is
> > expr_kind::call. This underscores the need to make this more explicit in
> > the docs, though. *TODO*
>
> I'm confused by this claim. You seem to be suggesting that STL math
> functions somehow can evaluate Yap expressions? How can that be?
>
> The following code, which I believe implements what you are suggesting,
> does not compile for me.
>
> Yes, there needs to be better documentation of the use of functions and
> the call operator kind of expression.
>
> Cheers,
> Brook
>
> #include <cmath>
> #include <boost/yap/algorithm.hpp>
>
> template < boost::yap::expr_kind Kind, typename Tuple >
> struct minimal_expr
> {
> static const boost::yap::expr_kind kind = Kind;
> Tuple elements;
> };
>
> class number {};
>
> int main ()
> {
> using boost::yap::make_terminal;
> std::sqrt(make_terminal<minimal_expr>(number{}));
> return 0;
> }
>
That's right. But try making `std::sqrt` the terminal that you chain
everything off of. As long as the expression template you use has a call
operator, it Just Works. For instance, our favorite whipping boy
expression<> has one. This compiles, I promise:
template <typename T>
using term = boost::yap::terminal<boost::yap::expression, T>;
boost::yap::expression<
boost::yap::expr_kind::plus,
boost::hana::tuple<
boost::yap::expression<
boost::yap::expr_kind::call,
boost::hana::tuple<
boost::yap::expression<
boost::yap::expr_kind::terminal,
boost::hana::tuple<double (*)(double)>
>,
boost::yap::expression<
boost::yap::expr_kind::terminal,
boost::hana::tuple<double>
>
>
>,
boost::yap::expression<
boost::yap::expr_kind::terminal,
boost::hana::tuple<float>
>
>
>
yap_expr = term<double (*)(double)>{{std::sqrt}}(3.0) + 8.0f;
Zach
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk