@@ -25,14 +25,10 @@ int main(int, char**) {
2525 using builder::basic::sub_array;
2626
2727 auto doc = builder::basic::document{};
28- doc.append (kvp (" team" , " platforms" ),
29- kvp (" id" , types::b_oid{oid (oid::init_tag)}),
28+ doc.append (kvp (" team" , " platforms" ), kvp (" id" , types::b_oid{oid (oid::init_tag)}),
3029 kvp (" members" , [](sub_array sa) {
31- sa.append (" tyler" , " jason" , " drew" ,
32- " sam" , " ernie" , " john" ,
33- " mark" , " crystal" );
34- })
35- );
30+ sa.append (" tyler" , " jason" , " drew" , " sam" , " ernie" , " john" , " mark" , " crystal" );
31+ }));
3632
3733 // document::value is an owning bson document conceptually similar to string.
3834 document::value value{doc.extract ()};
@@ -49,7 +45,6 @@ int main(int, char**) {
4945
5046 // iterate over the elements in a bson document
5147 for (document::element ele : view) {
52-
5348 // element is non owning view of a key-value pair within a document.
5449
5550 // we can use the key() method to get a string_view of the key.
@@ -59,31 +54,32 @@ int main(int, char**) {
5954
6055 // we can use type() to get the type of the value.
6156 switch (ele.type ()) {
62- case type::k_utf8:
63- std::cout << " Got String!" << std::endl;
64- break ;
65- case type::k_oid:
66- std::cout << " Got ObjectId!" << std::endl;
67- break ;
68- case type::k_array: {
69- std::cout << " Got Array!" << std::endl;
70- // if we have a subarray, we can access it by getting a view of it.
71- array::view subarr{ele.get_array ().value };
72- for (array::element ele : subarr) {
73- std::cout << " array element: " << to_json (ele.get_value ()) << std::endl;
57+ case type::k_utf8:
58+ std::cout << " Got String!" << std::endl;
59+ break ;
60+ case type::k_oid:
61+ std::cout << " Got ObjectId!" << std::endl;
62+ break ;
63+ case type::k_array: {
64+ std::cout << " Got Array!" << std::endl;
65+ // if we have a subarray, we can access it by getting a view of it.
66+ array::view subarr{ele.get_array ().value };
67+ for (array::element ele : subarr) {
68+ std::cout << " array element: " << to_json (ele.get_value ()) << std::endl;
69+ }
70+ break ;
7471 }
75- break ;
76- }
77- default :
78- std::cout << " We messed up!" << std::endl;
72+ default :
73+ std::cout << " We messed up!" << std::endl;
7974 }
8075
8176 // usually we don't need to actually use a switch statement, because we can also
8277 // get a variant 'value' that can hold any BSON type.
8378 types::value ele_val{ele.get_value ()};
8479 // if we need to print an arbitrary value, we can use to_json, which provides
8580 // a suitable overload.
86- std::cout << " the value is " << to_json (ele_val) << std::endl;;
81+ std::cout << " the value is " << to_json (ele_val) << std::endl;
82+ ;
8783 }
8884
8985 // If we want to search for an element we can use operator[]
0 commit comments