|
Boost : |
Subject: Re: [boost] Formal Review Request: mp11
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2017-03-19 08:37:36
Le 17/03/2017 à 15:06, Peter Dimov via Boost a écrit :
> I'd like to request a review for mp11, a simple C++11 metaprogramming
> library.
>
> The library implements the approach outlined in my two articles
>
> http://pdimov.com/cpp2/simple_cxx11_metaprogramming.html
> http://pdimov.com/cpp2/simple_cxx11_metaprogramming_2.html
>
> and is available at
>
> https://github.com/pdimov/mp11/
>
>
> There is documentation in doc/html/mp11.html, it can be viewed
> locally, or with
>
> https://htmlpreview.github.io/?https://github.com/pdimov/mp11/master/doc/html/mp11.html
>
>
> Please excuse the lack of .css in that link.
>
> Thanks in advance for any interest, comments or suggestions.
Hi,
I believe that there is a missing tutorial/design rationale section that
could be filled with some parts of your articles.
About the infamous tuple_cat challenge. tuple_cat doesn't append. tuple
cat construct a tuple with the elements of its tuple-like parameters (I
know that the standard wording doesn't says that exactly, as it accepts
only standard tuple-like types - I've written a proposal so that it can
take in account any product type including every type that is supported
by structure binding. See
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0327r1.pdf).
Examples of product types that don't follow the template aliases pattern
are T[N], array<T,N>, struct {...};
I'm not saying that mp_append is not useful and it surely is much more
efficient, but the description in your paper doesn't solves yet the
problem with concatenation of arbitrary product types. We would need to
obtain to obtain the type list associated to to each product type, then
append them and the rename to tuple.
About transform. I believe that we should have a simple unary
transform<TL, F>. What you have mp11::transform is what we use to name
fmap in functional languages.
As C++ is variadic it can be extended naturally to variadic meta-functions.
mp_fmap<F<Ps...>, TLs...>.
About your mp_count example. Compare your definition with this the HOF one
template <class TL, class V>
using mp_count_if<TL, P> = mp_plus<transform<TL, P>;
template <class TL, class V>
using mp_count<TL, V> = mp_cont_if<TL, is_same_t<_1,V>>;
I don't know if this could have worst or better performances, but IMHO,
it is much more readable and simpler than your definitions.
BTW, your mp_plus doesn't take a type list as parameter.
About mp_contains. I've not yet finished the second article yet. IMO, we
need different concepts as we can have different implementations. I
believe mp_contains is an example where we can have different
implementations for type list and for type set. I recognize however that
most of the meta-programming is done with type lists.
About C++11, C++14, C++17. I believe that meta-programming can profit a
lot of C++17 fold expressions. I believe that a new meta library should
use these features as implementation details when available and when the
performances are increased.
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk