Boost logo

Boost :

Subject: Re: [boost] [GSoC][MPL11] Post C++Now update
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2014-05-20 15:53:25


Lee Clagett <forum <at> leeclagett.com> writes:

[...]

> Is the issue the name, MPL11? These proposals seem to be more Fusion11. The

The name's not the issue. The new library is called Boost.Hana and as long
as it does not conflict with anything, I'm unwilling to discuss it; that
would be bikeshedding. It's just a name after all.

> current MPL has type-computation and compile-time value computation. It
> supports sequences of types and sequences of homogeneous values. It seems
> that people want the compile-time value computation written in the runtime
> language, as opposed to the compile time language. I like this idea too.
> But I'm not seeing a reason to do type-computation in the runtime-language.

If doing so allows us to have a single library instead of two libraries with
different interfaces, that's a reason. It would also mean that some functions
written for runtime arguments could work as-is on types, which is an advantage.
Finally, Matt Calabrese already pointed out the ease of debugging metaprograms.
There might be other less obvious advantages too.

> For example, take this in the current current MPL:
>
> template<bool IsOrdered>
> struct Values
> {
> boost::mpl::if_c<IsOrdered, std::set<int>, std::unordered_set<int>>::type
> values;
> };
>
> And then in the runtime MPL that Louis posted earlier:
>
> template<bool IsOrdered>
> struct Values
> {
> decltype(boost::mpl::if_c(declval(mpl::bool_<IsOrdered>),
> declval(std::set<int>), declval(std::unordered_set<int>))) values;
> };

With Boost.Hana, that would actually be

    template <bool IsOrdered>
    struct Values {
        static constexpr auto values_t = if_(bool_<IsOrdered>,
            type<std::set<int>>,
            type<std::unordered_set<int>>
        );
        typename decltype(values_t)::type values;
    };

which is worse than the current MPL. However, perhaps sticking to simple
tools is better for simple problems:

    template <bool IsOrdered>
    struct Values {
        using values_t = std::conditional_t<IsOrdered,
            std::set<int>,
            std::unordered_set<int>
>;
        values_t values;
    };

I'll admit that I would like these simple problems to have a simple solution
in Boost.Hana. It might be possible by providing thin wrappers for type-only
computations; I'll evaluate that and provide feedback.

> That seems like a step backward to me. It is possible to "stitch" together
> the runtime and compile languages with the expanded "using" keyword, but is

I'm sorry, but I don't see how the "using" keyword helps at all here.
Could you please expand?

[...]

Regards,
Louis Dionne


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