Skip to content

Commit df4d70d

Browse files
authored
Add internal C++14 polyfill for std::exchange (#1498)
1 parent 94a8e71 commit df4d70d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/mongocxx/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ set_dist_list(src_mongocxx_lib_DIST
262262
mongocxx/private/scoped_bson_value.hh
263263
mongocxx/private/scoped_bson.hh
264264
mongocxx/private/ssl.hh
265+
mongocxx/private/utility.hh
265266
mongocxx/v_noabi/mongocxx/append_aggregate_options.hh
266267
mongocxx/v_noabi/mongocxx/bulk_write.hh
267268
mongocxx/v_noabi/mongocxx/change_stream.hh
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2009-present MongoDB, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <utility> // IWYU pragma: export
18+
19+
//
20+
21+
namespace mongocxx {
22+
23+
#if defined(__cpp_lib_exchange_function) && __cpp_lib_exchange_function >= 201304L
24+
using std::exchange;
25+
#else
26+
template <typename T, typename U = T>
27+
T exchange(T& obj, U&& new_val) {
28+
T old_val = std::move(obj);
29+
obj = std::forward<U>(new_val);
30+
return old_val;
31+
}
32+
#endif
33+
34+
} // namespace mongocxx

0 commit comments

Comments
 (0)