[mp11][mpl] Recurse over type list using mp11's mp_rest

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[mp11][mpl] Recurse over type list using mp11's mp_rest

Boost - Users mailing list
Hello,
I am currently learning about mp11 from the docs . While mpl had an
iterator functionality to get an alias over a type in mp_list it seemed
mp11's mp_rest could be used for a similar task. So I coded up a simple
example of recursing over a type list based on some type check , but am
quite lost trying to make it work . So a possible pseudo code for the above
might be
template<typename list>
struct recurse{    
    using rest_of_list=mp_rest<list>;
    using type = typename std::conditional<
        mp_empty<rest_of_list>::value,
        base type here on empty list,
        typename std::conditional<
            some "loop" break condition,
            type on true condition,
            typename recurse<
            rest_of_list >::type
        >::type
>::type;
}
Is this even possible or there exists some other method to do the same in
mp11.
Thanks.



--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [mp11][mpl] Recurse over type list using mp11's mp_rest

Boost - Users mailing list
On 3/4/20 1:13 PM, deb via Boost-users wrote:

> Hello,
> I am currently learning about mp11 from the docs . While mpl had an
> iterator functionality to get an alias over a type in mp_list it seemed
> mp11's mp_rest could be used for a similar task. So I coded up a simple
> example of recursing over a type list based on some type check , but am
> quite lost trying to make it work . So a possible pseudo code for the above
> might be
> template<typename list>
> struct recurse{    
>     using rest_of_list=mp_rest<list>;
>     using type = typename std::conditional<
>         mp_empty<rest_of_list>::value,
>         base type here on empty list,
>         typename std::conditional<
>             some "loop" break condition,
>             type on true condition,
>             typename recurse<
>             rest_of_list >::type
>         >::type
>> ::type;
> }
> Is this even possible or there exists some other method to do the same in
> mp11.
> Thanks.
>
>
>
> --
> Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
>
**maybe** the following is close to what you want:


https://github.com/cppljevans/variadic_templates/blob/master/boost/mpl/if_recur.hpp

Honestly, I've not looked closely at your requirements, but your
description of the problem "sounds" close to what the if_recur
could solve.

I'd appreciate any feedback on whether this is any help ;)

-regards,
Larry


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [mp11][mpl] Recurse over type list using mp11's mp_rest

Boost - Users mailing list
Yes Larry,
> https://github.com/cppljevans/variadic_templates/blob/master/boost/mpl/if_recur.hpp

is somewhat similar to what I wanted to do . While it is using mpl, I wanted
to do it using mp11 only. Anyways , I have been able to get it working with
mp11's mp_rest after some extensive reading up.
Thanks for your help.
deb



--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [mp11][mpl] Recurse over type list using mp11's mp_rest

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 2020-03-05 14:00, deb via Boost-users wrote:

> to do it using mp11 only. Anyways , I have been able to get it working with
> mp11's mp_rest after some extensive reading up.

I am not entirely sure what you are trying to achieve, but it seems to
me that you could use mp_find() to get an index instead of an MPL
iterator.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [mp11][mpl] Recurse over type list using mp11's mp_rest

Boost - Users mailing list
Yes, mp_find and then mp_at_c would equivalently do the job .
And, if I may ask , do you know of any significant difference(regarding
compile-time) between the iterator based approach of mpl and mp_find?
Thanks.



--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [mp11][mpl] Recurse over type list using mp11's mp_rest

Boost - Users mailing list
On 3/5/20 1:54 PM, deb via Boost-users wrote:
> Yes, mp_find and then mp_at_c would equivalently do the job .
> And, if I may ask , do you know of any significant difference(regarding
> compile-time) between the iterator based approach of mpl and mp_find?
> Thanks.
>
>
Deb, the subject of profiling template compile times came up here:

  http://lists.llvm.org/pipermail/cfe-dev/2020-March/064811.html

with the subject line:

  Clang: How to Analyse Compiletime of Templates?

Maybe that could give you some hints of doing it yourself.

HTH.

-Larry
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users