I have to use some library that for some reason has very ugly classes:
template<char chr1='a', char chr2='b',char... _T_NAME>
class CParserVarFloat: public CParserVarNamed<chr1,chr2, _T_NAME ...>{
...
}
Yes, they could just use std::string
(especially when, inside of that class' constructor, they create temporary std::vector
to store the characters...). But they did not.
In order to create the variable I would have to write:
CParserVarFloat<'t', 'e', 'x', 't', 0, [[45 times 0 here]] > myVariable;
But I would like to create some c++ macro, so the code could look like:
CParserVarFloat<CHAR50_ARR("text")> myVariable;
So basically I need to convert "text" into 't', 'e', 'x', 't', 0, [[45 times 0 here]] with a macro. Note that I cannot use dynamic arrays as the parameters must be declared in compile-time.
The library suggests to use some _CONST_CHAR(s)
:
#define _CONST_CHAR(s)\
getChr(s,0),\
getChr(s,1),\
getChr(s,2),\
getChr(s,3),\
getChr(s,4),\
getChr(s,5),\
getChr(s,6),\
getChr(s,7),\
getChr(s,8),\
getChr(s,9),\
getChr(s,10),\
getChr(s,11),\
getChr(s,12),\
getChr(s,13),\
getChr(s,14),\
getChr(s,15),\
getChr(s,16),\
getChr(s,17),\
getChr(s,18),\
getChr(s,19),\
getChr(s,20),\
getChr(s,21),\
getChr(s,22),\
getChr(s,23),\
getChr(s,24),\
getChr(s,25),\
getChr(s,26),\
getChr(s,27),\
getChr(s,28),\
getChr(s,29),\
getChr(s,30),\
getChr(s,31),\
getChr(s,32),\
getChr(s,33),\
getChr(s,34),\
getChr(s,35),\
getChr(s,36),\
getChr(s,37),\
getChr(s,38),\
getChr(s,39),\
getChr(s,40),\
getChr(s,41),\
getChr(s,42),\
getChr(s,43),\
getChr(s,44),\
getChr(s,45),\
getChr(s,46),\
getChr(s,47),\
getChr(s,48),\
getChr(s,49),\
getChr(s,50)
#define getChr(name, ii) ((MIN(ii,MAX_CONST_CHAR))<strlen(name)?name[ii]:0)
Which is both ugly and non-constant at all (the code does not compile on VC++ 2013, because of ... ? name[ii]:0
part).