Zu diesem Zeitpunkt ist das beste, was wir (portabel) tun können, ein Makrotrick, wie gezeigt wurde for vtmpl::string
. Im Grunde erstellen wir eine Liste von Zugriffen wie
... die wir trimmen, um das gewünschte Ergebnis zu erhalten.
Der erste Schritt ist leicht über BOOST_PP_ENUM
getan, obwohl rekursive Makros auch in Ordnung sind (Definition von 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)
Verwendung der oben sieht wie folgt aus (inklusive Trimmen):
#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 )
Dabei ist rtrim
in algorithms.hxx
definiert.
[N3599] (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3599.html) kann es in C++ 1Z machen. – Columbo
Brauchen Sie wirklich eine 'integer_sequence'? Das riecht nach einem XY-Problem. – Columbo
@Columbo Woher haben Sie diese Informationen? Zuletzt hörte ich, dass es in EWG zugunsten eines 'string_literal' abgelehnt wurde. –