19 #include <bsoncxx/builder/core.hpp> 
   20 #include <bsoncxx/exception/error_code.hpp> 
   21 #include <bsoncxx/exception/exception.hpp> 
   22 #include <bsoncxx/types/bson_value/value.hpp> 
   24 #include <bsoncxx/config/prelude.hpp> 
   27 BSONCXX_INLINE_NAMESPACE_BEGIN
 
   29 using namespace bsoncxx::types;
 
   35     using initializer_list_t = std::initializer_list<list>;
 
   54     list(T value) : val{value} {}
 
   74     list(initializer_list_t init) : 
list(init, true, true) {}
 
  100     list(initializer_list_t init, 
bool type_deduction, 
bool is_array) : val{
nullptr} {
 
  101         std::stringstream err_msg{
"cannot construct document"};
 
  102         bool valid_document = 
false;
 
  103         if (type_deduction || !is_array) {
 
  104             valid_document = [&] {
 
  105                 if (init.size() % 2 != 0) {
 
  106                     err_msg << 
" : must be list of key-value pairs";
 
  109                 for (
size_t i = 0; i < init.size(); i += 2) {
 
  110                     auto t = (begin(init) + i)->val.
view().
type();
 
  111                     if (t != type::k_utf8) {
 
  112                         err_msg << 
" : all keys must be string type. ";
 
  113                         err_msg << 
"Found type=" << 
to_string(t);
 
  121         if (valid_document) {
 
  123             for (
size_t i = 0; i < init.size(); i += 2) {
 
  124                 _core.key_owned(std::string((begin(init) + i)->val.
view().
get_string().value));
 
  125                 _core.append((begin(init) + i + 1)->val);
 
  128         } 
else if (type_deduction || is_array) {
 
  130             for (
auto&& ele : init)
 
  131                 _core.append(ele.val);
 
  143     using initializer_list_t = std::initializer_list<list>;
 
  167     using initializer_list_t = std::initializer_list<list>;
 
  184     array(initializer_list_t init) : 
list(init, false, true) {}
 
  187 BSONCXX_INLINE_NAMESPACE_END