MQL5Book/Include/TypeName.mqh

28 lines
1 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:09:41 +02:00
//+------------------------------------------------------------------+
//| TypeName.mqh |
//| Copyright (c) 2022, MetaQuotes Ltd. |
//| https://www.mql5.com/ |
//| |
//| Provides stripped down type name to mimic legacy typename() |
//+------------------------------------------------------------------+
string _typename(const string t)
{
static const string keywords[] = {"class", "struct", "enum", "union", "interface"};
static const int n = sizeof(keywords) / sizeof(keywords[0]);
static string tokens[];
if(StringSplit(t, ' ', tokens) <= 1) return t;
for(int i = 0; i < n; ++i)
{
if(keywords[i] == tokens[0]) return tokens[1];
}
return tokens[0];
}
#define TYPENAME(T) _typename(typename(T))
//+------------------------------------------------------------------+