Editing BoostCon 2007/Container Printing Lib - Built-In Format Examples
BOOST WIKI
|
RecentChanges
|
Preferences
|
Page List
|
Links List
=== See the Sandbox === This page has been replaced with BoostTest files in the boost sandbox. This page is no longer being updated. - Jared === Test Examples for the default built in formatter === This page is an attempt to show default usage with a selection of built-in and standard library types to get an idea of what our default output should be. Once these have been hashed out, they should be put into test cases, and this page can go away. === Simple Types === ==== int ==== int i = 123; print(i); ''output: 123'' ==== float ==== float f = 1.234f; print(f); ''output: 1.234'' ==== string ==== string s = "some string"; print(s); ''output: some string'' ==== bool ==== bool b = true; print(b); ''output: true'' b = false; print(b); ''output: false'' === Container Types === ==== pair ==== pair<int,int> pi = make_pair(1,2); print(pi); ''output: [1, 2]'' ==== vector ==== vector<int> vi; print(vi); ''output: []'' vi.push_back(1); print(vi); ''output: [1]'' vi.push_back(2); vi.push_back(3); print(vi); ''output: [1, 2, 3]'' ==== vector in vector ==== vector<vector<int> > vvi; print(vvi); ''output: []'' vvi.push_back(vi); print(vvi); ''output: <nowiki>[[1, 2, 3]]</nowiki>'' vvi.push_back(vi); vvi.push_back(vi); print(vvi); ''output: [[1, 2, 3], [1, 2, 3], [1, 2, 3]]'' ==== vector with nasty string case ==== vector<string> vs; vs.push_back("[1, 2, 3], [1, 2, 3], [1, 2, 3]"); print(vs); '''output: [[1, 2, 3], [1, 2, 3], [1, 2, 3]]''' ==== vector of pairs ==== This is an interesting case as it shows a stylistic difference between a vector of pairs and a map. It also shows that if we allow this syntax, simple type and depth formatters will need to be enhanced to meet this requirement. vector<pair<int,int> > vpi; print(vpi); ''output: []'' pair<int,int> pi = make_pair(1,2); vpi.push_back(pi); print(vpi); ''output: <nowiki>[[1, 2]]</nowiki>'' vvi.push_back(pi); vvi.push_back(pi); print(vpi); ''output: [[1, 2], [1, 2], [1, 2]]'' ==== map ==== map<int,string> mis; print(mis); ''output: []'' mis.insert(make_pair(1, "first")); print(mis); ''output: [1:first]'' mis.insert(make_pair(2, "second")); mis.insert(make_pair(3, "third")); print(mis); ''output: [1:first, 2:second, 3:third]'' ==== vector in map ==== map<int,vector<int> > mivi; print(mivi); ''output: []'' mivi.insert(make_pair(1, vi)); print(mivi); ''output: [1:[1,2,3]]'' mivi.insert(make_pair(2, vi)); mivi.insert(make_pair(3, vi)); print(mivi); ''output: [1:[1,2,3], 2:[1,2,3], 3:[1,2,3]]'' === Special Formats === vector<string> vs; vs.push_back("first"); vs.push_back("sec,ond"); vs.push_back("th\"ird"); ==== HTML List ==== print(vs, <nowiki>HTMLListFormatter()</nowiki>); ''output:'' ''<ul>'' ''<li>first'' ''<li>sec,ond'' ''<li>th&quot;ird'' ''</ul>'' ==== CSV ==== '''Note: Does not deal with line breaks in strings.''' print(vs, <nowiki>CSVFormatter()</nowiki>); ''output: first,"sec,ond","th""ird"''
Summary:
This change is a minor edit.
(Visit
Preferences
to set your user name.)
View other revisions
BOOST WIKI
|
BoostCon 2007
|
RecentChanges
|
Preferences
|
Page List
|
Links List
Disclaimer: This site not officially maintained by Boost Developers