Peter : 
Left side isn't faster for me. However, both functions return 0, which means
something isn't right. https://cppx.godbolt.org/z/bGcP848zh

Ha, good catch. After investigating, this is due to three things : 
1/ the standard headers are not just in the std namespace, but in a nested inline namespace (std::__1 for libc++), which the members_of range doesn't traverse 
2/ meta::is_function return false if the entity is a function template, we need meta::is_function_template for that
3/ namespace reflections contains only the latest extension (this was a known issue), which also means that only the very last header included will be considered (i tried to count the number of functions template in std::__1 after including <algorithm>, to my surprise it returned 0, because of another include at the end of the file) 

https://cppx.godbolt.org/z/Y35bqhcjz

So we can't rely on traversing std for benchmarking purposes for now.  

Le lun. 12 avr. 2021 à 19:34, Peter Dimov via SG7 <sg7@lists.isocpp.org> a écrit :
Jean-Baptiste Vallon wrote:
>       This is true — looping over the entire members_of, with a condition
> inside, seems to be 2-3x slower in this example:
>
>       https://cppx.godbolt.org/z/bxGhGPfKo
>
>       Presumably this is due to the cost of instantiating each body of the
> `template for`, which involves considerable allocations of its own internally
> (e.g. lots of Stmt::Create(…) inside clang).
>
>
> David : I am unable to reproduce your results (the left side with a condition
> inside the loop is faster for me, which i think wasn't what you meant?).
> Also, the template for is not needed here, but replacing it by a simple for
> doesn't change the result (i suppose the compiler doesn't instantiate any
> statements since the body of the loop can simply be evaluated).

Left side isn't faster for me. However, both functions return 0, which means
something isn't right. https://cppx.godbolt.org/z/bGcP848zh

--
SG7 mailing list
SG7@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/sg7