www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

D - opIndex

↑ ↓ ← "Matthew Wilson" <matthew.hat stlsoft.dot.org> writes:
The examples given on the site have the binary opIndex returning a value of
the same type as the second parameter, as in

 struct A
	{
	    int opIndex(int i);
	    int opIndex(int i, int value);
}

Is this so that it can be reused in expressions such as the following

A a1 = ...
A a2 = ...

a1[10] = a2[5] = 3;

I presume the author returns the new value, rather than the previous value?

Matthew
Dec 18 2003
↑ ↓ → "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew.hat stlsoft.dot.org> wrote in message
news:brs079$2n2g$2 digitaldaemon.com...
 The examples given on the site have the binary opIndex returning a value

 the same type as the second parameter, as in

  struct A
 {
     int opIndex(int i);
     int opIndex(int i, int value);
 }

 Is this so that it can be reused in expressions such as the following

 A a1 = ...
 A a2 = ...

 a1[10] = a2[5] = 3;

 I presume the author returns the new value, rather than the previous

The return type and value from opIndex is whatever the programmer specifies it to be.
Dec 19 2003