maybe something like this ...
void arrayfunction(int& array1[], double& array2[], string& array3[], int type) { switch(type) { case 1: //operate on int array case 2: //operate on double array case 3: //operate on string array } }
I made a function ArrayPrepend() that insert a value in the first element [0] of an array
shifting the values already present down by 1. (the last element is lost)
Currently I need 2 different functions to do this, because ArrayPrepend() only accept arrays of the declared type:
Do you know any way to make it type-indipendent? A single ArrayPrepend() that accept double and int types?
Thank you
Why don't you just make it a series array and increase it's size by one, then make it a non series array and reduce it's size by one . . . thats how I do it, test it against your current version I assume it will be a lot faster.
// INSERTION OF THE VALUE 'K' AT THE TOP OF THE ARRAY // [0] show where is the first element // [0] -> { A , B , C , D } ArraySetAsSeries( vector, true ) // { A , B , C , D } <- [0] ArrayResize( vector, ArraySize(vector)+1 ) // { _ , A , B , C , D } <- [0] ArraySetAsSeries( vector, false ) // [0] -> { _ , A , B , C , D } ArrayResize( vector, ArraySize(vector)-1 ) // [0] -> { _ , A , B , C } vector[0] = K // [0] ->{ K , A , B , C }
Yes it does but it would still mean creating two functions. I would like to compare the speed of doing it one function by passing an ID variable to define the type like I did above, with creating a class and two overloaded functions in the C++ way, I might do that in the new beta later and see which is faster. (I might suprise myself by accomplishing that without getting all lost in a C++ mess)
Here some dirty trick, just for the fun of it.. uses a system dll's memcpy.
The other possibillity is to use your own dll where you are free to do what you want.
// MT4 - build 568 script #import "msvcrt.dll" int memcpy(int&[], int&[], int); int memcpy(double&[], double&[], int); int memcpy(int, int, int); #import int int_array[3] = {3, 2, 1}; int int_element[1]; double double_array[3] = {3.3, 2.2, 1.1}; double double_element[1]; // note: the following first two parameters do not in fact transport ints but pointers to memory void push_front(int dst, int src, int dst_size, int src_size) { memcpy(dst + src_size, dst, dst_size - src_size); memcpy(dst, src, src_size); } void OnStart() { int_element[0] = 4; // push 4 to front of int_array push_front(memcpy(int_array, int_array, 0), memcpy(int_element, int_element, 0), ArraySize(int_array)*sizeof(int), sizeof(int)); for(int i = 0; i < ArraySize(int_array); i++) Print(int_array[i]); double_element[0] = 4.4; // push 4.4 to front of double_array push_front(memcpy(double_array, double_array, 0), memcpy(double_element, double_element, 0), ArraySize(double_array)*sizeof(double), sizeof(double)); for(i = 0; i < ArraySize(double_array); i++) Print(double_array[i]); }
Hmmm thats interesting so how did you know memcpy is in that dll and how did you know the correct parameters to pass to it ?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I made a function ArrayPrepend() that insert a value in the first element [0] of an array
shifting the values already present down by 1. (the last element is lost)
Currently I need 2 different functions to do this, because ArrayPrepend() only accept arrays of the declared type:
Do you know any way to make it type-indipendent? A single ArrayPrepend() that accept double and int types?
Thank you