Boost logo

Boost :

Subject: Re: [boost] Yap's formal review is starting now!
From: Zach Laine (whatwasthataddress_at_[hidden])
Date: 2018-02-17 05:40:56


On Fri, Feb 16, 2018 at 4:26 PM, Peter Dimov via Boost <
boost_at_[hidden]> wrote:

> Zach Laine wrote:
>
>> In this case, something like the expression_tag<> scheme Peter
>> recommended helps with this particular ambiguity:
>>
>> template <typename Tag, typename... T>
>> auto operator()(expression_tag<Tag>, T &&... t)
>>
>
> What I suggested was rather
>
> template <expr_kind Kind, typename... T>
> auto operator()(expression_tag<Kind>, T &&... t)
>
> as this enforces the necessary 1:1 correspondence between kinds and tags.
>
> {
>> // and it also seems to help with writing targeted transforms in
>> C++17:
>> if (yap::to_kind<Tag>() == yap::expr_kind::terminal) {
>>
>
> Resp.
>
> if (Kind == yap::expr_kind::terminal) {
>
> There's an argument to be made in favor of making Expression take a Tag
> first parameter instead of the non-type Kind (`template<class...> class` is
> more regular and easier to manipulate in a generic manner) but that might
> be too much of a change.

I'm vaguely embarrassed that it didn't already work this way. I've made
this change on the boost_review branch, and the recursive case of the
get_arity example transform is now:

    template <boost::yap::expr_kind Kind, typename... Arg>
    auto operator() (boost::yap::expr_tag<Kind>, Arg &&... arg)
    {
        return boost::hana::maximum(
            boost::hana::make_tuple(
                boost::yap::transform(
                    boost::yap::as_expr(std::forward<Arg>(arg)),
                    get_arity{}
                )...
            )
        );
    }

It's not quite as nice as using std::max() as you wrote previously, because
of course std::max() is not yet constexpr.

Zach


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk