How do I remove an element from an array (one-dimensional two-dimensional)? - page 8

 
Dmitry Fedoseev:

It compiles, but it's not interesting, and what about z[][][]?

The second and above dimensions cannot be dynamic, but the function does not need to be customized for a particular size of the second dimension, it can be found out through ArrayRange().

If the number of measurements won't allow to overload the function, the size of the second and other measurements certainly won't. Besides, it's not interesting at all, since it is not universal at all. It would be much easier to write functions with different names.

You mean it should be written like this?

void z(int size_second_dimension,int & z[][4],int shift){};

if there are 4 elements in the second dimension?

 
Alexey Viktorov:

You mean it should be written like this?

if there are 4 elements in the second dimension?

Write it that way if you want, I don't mind.

 

That's the way it's going to be:

void z4(int & a[][][][],int Start,int Count=1){
   int n=ArrayRange(a,1)*ArrayRange(a,2)*ArrayRange(a,3);
   ArrayCopy(a,a,Start*n,(Start+Count)*n);
   ArrayResize(a,ArrayRange(a,0)-Count);
};
void z3(int & a[][][],int Start,int Count=1){
   int n=ArrayRange(a,1)*ArrayRange(a,2);
   ArrayCopy(a,a,Start*n,(Start+Count)*n);
   ArrayResize(a,ArrayRange(a,0)-Count);
};
void z2(int & a[][],int Start,int Count=1){
   int n=ArrayRange(a,1);
   ArrayCopy(a,a,Start*n,(Start+Count)*n);
   ArrayResize(a,ArrayRange(a,0)-Count);
};
void z1(int & a[],int Start,int Count=1){
   ArrayCopy(a,a,Start,Start+Count);
   ArrayResize(a,ArrayRange(a,0)-Count);
};
 
Dmitry Fedoseev:

Write like that if you want, I don't mind.

I asked because I haven't had a chance to experiment.

 
Dmitry Fedoseev:

That's what it looks like:

Then ArrayResize should be set to -Count, not -1, no?

 
Ilya Malev:

Then ArrayResize should be set to -Count, not -1, no?

Yeah. Corrected.

 
Alexey Viktorov:

I asked because I haven't had a chance to experiment.

You don't need to and it won't help for overloading.

 

Then like this?

#define  ArrayDel(A,S,C) {int n=fmax(1,ArrayRange(A,3))*fmax(1,ArrayRange(A,2))*fmax(1,ArrayRange(A,1)); \
                              ArrayCopy(A,A,S*n,(S+C)*n); ArrayResize(A,ArrayRange(A,0)-C);}
True, we need to clarify that this is removing the index by the first dimension, not removing an element (if a multidimensional array is passed, then all "elements" by the S index of the first dimension are removed).
 
Dmitry Fedoseev:

You don't need to and it won't help for overloading.

Why not?

Will this untested version work?

class CDellArrayElement
  {
public:
  void DellArrayElement(int &arr[], int Start, int Count=1);
  void DellArrayElement(int &arr[][], int size_1_dimension, int Start, int Count=1);
  void DellArrayElement(int &arr[][][], int size_1_dimension, int size_2_dimension, int Start, int Count=1);
  void DellArrayElement(int &arr[][][][], int size_1_dimension, int size_2_dimension, int size_3_dimension, int Start, int Count=1);
  };

//+------------------------------------------------------------------+
//|            Одномерный массив                                     |
//+------------------------------------------------------------------+
void CDellArrayElement::DellArrayElement(int &arr[], int Start, int Count=1)
{
 ArrayCopy(arr, arr, Start, Start+Count);
 ArrayResize(arr, ArrayRange(arr,0)-Count);
};
//+------------------------------------------------------------------+
//|            Двухмерный массив                                     |
//+------------------------------------------------------------------+
void CDellArrayElement::DellArrayElement(int &arr[][], int size_1_dimension, int Start, int Count=1)
{
 ArrayCopy(arr, arr, Start*size_1_dimension, (Start+Count)*size_1_dimension);
 ArrayResize(arr, ArrayRange(arr,0)-Count);
};
//+------------------------------------------------------------------+
//|            Трёхмерный массив                                     |
//+------------------------------------------------------------------+
void CDellArrayElement::DellArrayElement(int &arr[][][],int size_1_dimension,int size_2_dimension,int Start,int Count=1)
{
 int n = size_1_dimension*size_2_dimension;
 ArrayCopy(arr,arr, Start*n, (Start+Count)*n);
 ArrayResize(arr, ArrayRange(arr, 0)-Count);
};
//+------------------------------------------------------------------+
//|            Четырёхмерный массив                                  |
//+------------------------------------------------------------------+
void CDellArrayElement::DellArrayElement(int &arr[][][][],int size_1_dimension,int size_2_dimension,int size_3_dimension,int Start,int Count=1)
{
 int n = size_1_dimension*size_2_dimension*size_3_dimension;
 ArrayCopy(arr, arr, Start*n, (Start+Count)*n);
 ArrayResize(arr, ArrayRange(arr, 0)-Count);
};


I saw Ilya's variant and didn't want to check it, because it's an empty undertaking.

The second way of working with structures. You can work with an array of structures like with a one-dimensional array.

struct a
{
 int b;
 double c;
 datetime d;
}array[];

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnStart()
  {
//---
   ArrayResize(array, 6);
   double op[];
    CopyOpen(_Symbol, PERIOD_CURRENT, 0, 6, op);
   datetime ti[];
    CopyTime(_Symbol, PERIOD_CURRENT, 0, 6, ti);
   for(int i = 0; i < 6; i++)
    {
     array[i].b = i;
     array[i].c = op[i];
     array[i].d = ti[i];
    }
   ArrayPrint(array);
 ArrayCopy(array, array, 4, 5);
 ArrayResize(array, 5);
   ArrayPrint(array);
//---
  }

The result is

2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)            [b]     [c]                 [d]
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [0]   0 1.14110 2018.12.24 12:30:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [1]   1 1.14096 2018.12.24 12:35:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [2]   2 1.14079 2018.12.24 12:40:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [3]   3 1.14064 2018.12.24 12:45:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [4]   4 1.14069 2018.12.24 12:50:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [5]   5 1.14036 2018.12.24 12:55:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)            [b]     [c]                 [d]
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [0]   0 1.14110 2018.12.24 12:30:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [1]   1 1.14096 2018.12.24 12:35:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [2]   2 1.14079 2018.12.24 12:40:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [3]   3 1.14064 2018.12.24 12:45:00
2018.12.24 13:55:20.336 TestDellArrayElement (EURUSD,M5)        [4]   5 1.14036 2018.12.24 12:55:00
 
Alexey Viktorov:

I saw Ilya's variant and didn't check it because it's an empty undertaking.

You're right, because you can't pass more than 1-dimensional array to a function withint &arr[] signature.