Features of the mql5 language, subtleties and tricks - page 46

 

The thread is called "Peculiarities of mql5 language, nuances and working methods", but instead 45 pages are discussing trading / trading operations and other stuff, which concerns specifically MT5, but not the programming language. So this topic could have been really useful and useful for programmers, people would have shared interesting features and constructions, but it has turned into another garbage dump.

 
Alexey Navoykov:

The thread is called "Peculiarities of mql5 language, nuances and working methods", but instead 45 pages are discussing trading / trading operations and other stuff, which concerns specifically MT5, but not the programming language. If to say that this topic could be really useful and useful for programmers, people would share interesting features and constructions, but it has turned into another garbage dump.

Unfortunately, yes, it is. There shouldn't be any questions and discussions here at all.
 
Alexey Navoykov:

The thread is called "Peculiarities of mql5 language, nuances and working methods", but instead 45 pages are discussing trading / trading operations and other stuff, which concerns specifically MT5, but not the programming language. So this topic could have been really useful and useful for programmers, people would have shared interesting features and constructions, but it has turned into another garbage dump.

Forum on trading, automated trading systems and strategy testing

Libraries: TypeToBytes

fxsaber, 2017.07.11 15:40

// Чтение/Запись private-полей простых структур

#include <TypeToBytes.mqh>

template <typename T>
struct STRUCT
{
private:
  T Data; // private-поле
  
public:
  T GetData( void ) const
  {
    return(this.Data);
  }
};

void OnStart()
{    
  STRUCT<int> Struct = {0};  
  
  _W(Struct) = 2;          // Write-доступ к private-полю
  Print(Struct.GetData()); // убедились штатно, что это так
  
  Print(_R(Struct)[0]);    // Read-доступ к private-полю
}
 
fxsaber:
Why do you need access to the private field from the outside? Is this some kind of perversion? ) Declare the field private first, and then try to access it. And not only read access, but write access as well! Well... That's really "subtleties and tricks of the trade". ))
 
Alexey Navoykov:
Why do you need access to the private field from the outside? Is it some kind of perversion? ) Declare the field private first, and then try to access it. And not only read access, but write access as well! Well... That's really "subtleties and tricks of the trade". ))

This is private-PR!

 
Attention, gentlemen programmers! We have a dangerous hacker, hacking into someone else's classes and ruthlessly changing their private fields! Be careful, take care of your classes.
 
// Объяснение, почему static-поля структур не являются на самом деле ее полями
// Поэтому структура может быть простой, даже если ее static-поле является объектом
struct STRUCT
{
  static string Str;
  int i;
};

string STRUCT::Str = NULL;

union UNION
{
  STRUCT Struct; // для сложной структуры была бы ошибка
  int i;
};

void OnStart()
{
  Print(sizeof(STRUCT)); // sizeof(int) == 4
}
 
fxsaber:

This is private-PR!

I suggest you, as the chief hacker of the classes, to tackle a more difficult task. Make it possible to access a private field by name, not by location (because location is very unreliable). Naturally, this should be in the form of a macro. This feature can be useful sometimes, if we want to fix something in someone else's library, without having to edit its source.
 

Has anyone done resource-efficient sorting of an array of structures by any (not string) given field of the structure?

Suppose there is a structure with three fields int, datetime and double, and there is an array filled with data consisting of this structure. In each cell of the array, the fields of the structure are populated.

How do I sort this array by any of these fields?

 
Artyom Trishkin:

Has anyone done resource-efficient sorting of an array of structures by any (not string) given field of the structure?

Suppose there is a structure with three fields int, datetime and double, and there is an array filled with data consisting of this structure. In each cell of the array, the fields of the structure are populated.

How do I sort this array by any of these fields?

Like this one?

https://www.mql5.com/ru/code/9336

ArrayEx
ArrayEx
  • votes: 4
  • 2009.11.19
  • Андрей
  • www.mql5.com
Библиотека реализует 3 основных функции работы с двумерными массивами: сортировка, группировка, выборка - по множественным критериям.