El 23/07/2017 a las 14:42, Peter Dimov via Boost escribió:
Hi,
not a review yet.
I´m just wondering: would the implementation below perfom better
Roberto Hinz wrote:
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).
Upon further experimentation, while it does perform very well for
repeated finds such as those done by this test case:
using L1 = mp_iota_c<300>;
template<class T> using F = mp_find;
using L2 = mp_transform;
static_assert( std::is_same::value, "L1 != L2" );
it has a large one-time cost in both time and heap space, making it
unsuitable for N in the thousands.
The following alternative based on bool sequences seems to perform very
well for the mp_iota_c case
(basically, mp_find runs out of heap space in my machine for
mp_iota_c<300> whereas mp_find2 takes
4-5 s). Don't know if mp_find2 stands up for other scenarios:
template
struct mp_find2_bools{};
template
struct
mp_find2_bools
{static constexpr std::size_t value=10+mp_find2_bools::value;};
template<>
struct
mp_find2_bools
{static constexpr std::size_t value=9;};
template<>
struct mp_find2_bools
{static constexpr std::size_t value=8;};
template<>
struct mp_find2_bools
{static constexpr std::size_t value=7;};
template<>
struct mp_find2_bools
{static constexpr std::size_t value=6;};
template<>
struct mp_find2_bools
{static constexpr std::size_t value=5;};
template<>
struct mp_find2_bools
{static constexpr std::size_t value=4;};
template<>
struct mp_find2_bools
{static constexpr std::size_t value=3;};
template<>
struct mp_find2_bools
{static constexpr std::size_t value=2;};
template<>
struct mp_find2_bools<false>
{static constexpr std::size_t value=1;};
template<>
struct mp_find2_bools<>
{static constexpr std::size_t value=0;};
template
struct
mp_find2_bools
{static constexpr std::size_t value=9;};
template
struct
mp_find2_bools
{static constexpr std::size_t value=8;};
template
struct
mp_find2_bools
{static constexpr std::size_t value=7;};
template
struct mp_find2_bools
{static constexpr std::size_t value=6;};
template
struct mp_find2_bools
{static constexpr std::size_t value=5;};
template
struct mp_find2_bools
{static constexpr std::size_t value=4;};
template
struct mp_find2_bools
{static constexpr std::size_t value=3;};
template
struct mp_find2_bools
{static constexpr std::size_t value=2;};
template
struct mp_find2_bools
{static constexpr std::size_t value=1;};
template
struct mp_find2_bools
{static constexpr std::size_t value=0;};
template
struct mp_find2_impl;
template class L,typename... T,typename V>
struct
mp_find2_impl,V>:mp_find2_bools::value...>{};
template using
mp_find2=mp_size_t::value>;
Joaquín M López Muñoz