Skip to content

Commit a0b7e7c

Browse files
committed
Merge pull request #353 from jonitis/feature_sbuffer_move_semantics
Add move semantics to sbuffer in c++11 mode
2 parents 294aa52 + e9eac32 commit a0b7e7c

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

include/msgpack/sbuffer.hpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,32 @@ class sbuffer {
5151
::free(m_data);
5252
}
5353

54-
public:
54+
#if !defined(MSGPACK_USE_CPP03)
55+
sbuffer(const sbuffer&) = delete;
56+
sbuffer& operator=(const sbuffer&) = delete;
57+
58+
sbuffer(sbuffer&& other) :
59+
m_size(other.m_size), m_data(other.m_data), m_alloc(other.m_alloc)
60+
{
61+
other.m_size = other.m_alloc = 0;
62+
other.m_data = nullptr;
63+
}
64+
65+
sbuffer& operator=(sbuffer&& other)
66+
{
67+
::free(m_data);
68+
69+
m_size = other.m_size;
70+
m_alloc = other.m_alloc;
71+
m_data = other.m_data;
72+
73+
other.m_size = other.m_alloc = 0;
74+
other.m_data = nullptr;
75+
76+
return *this;
77+
}
78+
#endif // !defined(MSGPACK_USE_CPP03)
79+
5580
void write(const char* buf, size_t len)
5681
{
5782
if(m_alloc - m_size < len) {
@@ -118,10 +143,7 @@ class sbuffer {
118143
private:
119144
sbuffer(const sbuffer&);
120145
sbuffer& operator=(const sbuffer&);
121-
#else // defined(MSGPACK_USE_CPP03)
122-
sbuffer(const sbuffer&) = delete;
123-
sbuffer& operator=(const sbuffer&) = delete;
124-
#endif // defined(MSGPACK_USE_CPP03)
146+
#endif // defined(MSGPACK_USE_CPP03)
125147

126148
private:
127149
size_t m_size;

0 commit comments

Comments
 (0)