46
46
#include < mongocxx/test/client_helpers.hh>
47
47
#include < mongocxx/test/spec/util.hh>
48
48
49
- namespace {
50
49
using namespace bsoncxx ;
51
50
using namespace mongocxx ;
52
51
53
- // This function is a workaround for clang 3.8 and mnmlstc/core, where `return
54
- // optional<item_t>{an_item_t};` fails to compile.
55
- bsoncxx::stdx::optional<test_util::item_t > make_optional (test_util::item_t item) {
56
- bsoncxx::stdx::optional<test_util::item_t > option{};
57
- option = item;
58
-
59
- return option;
60
- }
52
+ namespace {
61
53
62
54
// Query the GridFS files collection and fetch the length of the file.
63
55
//
@@ -80,20 +72,20 @@ std::int64_t get_length_of_gridfs_file(gridfs::bucket bucket, types::bson_value:
80
72
bsoncxx::stdx::optional<test_util::item_t > transform_hex (test_util::item_t pair,
81
73
builder::basic::array* context) {
82
74
if (!pair.first ) {
83
- return make_optional ( pair) ;
75
+ return { pair} ;
84
76
}
85
77
86
78
auto key = *(pair.first );
87
79
auto value = pair.second ;
88
80
89
81
if (bsoncxx::string::to_string (key) != " data" || value.type () != type::k_document) {
90
- return make_optional ( pair) ;
82
+ return { pair} ;
91
83
}
92
84
93
85
auto data = value.get_document ().value ;
94
86
95
87
if (!data[" $hex" ] || data[" $hex" ].type () != type::k_string) {
96
- return make_optional ( pair) ;
88
+ return { pair} ;
97
89
}
98
90
99
91
std::basic_string<std::uint8_t > bytes =
@@ -106,8 +98,8 @@ bsoncxx::stdx::optional<test_util::item_t> transform_hex(test_util::item_t pair,
106
98
auto view = context->view ();
107
99
auto length = std::distance (view.cbegin (), view.cend ());
108
100
109
- return make_optional ( std::make_pair (bsoncxx::stdx::optional<bsoncxx::stdx::string_view>(" data" ),
110
- view[static_cast <std::uint32_t >(length - 1 )].get_value ())) ;
101
+ return { std::make_pair (bsoncxx::stdx::optional<bsoncxx::stdx::string_view>(" data" ),
102
+ view[static_cast <std::uint32_t >(length - 1 )].get_value ())} ;
111
103
}
112
104
113
105
// The GridFS spec specifies the expected binary data in the form of { $hex: "<hexadecimal string>"
@@ -120,21 +112,20 @@ document::value convert_hex_data_to_binary(document::view document) {
120
112
bsoncxx::stdx::optional<test_util::item_t > convert_length_to_int64 (test_util::item_t pair,
121
113
builder::basic::array*) {
122
114
if (!pair.first ) {
123
- return make_optional ( pair) ;
115
+ return { pair} ;
124
116
}
125
117
126
118
auto key = *(pair.first );
127
119
auto value = pair.second ;
128
120
129
121
if (bsoncxx::string::to_string (key) != " length" || value.type () != type::k_int32) {
130
- return make_optional ( pair) ;
122
+ return { pair} ;
131
123
}
132
124
133
125
types::b_int64 length = {value.get_int32 ()};
134
126
135
- return make_optional (
136
- std::make_pair (bsoncxx::stdx::optional<bsoncxx::stdx::string_view>(" length" ),
137
- types::bson_value::view{length}));
127
+ return {std::make_pair (bsoncxx::stdx::optional<bsoncxx::stdx::string_view>(" length" ),
128
+ types::bson_value::view{length})};
138
129
}
139
130
140
131
void compare_collections (database db) {
@@ -306,7 +297,7 @@ void test_upload(database db,
306
297
[id](test_util::item_t pair,
307
298
builder::basic::array* context) -> bsoncxx::stdx::optional<test_util::item_t > {
308
299
if (!pair.first ) {
309
- return make_optional ( pair) ;
300
+ return { pair} ;
310
301
}
311
302
312
303
auto key = *(pair.first );
@@ -336,10 +327,10 @@ void test_upload(database db,
336
327
}
337
328
338
329
if (id_str != " *result" ) {
339
- return make_optional ( pair) ;
330
+ return { pair} ;
340
331
}
341
332
342
- return make_optional ( std::make_pair (pair.first , types::bson_value::view{id})) ;
333
+ return { std::make_pair (pair.first , types::bson_value::view{id})} ;
343
334
});
344
335
345
336
db.run_command (transformed_data.view ());
0 commit comments