HYROLEAN

hyrTmpl.mqh

Mar 9th, 2026 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | Money | 0 0
  1. // hyrTmpl.mqh
  2. //   by 2025 hyrolean
  3. //---------------------------------------------------------------------------
  4. // Local:: <DataFolder>\MQLx\Include\User\hyrTmpl.mqh
  5. // URL:: https://pastebin.com/LG1vurny
  6. //===========================================================================
  7. // インラインテンプレート
  8. //---------------------------------------------------------------------------
  9. //オブジェクトのソート
  10. // ( https://youtu.be/ZRPiwUNLjiA )
  11. #include <Arrays/ArrayObj.mqh>
  12. #define ARRAY_SORT_ASCEND 1
  13. #define ARRAY_SORT_DESCEND 2
  14. template <typename T>
  15. class CSortable : public CObject {
  16. public:
  17.     T v;
  18.     int Compare(const CObject *node, const int mode=0) const {
  19.       if(mode<=0) return 0;
  20.       CSortable *comp= (CSortable*)node ;
  21.       bool f = v<comp.v ;
  22.       if(!f&&!(comp.v<v)) return 0;
  23.       int result = f ? -1:+1 ;
  24.       switch(mode) {
  25.         case ARRAY_SORT_ASCEND:  return +result;
  26.         case ARRAY_SORT_DESCEND: return -result;
  27.       }
  28.       return 0;
  29.     }
  30.     CSortable(const T& v_) : CObject(), v(v_) {}
  31. };
  32. template <typename T>
  33. void AddToArray(CArrayObj &array, const T& v) {
  34.   CSortable<T> *node = new CSortable<T>(v);
  35.   array.Add(node);
  36. }
  37. template <typename T>
  38. void AddToSortedArray(CArrayObj &array, const T& v) {
  39.   CSortable<T> *node = new CSortable<T>(v);
  40.   array.InsertSort(node);
  41. }
  42. template <typename T>
  43. int SearchSortedArray(CArrayObj &array, const T& v) {
  44.   CSortable<T> node(v);
  45.   return array.Search(&node);
  46. }
  47. //---------------------------------------------------------------------------
  48.  
Tags: Mt4 Mt5
Advertisement
Add Comment
Please, Sign In to add comment