ericniebler / meta

A tiny metaprogramming library
Boost Software License 1.0
302 stars 47 forks source link

Does __make_integer_seq intrinsic make it possible to implement meta::take in O(1)? #39

Open ericniebler opened 8 years ago

gabyx commented 8 years ago

what does meta::take do? is it already implemented?

(take the n-th element?)

ericniebler commented 8 years ago

See take from the Haskell Prelude for a description. Meta already has drop, but I haven't found a way to implement take in O(1) so I haven't provided it.

ldionne commented 6 years ago

You can prepare the pack of indices you want to take in O(1) (using __make_integer_seq, and then expand into a list using the __type_pack_element intrinsic explained in a blog post). That's technically O(K) for K elements taken because you have multiple calls to __type_pack_element, but may still be fast since it's an intrinsic. I've also worked on another intrinsic to basically take a subsequence of a parameter pack, but never submitted it for review in Clang.