Coder Social home page Coder Social logo

Comments (6)

dingmaotu avatar dingmaotu commented on June 8, 2024

@janckerchen Thank you for the feedback. Doc has been updated.

The Iter class had been deprecated for a while, as I found a new trick to implement a foreach macro. Do check out the foreach macro, it works just as you wanted.

It is generally not recommended to do insertion while in iteration. The iterator will be invalidated due to size change. A temporary solution might be:

Vector<int> idx;
int i=-1;
foreach(T, list)
{
++i;
T e = it.current();
if(e match condition) idx.push(i+idx.size()); // note that index will change after previous insertions
}
foreach(int,idx) list.insert(it.current(), new T);

I know this is verbose but this is currently the only safe way to do what you want.
I have plans to make iterator support element removal and insertion. As we are in rapid development of a complex product (which uses this library), the collection code will see constant improvements. Any feedback is welcome.

from mql4-lib.

janckerchen avatar janckerchen commented on June 8, 2024

I just found a insert() method in LinkedList, but the params type is different from your example, further more it is under protected limit, cant access by list.insert().

protected:
   void              insert(LinkedNode<T>*ref,LinkedNode<T>*node);

from mql4-lib.

dingmaotu avatar dingmaotu commented on June 8, 2024

Use public insert of ArrayList. You use insertion position by index, not by element reference.

from mql4-lib.

janckerchen avatar janckerchen commented on June 8, 2024

foreach is a macro, as your code style, I think it should be UPPER_CASE.

If I just wanna find something then break in iteration, SafeDelete(it) at the end of loop, as your foreach macro defined, have no chance to be executed then memory leak show up.

from mql4-lib.

dingmaotu avatar dingmaotu commented on June 8, 2024

Normally macros should be upper case, but I want foreach to be a language construct just like a keyword.

Yes, the foreach macro can not handle exceptional control flow where it pointer has no chance to be deleted. Afraid that Iter class has to be bring back 😜 . This bug will be fixed soon. Thanks for the bug report . You can open new issues for easier tracking.

from mql4-lib.

janckerchen avatar janckerchen commented on June 8, 2024

ok, I will open new issue, thanks to your effort.

from mql4-lib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.