Hi, I would like to overload the subscript operator so that I can use tuples like an array
e.g.
mytuple[0];
Here is what I've coded, but I am new to using templates so I don't know what is happening, could someone tell me what I'm doing wrong & what should be done?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <tuple>
template <typename T>
T tuple::operator[](constint index) {
return get<index>(tuple);
}
...
int main()
{
int a=14;
tuple<int,string,char> myTuple;
myTuple[0]=1;
a=myTuple[0];
...
return 0;
I was also going to add that it is mostly prohibited to add behavior to the standard library. This is at least because the implementation may rely on the interface to select the correct behavior.