U++ framework
Do not panic. Ask here before giving up.

Home » Developing U++ » UppHub » Anonymous delegates
Re: Anonymous delegates [message #13019 is a reply to message #12541] Wed, 05 December 2007 15:33 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Zardos wrote on Wed, 07 November 2007 21:17

If you use it, please be aware it's still only a macro.

To illustrate the fundamentel problem a simple example:

Vector<int> CreateResultVector() {
   Vector<int> r;
   r.Add(1);
   r.Add(2);
   r.Add(3);
   return r;
}

...

foreach(int e, CreateResultVector())
   DUMP(e);


Basically the code is stupidly translated to something like this:
for(int i = 0; i < CreateResultVector().GetCount(); i++)
   DUMP(CreateResultVector()[i]);


... CreateResultVector is called multiple times!
But this is probably not what you would expect from a real foreach build into the language!



Curiously, this is exactly what I would expect... (I mean, called multiple times).

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: FontSel dialog
Next Topic: ChessBoard
Goto Forum:
  


Current Time: Sun Aug 02 15:20:18 GMT+2 2026

Total time taken to generate the page: 0.00679 seconds