Efficiency of std::get with std::tuple
c++, c++11
Solution
The C++ specification does not provide a guarantee on the runtime performance of any function. Even when it states asymptotic requirements, that only guarantees the relative number of operations, not the performance of those operations. O(1) doesn't mean fast, nor does O(n) mean slow.
You can either trust your compiler/optimizer/standard library implementation, or you can rewrite it all yourself to get whatever performance you want. `std::get`, under most reasonable compilers (with optimizations on), should perform more or less equivalently to directly accessing the value from a struct. But the spec doesn't require that at any point.
Problem
I'm curious as to the lookup time that a call to `std::get<>` on a `std::tuple<>` takes. Some brief googling (including the reference pages which usually have this information) turned up no results. My initial intuition (and fear) is that the recursive structure of tuple (if it is implemented as a variadic template) would lead to get requiring an order of N lookups (A call to `get<3>(t)` looking like `t.rest().rest().first()`. I'm hoping I'm way off here... Then again, I would hope the compiler would be able to optimize this to directly return the correct offset without the overhead of N of calls. Basically what I want: is there a specced guarantee on runtime? does this restrict how `std::tuple` is implemented?