2016-12-12 2 views
1

Dies ist ein Nachfolger zu Kerrek SB usw. vorherige Frage auf hübsch-Drucken STL-Container Pretty-print C++ STL containers, für die Kerrek etc gelungen ist, eine sehr elegante und vollständig allgemeine Lösung zu entwickeln, und seine Fortsetzung, Pretty-print std::tuple, wobei std::tuple<Args...> behandelt wird.pretty-print C++ - Container mit Einzug nach Ebene

Ich frage mich, ob es möglich ist, in der Lösung über Einzug einzubeziehen?

Zum Beispiel, wenn ich einen Vektor von Vektor der Vektor der Zeichenfolge haben, würde Ich mag, wie etwas sehen:

{ // vector of vector of vector of string 
    { // vector of vector of string 
     { hello, world };// vector of string 
     { The, quick, brown, fox, jumps, over, the, lazy, dog }; 
     ... 
     { Now, is, the, time, for, all, good, men, to, come, to, the, aid, of, the, party} 
    }; 
    { // vector of vector of string 
     { hello, world };// vector of string 
     { The, quick, brown, fox, jumps, over, the, lazy, dog }; 
     ... 
     { Now, is, the, time, for, all, good, men, to, come, to, the, aid, of, the, party} 
    }; 
    ... 
    { // vector of vector of string 
     { hello, world };// vector of string 
     { The, quick, brown, fox, jumps, over, the, lazy, dog }; 
     ... 
     { Now, is, the, time, for, all, good, men, to, come, to, the, aid, of, the, party} 
    }; 
} 

Wie das schön gemacht werden würde?

Antwort

2

Hinweis: Dies ist keine ‚echte‘ Antwort auf die Frage, wie ich es interpretieren, weil ich vermute, dass OP eine allgemeine Lösung will, die für beliebig verschachtelt Behälter richtige Vertiefung verwendet.

Als Workaround können Sie natürlich die gegebenen Lösungen verwenden und Präfix, Delimiter und Postfix richtig einstellen.

Example:

using namespace std::string_literals; 

using vs = std::vector<std::string>; 
using vvs = std::vector<std::vector<std::string>>; 
using vvvs = std::vector<std::vector<std::vector<std::string>>>; 
std::cout << pretty::decoration<vs>("  { ", ", ", " }"); 
std::cout << pretty::decoration<vvs>(" {\n", ",\n", "\n }"); 
std::cout << pretty::decoration<vvvs>("{\n", ",\n", "\n}\n"); 

std::vector<std::string> vs1 = { "hello"s, "world"s }; 
std::vector<std::string> vs2 = { "The"s, "quick"s, "brown"s, "fox"s }; 
std::vector<std::vector<std::string>> vvs1 = { vs1, vs1, vs2 }; 
std::vector<std::vector<std::string>> vvs2 = { vs2, vs1, vs2 }; 
std::vector<std::vector<std::vector<std::string>>> vvvs1 = { vvs1, vvs2 }; 

std::cout << vvvs1; 

Drucke:

{ 
    { 
     { hello, world }, 
     { hello, world }, 
     { The, quick, brown, fox } 
    }, 
    { 
     { The, quick, brown, fox }, 
     { hello, world }, 
     { The, quick, brown, fox } 
    } 
} 
+0

thx für die Antwort, ja, ich bin für eine generische suchen. – athos