Skip to content

Commit cc54386

Browse files
committed
SERVER-14937 Give BSONObj move semantics in C++11 mode
1 parent 6354bcf commit cc54386

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/mongo/bson/bsonobj.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ namespace mongo {
106106
init(bsonData);
107107
}
108108

109+
#if __cplusplus >= 201103L
110+
/** Move construct a BSONObj */
111+
BSONObj(BSONObj&& other)
112+
: _objdata(std::move(other._objdata))
113+
, _holder(std::move(other._holder)) {
114+
other._objdata = BSONObj()._objdata; // To return to an empty state.
115+
dassert(!other._holder);
116+
}
117+
118+
// The explicit move constructor above will inhibit generation of the copy ctor, so
119+
// explicitly request the default implementation.
120+
121+
/** Copy construct a BSONObj. */
122+
BSONObj(const BSONObj&) = default;
123+
#endif
124+
109125
/** Provide assignment semantics. We use the value taking form so that we can use copy
110126
* and swap, and consume both lvalue and rvalue references.
111127
*/

0 commit comments

Comments
 (0)