Re: [boost] Formal Review Request: mp11

On 03/17/2017 03:06 PM, Peter Dimov via Boost wrote:
A few comments... Most algorithms take the typelist as the first argument, but others do not, e.g. mp_transform<F, L...>. If possible, I would like to see all algorithms take typelist as the first argument. It looks like the current order is dictated by the requirements of mp_tranform_impl. Would it be possible to swap the types where the algorithm is declared? For example: template<class L, template<class...> class F> using mp_transform = typename detail::mp_transform_impl<F, L>::type; Apropos mp_transform, would it be possible to extend it such that we can pass a type-trait directly to it? For example: using const_list = mp_transform<std::add_const, typelist>; instead of using std::add_const_t. The reason I ask is that I have lots of my own domain-specific type-traits that does not come with a _t version, so this is mainly for convenience. The reference documentation is a bit terse and obscure. For example, the documentation for mp_find tells us in a convoluted way that it returns the index of a type in a typelist. It could also mention that it is the dual algorithm to mp_at, which returns a type at an index in a typelist.

Bjorn Reese wrote:
Most algorithms take the typelist as the first argument, but others do not, e.g. mp_transform<F, L...>. If possible, I would like to see all algorithms take typelist as the first argument.
It's not possible for L... to be first. Note the ellipsis.

Bjorn Reese wrote:
Apropos mp_transform, would it be possible to extend it such that we can pass a type-trait directly to it? For example:
using const_list = mp_transform<std::add_const, typelist>;
instead of using std::add_const_t. The reason I ask is that I have lots of my own domain-specific type-traits that does not come with a _t version, so this is mainly for convenience.
That's unfortunately not possible because mp_transform<std::add_const, mp_list<int, float>> is perfectly valid and yields mp_list<add_const<int>, add_const<float>>. I can add template<template<class...> class T> struct mp_quote_trait { template<class... U> using invoke = typename T<U...>::type; }; that would allow mp_transform<mp_quote_trait<std::add_const>::invoke, L> but that's not much of an improvement. _t is the way to go with mp11.
The reference documentation is a bit terse and obscure.
That it is. I'm gradually improving it bit by bit when I find time to work on it.

On 03/18/2017 02:33 PM, Peter Dimov via Boost wrote:
Bjorn Reese wrote:
Most algorithms take the typelist as the first argument, but others do not, e.g. mp_transform<F, L...>. If possible, I would like to see all algorithms take typelist as the first argument.
It's not possible for L... to be first. Note the ellipsis.
Notice that I removed them :) The documentation states that "data structures are lists of the form L<T...>" so why is L... needed in mp_transform? I just the type-swapping trick with mp_list and std::tuple, and both worked fine.

Bjorn Reese wrote:
On 03/18/2017 02:33 PM, Peter Dimov via Boost wrote:
Bjorn Reese wrote:
Most algorithms take the typelist as the first argument, but others do not, e.g. mp_transform<F, L...>. If possible, I would like to see all algorithms take typelist as the first argument.
It's not possible for L... to be first. Note the ellipsis.
Notice that I removed them :)
The documentation states that "data structures are lists of the form L<T...>" so why is L... needed in mp_transform?
mp_transform is variadic, it works on more than one list. mp_transform<std::pair, mp_list<int, float>, mp_list<char, double>> -> mp_list<std::pair<int, char>, std::pair<float, double>>

On Sat, Mar 18, 2017 at 2:55 PM, Peter Dimov via Boost < boost@lists.boost.org> wrote:
Bjorn Reese wrote:
On 03/18/2017 02:33 PM, Peter Dimov via Boost wrote:
Bjorn Reese wrote:
Most algorithms take the typelist as the first argument, but others do not, e.g. mp_transform<F, L...>. If possible, I would like to see all >> algorithms take typelist as the first argument.
It's not possible for L... to be first. Note the ellipsis.
Notice that I removed them :)
The documentation states that "data structures are lists of the form L<T...>" so why is L... needed in mp_transform?
mp_transform is variadic, it works on more than one list.
Is it truly variadic? Does it work for more than 3 lists?

Bruno Dutra wrote:
mp_transform is variadic, it works on more than one list.
Is it truly variadic? Does it work for more than 3 lists?
The actual implementation in mp11 doesn't work on more than 3 lists at the moment, but that's a defect that will eventually be fixed. :-)

On 03/18/2017 02:55 PM, Peter Dimov via Boost wrote:
mp_transform is variadic, it works on more than one list.
Ok. How about having two versions? One that takes a single typelist (at the beginning) and one that takes an arbitrary number. The latter should probably be named differently to indicate that its arguments deviate from the rest of the algorithms (e.g mp_multi_transform.)
mp_transform<std::pair, mp_list<int, float>, mp_list<char, double>>
->
mp_list<std::pair<int, char>, std::pair<float, double>>
Oh, a zip. That looks useful. You should add that example to the documentation.

Bjorn Reese wrote:
On 03/18/2017 02:50 PM, Peter Dimov via Boost wrote:
but that's not much of an improvement. _t is the way to go with mp11.
As _t for <type_traits> is C++14, what is the solution for C++11?
Well, you write the _t versions yourself on an as-needed basis, I suppose. :-)
participants (3)
-
Bjorn Reese
-
Bruno Dutra
-
Peter Dimov