Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC (in any version) equivalent of clang's __type_pack_element to get Nth element of template parameter pack

https://reviews.llvm.org/D15421

clang has __type_pack_element which allows efficient indexing of parameter packs in variadic templates. Is there a GCC equivalent?

I am not interested in using tuple_element_t. I am looking for an alternative that is a compiler primitive

like image 357
zrb Avatar asked Feb 07 '17 17:02

zrb


1 Answers

If you are really brave/crazy you could try and use the same techniques as kvasir::mpl does for this problem. In metaben.ch benchmarks its the same or faster than others who use __type_pack_element and works on GCC (note that the benchmark looks at every element, if you just ever index a few it will look quite different but usually if you want one then you eventually want the others too).

benchmark

implementation

old blog post about it

like image 131
odinthenerd Avatar answered Oct 26 '22 12:10

odinthenerd