According to boost :: tuple documentation , accessing a single tuple element has the same performance as accessing a member variable. For example, given the following declaration:
tuple<A, B, C> t1(A(), B(), C()); struct T { A a; B b; C c; } T t2;
These two operators should have equal (or with a slight difference) performance:
t1.get<2>(); t2.c;
I looked at the sources of boost :: tuple and, if I understood them correctly (I'm not sure what I did), the get<N> function actually performs this action:
C get<2>(tuple<A, B, C>& t) { return t.tail.tail.head; //Generally: return t.tail. <<N times>> .head; }
This is more like searching in a linked list than direct access, and as I understand it, has the complexity O (N) instead of O (1) expected from accessing a member. From my past experience with amplification, I assume that I was wrong; but what is my mistake? How does get work?
c ++ boost templates boost-tuples
Fireaphis
source share