In a recent mail on the boost developers mailing list Eric Niebler mentioned that it is possible to get the last element of a template parameter pack in O(1) instantiations.
How can this be done?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can check https://github.com/ericniebler/proto-0x/blob/master/boost/proto/utility.hpp, as mentioned in the post, on how the
get_nthmetafunctions are implemented. The essence, after much simplification:Actually it is O(log N), not O(1), because of the time taken in
RepeatVoid.But this method does perform much better than linear methods like the typical implementation of
tuple_element<>. I have tried to compare the performance ofGetNthwithtuple_element<>on getting the item 899 of a list, and the latter is an order of magnitude faster: