MQL5Book/Include/PRTF.mqh
2025-06-12 13:40:26 +01:00

23 lines
1 KiB
MQL5

//+------------------------------------------------------------------+
//| PRTF.mqh |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include "MqlError.mqh"
#define PRTF(A) ResultPrint(#A, (A))
//+------------------------------------------------------------------+
//| Helper printer returning result and checking errors |
//+------------------------------------------------------------------+
template<typename T>
T ResultPrint(const string s, const T retval = NULL)
{
const int snapshot = _LastError; // required because _LastError is volatile
const string err = E2S(snapshot) + "(" + (string)snapshot + ")";
Print(s, "=", retval, " / ", (snapshot == 0 ? "ok" : err));
ResetLastError(); // cleanup for next execution
return retval;
}
//+------------------------------------------------------------------+