Skip to content

Commit 1bd8795

Browse files
committed
using default implementations of trivial constructors
removed the move constructor/assignment from json::value, it was broken on modern compilers and was also a bit deceiving since it was never cheap to move a json::value, it was always effectively just a copy. So there was no gain in having it.
1 parent df075cf commit 1bd8795

File tree

6 files changed

+11
-102
lines changed

6 files changed

+11
-102
lines changed

include/cpp-json/array.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class array {
3131
typedef typename C::size_type size_type;
3232

3333
public:
34-
array();
35-
array(array &&other);
36-
array(const array &other);
34+
array() = default;
35+
array(array &&other) = default;
36+
array(const array &other) = default;
37+
array &operator=(array &&rhs) = default;
38+
array &operator=(const array &rhs) = default;
3739
array(std::initializer_list<value> list);
38-
array &operator=(array &&rhs);
39-
array &operator=(const array &rhs);
4040

4141
public:
4242
iterator begin() { return values_.begin(); }

include/cpp-json/array.tcc

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@
44

55
namespace json {
66

7-
//------------------------------------------------------------------------------
8-
// Name: array
9-
//------------------------------------------------------------------------------
10-
inline array::array() {
11-
}
12-
13-
//------------------------------------------------------------------------------
14-
// Name: array
15-
//------------------------------------------------------------------------------
16-
inline array::array(const array &other) : values_(other.values_) {
17-
}
18-
19-
//------------------------------------------------------------------------------
20-
// Name: array::operator=
21-
//------------------------------------------------------------------------------
22-
inline array &array::operator=(const array &rhs) {
23-
array(rhs).swap(*this);
24-
return *this;
25-
}
26-
277
//------------------------------------------------------------------------------
288
// Name: array
299
//------------------------------------------------------------------------------
@@ -33,22 +13,6 @@ inline array::array(std::initializer_list<value> list) {
3313
}
3414
}
3515

36-
//------------------------------------------------------------------------------
37-
// Name: array
38-
//------------------------------------------------------------------------------
39-
inline array::array(array &&other) : values_(std::move(other.values_)) {
40-
}
41-
42-
//------------------------------------------------------------------------------
43-
// Name: operator=
44-
//------------------------------------------------------------------------------
45-
inline array &array::operator=(array &&rhs) {
46-
if(this != &rhs) {
47-
values_ = std::move(rhs.values_);
48-
}
49-
return *this;
50-
}
51-
5216
//------------------------------------------------------------------------------
5317
// Name: append
5418
//------------------------------------------------------------------------------

include/cpp-json/object.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class object {
2929
typedef typename C::size_type size_type;
3030

3131
public:
32-
object();
33-
object(const object &other);
34-
object(object &&other);
32+
object() = default;
33+
object(const object &other) = default;
34+
object(object &&other) = default;
35+
object &operator=(const object &rhs) = default;
36+
object &operator=(object &&rhs) = default;
3537
object(std::initializer_list<std::pair<std::string, value>> list);
36-
object &operator=(const object &rhs);
37-
object &operator=(object &&rhs);
3838

3939
public:
4040
iterator begin() { return values_.begin(); }

include/cpp-json/object.tcc

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@
44

55
namespace json {
66

7-
//------------------------------------------------------------------------------
8-
// Name: object
9-
//------------------------------------------------------------------------------
10-
inline object::object() {
11-
}
12-
13-
//------------------------------------------------------------------------------
14-
// Name: object
15-
//------------------------------------------------------------------------------
16-
inline object::object(const object &other) : values_(other.values_) {
17-
}
18-
19-
//------------------------------------------------------------------------------
20-
// Name: operator=
21-
//------------------------------------------------------------------------------
22-
inline object &object::operator=(const object &rhs) {
23-
object(rhs).swap(*this);
24-
return *this;
25-
}
26-
277
//------------------------------------------------------------------------------
288
// Name: object
299
//------------------------------------------------------------------------------
@@ -34,22 +14,6 @@ inline object::object(std::initializer_list<std::pair<std::string, value>> list)
3414
}
3515
}
3616

37-
//------------------------------------------------------------------------------
38-
// Name: object
39-
//------------------------------------------------------------------------------
40-
inline object::object(object &&other) : values_(std::move(other.values_)) {
41-
}
42-
43-
//------------------------------------------------------------------------------
44-
// Name: operator=
45-
//------------------------------------------------------------------------------
46-
inline object &object::operator=(object &&rhs) {
47-
if(this != &rhs) {
48-
values_ = std::move(rhs.values_);
49-
}
50-
return *this;
51-
}
52-
5317
//------------------------------------------------------------------------------
5418
// Name: insert
5519
//------------------------------------------------------------------------------

include/cpp-json/value.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class value {
6565
public:
6666
value(const value &other);
6767
value &operator=(const value &rhs);
68-
value(value &&other);
69-
value &operator=(value &&rhs);
7068

7169
public:
7270
void swap(value &other);

include/cpp-json/value.tcc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,6 @@ inline value::value(const std::nullptr_t &): type_(type_null) {
4242
new (&value_) std::string("null");
4343
}
4444

45-
//------------------------------------------------------------------------------
46-
// Name: value
47-
//------------------------------------------------------------------------------
48-
inline value::value(value &&other) : value() {
49-
other.swap(*this);
50-
}
51-
52-
//------------------------------------------------------------------------------
53-
// Name: operator=
54-
//------------------------------------------------------------------------------
55-
inline value &value::operator=(value &&rhs) {
56-
if(this != &rhs) {
57-
value(std::move(rhs)).swap(*this);
58-
}
59-
return *this;
60-
}
61-
6245
//------------------------------------------------------------------------------
6346
// Name: value
6447
//------------------------------------------------------------------------------
@@ -168,7 +151,7 @@ inline value &value::operator=(const value &rhs) {
168151
//------------------------------------------------------------------------------
169152
inline void value::swap(value &other) {
170153
using std::swap;
171-
154+
172155
swap(value_, other.value_);
173156
swap(type_, other.type_);
174157
}

0 commit comments

Comments
 (0)