Re: operator[] with multiple arguments
"Seungbeom Kim" <musiphil@bawi.org> skrev i meddelandet
news:ea8tu5$3i1$1@news.Stanford.EDU...
Carl Barron wrote:
A[i][j] is (A[i])[j] A[i] returns a Matrix::proxy and then
calls
Matrix::proxy::operator [](j) which returns a T & to the A[i][j] in
the
'usual sense'.
It works, but it is more complicated, and more tedious to write and
maintain. We need two similar but different proxies for the const
and
non-const versions. And an additional pair of proxies for each extra
dimension.
And there could be performance issues: When I tested with gcc-3.3.5
on
i486-linux, I found that the proxy version doesn't produce as
efficient
a machine code as the directly-with-one-operator() version, even
with a
high optimize level. Fortunately both seem to produce the same
machine
code with gcc-4.0.2 on i486-linux, but there may still be less good
compilers around.
Should we change the language to support bad compilers, or should we
demand good compilers? :-)
Bo Persson
---
[ 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 ]