我必须使用一些库,由于某种原因,它有非常难看的类:
template<char chr1='a', char chr2='b',char... _T_NAME>
class CParserVarFloat: public CParserVarNamed<chr1,chr2, _T_NAME ...>{
...
}
是的,他们可以只使用std::string
(特别是在该类的构造函数内部,他们创建临时std::vector
来存储字符...)。但他们没有。
为了创建变量,我必须写:
CParserVarFloat<'t', 'e', 'x', 't', 0, [[45 times 0 here]] > myVariable;
但是我想创建一些c ++宏,所以代码看起来像:
CParserVarFloat<CHAR50_ARR("text")> myVariable;
所以基本上我需要用“宏”将“text”转换为't','e','x','t',0,[[45 times 0 here]]。请注意,我不能使用动态数组,因为参数必须在编译时声明。
图书馆建议使用一些_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)
哪个都是丑陋的和非常量的(代码不能在VC ++ 2013上编译,因为... ? name[ii]:0
部分)。