|
Boost : |
Subject: Re: [boost] [mpl] multiset
From: Eric Niebler (eniebler_at_[hidden])
Date: 2015-03-05 21:41:56
On 3/5/2015 4:52 AM, Louis Dionne wrote:
> Eric Niebler <eniebler <at> boost.org> writes:
>
>>
>> [...]
>>
>> [*] My GSoC idea: my Meta library is built around variadic parameter
>> packs, aka lists, and I think I'm happy with that. But it has been
>> suggested that it could be built instead around the Foldable concept.
>> The project would be to redesign Meta around Foldable types, and add
>> other "containers" to Meta besides lists, like sets, and have the
>> algorithms work with anything that is Foldable.
>
> Thanks for the feedback, Eric. However, there's something that has been
> tickling me for a while with Meta. I am seeing some kind of convergence
> in Meta towards the MPL11, especially with the addition of the lazy
> operations. If you go down the Foldable road, then you would end up
> with something incredibly similar. The MPL11 does exactly that work
> of splitting sequences into Foldable, Iterable and other similar concepts.
> Frankly, my impression is that Meta is reinventing MPL11's wheel, and I
> would like to know whether (1) I am wrong (2) this is done unconsciously
> (3) this is done consciously because you think the MPL11 doesn't cut it.
>
> Of course, it is the possibility of (3) that has been tickling me :-).
I found MPL11 and read some of its docs. Although there are many
similarities (naturally, we're both influenced by the MPL), I think
there is a fundamental difference. Meta isn't built around metafunctions
as folks here know them. The Meta library is built around template
aliases. The difference is illustrated in the way the quote feature is
implemented in the two libraries.
In MPL11, it's called "lift" and it looks like:
template <template <typename ...> class f>
struct lift {
template <typename ...xs>
struct apply
: f<xs...>
{ };
};
Here, the assumption seems to be that "f" is a what you're calling a
thunk or a boxed value; aka a metafunction. Something with a nested ::type.
In contrast, here is (in essence) how Meta defines quote:
template <template <typename ...> class f>
struct quote
{
template <typename ...xs>
using apply = f<xs...>;
};
In Meta, the template aliases are used extensively, and types evaluate
directly to their results. Things are done eagerly. There are no "thunks".
Of course, when writing a lambda or a let expression, evaluation needs
to be deferred until the substitutions are made. I use a template called
"defer" for that. It's only intended for use by let and lambda. Although
it does give things a nested "::type", it doesn't strictly need to;
indeed when I first added it, it didn't.
Anyway, that may seem like a subtle difference, but it feels like sea
change to me. I find it much nicer working this way.
-- Eric Niebler Boost.org http://www.boost.org
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk