Boost logo

Boost :

Subject: Re: [boost] [review][mp11] Reminder of ongoing formal review
From: Peter Dimov (lists_at_[hidden])
Date: 2017-07-23 09:45:44


Roberto Hinz wrote:
> Hi,
>
> not a review yet.
> I´m just wondering: would the implementation below perfom better than the
> recursive version of mp_find_impl ?
> I think it should perform better when one uses mp_find several times in
> the same list.
> It also compiles in vs2013.

It performs better across the board (for repeated finds). Would you be
willing to submit a pull request that replaces the current mp_find_impl with
this one, so that your authorship is preserved in the commit history?

> template <class ... T> struct mp_find_impl_helper;
>
> template <> struct mp_find_impl_helper<>
> {
> struct tag {};
> static mp_size_t<0> get(const tag&, ...);
> };
>
> template <class T, class ... Rest>
> struct mp_find_impl_helper<T, Rest...> : mp_find_impl_helper<Rest...>
> {
> using mp_find_impl_helper<Rest...>::get;
>
> using parent_tag = typename mp_find_impl_helper<Rest...>::tag;
>
> struct tag : parent_tag {};
>
> static mp_size_t<1 + sizeof...(Rest)> get(const tag&, mp_identity<T>);
> };
>
> template<class L, class V> struct mp_find_impl;
>
> template <template <class ...> class L, class ... T, class V>
> struct mp_find_impl<L<T...>, V>
> {
> using helper = mp_find_impl_helper<T...>;
>
> using tag = typename helper::tag;
>
> using R = decltype(helper::get(tag(), mp_identity<V>()));
>
> using type = mp_size_t<sizeof...(T) - R::value>;
> };


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk