Amir Yacoby: I try to avoid static classes, would rather the plain #define if any.
The problem with using plain #defines is that they won't work with templates like the class version does. For example, if we were to templatize the ring buffer class then all we'd have to do is the following (snippet)
template<typename T>
bool CArrayRing::Init(int size, T volue=WRONG_VALUE)
{
volue = volue == WRONG_VALUE ? NONE(T) : volue;
m_last_pos=0; // last element position
m_filling=volue; // value for buffer filling
m_size=ArraySize(m_data); // get size of the buffer bool result=Resize(size); // create a buffer with the desired sizeArrayFill(m_data,0,m_size,m_filling); // fill the buffer with default valuesreturn(result);
}
The problem with using plain #defines is that they won't work with templates like the class version does. For example, if we were to templatize the ring buffer class then all we'd have to do is the following (snippet)
This is why I said the std lib is not holy:
class CObject
{
protected:
double None(const double) const {return(double)"nan";}
char None(const char) const {return CHAR_MAX;}
uchar None(const uchar) const {return UCHAR_MAX;}
int None(const int) const {return INT_MAX;}
uint None(const uint) const {return UINT_MAX;}
long None(const long) const {return LONG_MAX;}
ulong None(const ulong) const {return ULONG_MAX;}
short None(const short) const {return SHORT_MAX;}
ushort None(const ushort) const {return USHORT_MAX;}
datetime None(const datetime) const {return WRONG_VALUE;}
color None(const color) const {return clrNONE;}
string None(const string) const {return "__NULL-*-*-STRING__";}
};
template<typename T>
class CArrayRing : public CObject
{
public:
//+------------------------------------------------------------------+//| Buffer initialization method. |//+------------------------------------------------------------------+template<typename T>
bool CArrayRing::Init(int size,T volue=WRONG_VALUE)
{
volue=volue==WRONG_VALUE ? None(volue) : volue;
m_last_pos=0; // last element position
m_filling=volue; // value for buffer filling
m_size=ArraySize(m_data); // get size of the buffer bool result=Resize(size); // create a buffer with the desired sizeArrayFill(m_data,0,m_size,m_filling); // fill the buffer with default valuesreturn(result);
}
};
MQL's first anonymous functions. ;)
Romantically beautiful and useful to me, thnx Fxsaber
I I like it!
What do you guys think about the implementation of NONE(type)?
What do you guys think about the implementation of NONE(type)?
I do not use this opportunity. But your implementation looks fine.
I I like it!
What do you guys think about the implementation of NONE(type)?
Instead of:
Pretty nice. But is there a reason for using the merge operator in the macro?
Instead of:
Reason:
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Обсуждение статьи "LifeHack для трейдера: замешиваем ForEach на дефайнах (#define)"
fxsaber, 2018.02.15 08:40
Reason:
I try to avoid static classes, would rather the plain #define if any.
The problem with using plain #defines is that they won't work with templates like the class version does. For example, if we were to templatize the ring buffer class then all we'd have to do is the following (snippet)
The problem with using plain #defines is that they won't work with templates like the class version does. For example, if we were to templatize the ring buffer class then all we'd have to do is the following (snippet)