47 using initializer_list_t = std::initializer_list<list>;
67 list(T value) : val{value} {}
89 list(initializer_list_t init) :
list(init, true, true) {}
97 operator bson_value::view() {
112 bson_value::value val;
114 friend ::bsoncxx::v_noabi::builder::document;
115 friend ::bsoncxx::v_noabi::builder::array;
117 list(initializer_list_t init,
bool type_deduction,
bool is_array) : val{nullptr} {
118 std::stringstream err_msg{
"cannot construct document"};
119 bool valid_document =
false;
120 if (type_deduction || !is_array) {
121 valid_document = [&] {
122 if (init.size() % 2 != 0) {
123 err_msg <<
" : must be list of key-value pairs";
126 for (
size_t i = 0; i < init.size(); i += 2) {
127 auto t = (begin(init) + i)->val.view().type();
129 err_msg <<
" : all keys must be string type. ";
130 err_msg <<
"Found type=" <<
to_string(t);
138 if (valid_document) {
140 for (
size_t i = 0; i < init.size(); i += 2) {
141 _core.key_owned(std::string((begin(init) + i)->val.view().get_string().value));
142 _core.append((begin(init) + i + 1)->val);
144 val = bson_value::value(_core.extract_document());
145 }
else if (type_deduction || is_array) {
147 for (
auto&& ele : init)
148 _core.append(ele.val);
149 val = bson_value::value(_core.extract_array());
161 using initializer_list_t = std::initializer_list<list>;
186 using initializer_list_t = std::initializer_list<list>;
204 array(initializer_list_t init) :
list(init, false, true) {}
219#if defined(BSONCXX_TEST_MACRO_GUARDS_FIX_MISSING_POSTLUDE)
Declares bsoncxx::v_noabi::builder::basic::array.
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
Provides bsoncxx::v_noabi::error_code.
Provides bsoncxx::v_noabi::exception.
A JSON-like builder for creating arrays.
Definition list.hpp:185
array(initializer_list_t init)
Creates a BSON array.
Definition list.hpp:204
array()
Creates an empty array.
Definition list.hpp:192
A JSON-like builder for creating documents.
Definition list.hpp:160
document(initializer_list_t init)
Creates a BSON document.
Definition list.hpp:179
document()
Creates an empty document.
Definition list.hpp:167
A JSON-like builder for creating documents and arrays.
Definition list.hpp:46
list(T value)
Creates a bsoncxx::v_noabi::builder::list from a value of type T. T must be a bsoncxx::v_noabi::types...
Definition list.hpp:67
list()
Creates an empty document.
Definition list.hpp:53
bson_value::view view()
Provides a view of the underlying BSON value.
Definition list.hpp:107
list(initializer_list_t init)
Creates a BSON document, if possible. Otherwise, it will create a BSON array. A document is possible ...
Definition list.hpp:89
operator bson_value::view()
Provides a view of the underlying BSON value.
Definition list.hpp:97
Class representing any exceptions emitted from the bsoncxx library or its underlying implementation.
Definition exception.hpp:34
Provides bsoncxx::v_noabi::builder::core.
Provides entities for use with "list" BSON builder syntax.
Declares entities representing BSON value types.
@ k_unmatched_key_in_builder
Attempted to view or extract a document when a key was still awaiting a matching value.
std::string to_string(type rhs)
Returns a stringification of the given type.
@ k_utf8
Equivalent to k_string.
The top-level namespace within which all bsoncxx library entities are declared.
Provides bsoncxx::v_noabi::types::bson_value::value.