A questo punto nel tempo, il meglio che possiamo (portabile) fare è un trucco macro come dimostrato for vtmpl::string
. Fondamentalmente, creiamo un elenco di accessi come
"abcd" -> {(0 < sizeof "abcd"? "abcd"[0] : 0), (1 < sizeof "abcd"? "abcd"[1] : 0), ...}
... che abbiamo tagliato per ottenere il risultato desiderato.
Il primo passo è fatto facilmente attraverso BOOST_PP_ENUM
, anche se le macro ricorsive sono anche bene (definizione da here):
#define VTMPL_SPLIT_1(s, x, m) m(s, x)
#define VTMPL_SPLIT_4(s, x, m) VTMPL_SPLIT_1 (s, x, m), VTMPL_SPLIT_1 (s, x+1 , m), VTMPL_SPLIT_1 (s, x+2 , m), VTMPL_SPLIT_1 (s, x+3 , m)
#define VTMPL_SPLIT_16(s, x, m) VTMPL_SPLIT_4 (s, x, m), VTMPL_SPLIT_4 (s, x+4 , m), VTMPL_SPLIT_4 (s, x+8 , m), VTMPL_SPLIT_4 (s, x+12 , m)
#define VTMPL_SPLIT_64(s, x, m) VTMPL_SPLIT_16 (s, x, m), VTMPL_SPLIT_16 (s, x+16 , m), VTMPL_SPLIT_16 (s, x+32 , m), VTMPL_SPLIT_16 (s, x+48 , m)
#define VTMPL_SPLIT_256(s, x, m) VTMPL_SPLIT_64 (s, x, m), VTMPL_SPLIT_64 (s, x+64 , m), VTMPL_SPLIT_64 (s, x+128, m), VTMPL_SPLIT_64 (s, x+194, m)
#define VTMPL_SPLIT_1024(s, x, m) VTMPL_SPLIT_256(s, x, m), VTMPL_SPLIT_256(s, x+256, m), VTMPL_SPLIT_256(s, x+512, m), VTMPL_SPLIT_256(s, x+768, m)
Uso dei look di cui sopra come questo (trimming inclusa):
#define VTMPL_STRING_IMPL(str, n) vtmpl::rtrim<vtmpl::value_list<decltype(*str), VTMPL_SPLIT_##n(str, 0, VTMPL_ARRAY_SPLIT)>>::type
#
#define VTMPL_STRING(str) VTMPL_STRING_IMPL(str, 64 )
Dove rtrim
è definito in algorithms.hxx
.
[N3599] (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3599.html) può trasformarsi in C++ 1Z. – Columbo
Hai davvero bisogno di un 'integer_sequence'? Questo ha l'odore di un problema XY. – Columbo
@Columbo Dove hai preso quell'informazione? Infine ho sentito che è stato rifiutato in EWG in favore di un 'string_literal'. –