Re: operator[][][]
"Frederick Gotham" <fgothamNO@SPAM.com> wrote...
The "fishing rod" solution would allow defining operator[] with any
statically-known number of levels.
I shudder to think that you gathered I was implying that only:
operator[][][]
should be allowed, rather than any amount of them:
operator[][][][]
operator[][][]
operator[][][][][]
operator[][]
How about this? The definition syntax should allow having more than
one argument, and the utilisation syntax should check the number of
bracket pairs after the expression and reach for an overloaded operator
with the same number of arguments. Like
class C {
public:
int operator[](int a, char b) { return 42; } // 1
char const* operator[](char const* s) { return s; } // 2
};
int main() {
C c;
c[22]['a']; // resolves to 1 rather than 2 - exact match
// calls c.operator[](22,'a')
c["abc"][1]; // resolves to 2 - closer match
// calls c.operator[]("abc") and then
// indexes the resulting pointer
}
Or am I completely missing the point here? If so, I'm sorry.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]