Well, yes, I don't use all modifiers properly here, that's why it caused my admiration, I checked it, now I obfuscated the code, though I wanted just to write it compactly ))))
So far, it only works for arrays: 1) regular mql-arrays; 2) custom array classes, which should have [](int) operator defined and globalArraySize function overloaded.
Syntax:
foreach(element_var, array) { ... }
An array can be defined as either a variable or an expression - that's why we had to build the garden.) The expression is executed once, storing a pointer to the array, and then accessing the pointer.
So far, it works only for arrays: 1) regular mql-arrays; 2) custom array classes, which should have [](int) operator defined and global ArraySize function overloaded.
That's cool! Is it possible to make such a variant?
voidOnStart()
{
MqlTick Ticks[3];
for (int i = 0; i < ArraySize(Ticks); i++)
Ticks[i].bid = i + 1;
foreach(MqlTick Tick, Ticks) Print(Tick.bid); // OK
foreach(MqlTick Tick[1], Ticks) ArrayPrint(Tick); // 'Tick' - invalid array access
}
Yes, it is. When I started to look into it, I discovered an interesting peculiarity. When an argument of a constant type (const int, for example) is passed to a template, it is taken simply as: T = int, but the constancy is somehow taken into account too, which is confusing:
template<typename T>
class B { };
template<typename T>
void f(T & a)
{
B<const T> b; // OK. Значит T==int
const T arr[]={}; // Тоже всё ОК.
T arr2[]; // 'arr2' - 'const' variable must be initialized. wtf?
}
voidOnStart()
{
constint a=0;
f(a);
}
At first I thought it was a feature of MQL, but it's the same in C++.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
// Некоторые возможности структур, которых нет у классов.hm, interesting, really liked the idea with const fields, const will only be initialised once
hm, interesting, I like the idea with const fields, const will be initialized only once
you can now do lot normalization in this way:
You can declare constant members in classes too.
You can also declare constant members in classes.
Well, yes, I don't use all modifiers properly here, that's why it caused my admiration, I checked it, now I obfuscated the code, though I wanted just to write it compactly ))))
ZS: the folding in ME is really lacking! - it's tiring to roll the mouse wheel here and there (((My implementation of construct for each by MQL.
So far, it only works for arrays: 1) regular mql-arrays; 2) custom array classes, which should have [](int) operator defined and globalArraySize function overloaded.
Syntax:
foreach(element_var, array) { ... }An array can be defined as either a variable or an expression - that's why we had to build the garden.) The expression is executed once, storing a pointer to the array, and then accessing the pointer.
Usage examples:
Examples of use:
A little rewritten
My implementation of construct for each by MQL.
So far, it works only for arrays: 1) regular mql-arrays; 2) custom array classes, which should have [](int) operator defined and global ArraySize function overloaded.
That's cool! Is it possible to make such a variant?
That's cool! Is it possible to do a version of this?
foreach(Ticks[0], Ticks) ArrayPrint(Ticks[0].bid);Well, initializing an array with variables is not supported in MQL. You can do an assignment to an array element:
I haven't figured out the implementation, but I don't see the point in doing it that way.
This does not work
This variant doesn't work
At first I thought it was a feature of MQL, but it's the same in C++.
At first I thought it was a feature of MQL, but it's the same in C++ too.
because the type is const int. it is just that in the template you can still attach const to the front without any problems
but if in c++ you can remove const from a type by some simple manipulations, you can't do it in mql.