[mp11][mpl] Recurse over type list using mp11's mp_rest
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
::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
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
::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_re... 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
Yes Larry,
https://github.com/cppljevans/variadic_templates/blob/master/boost/mpl/if_re...
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
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.
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
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
participants (3)
-
Bjorn Reese
-
deb
-
Larry Evans