File tree Expand file tree Collapse file tree 2 files changed +37
-7
lines changed Expand file tree Collapse file tree 2 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -59,8 +59,9 @@ namespace detail {
59
59
++read;
60
60
++num_dropped_in_row;
61
61
} else {
62
- size_t trunc_to_length = dropped.size () - num_dropped_in_row;
63
- dropped.resize (trunc_to_length);
62
+ for (int i = 0 ; i < num_dropped_in_row; ++i) {
63
+ dropped.pop_back ();
64
+ }
64
65
read -= num_dropped_in_row;
65
66
66
67
--write;
@@ -126,12 +127,11 @@ namespace detail {
126
127
++read;
127
128
++num_dropped_in_row;
128
129
} else {
129
- size_t trunc_to_length = dropped.size () - num_dropped_in_row;
130
130
for (int i = 0 ; i < num_dropped_in_row; ++i) {
131
131
--read;
132
- *read = std::move (*(dropped.end () - (i+1 )));
132
+ *read = std::move (*(dropped.end () - 1 ));
133
+ dropped.pop_back ();
133
134
}
134
- dropped.resize (trunc_to_length);
135
135
136
136
--write;
137
137
dropped.push_back (std::move (*write));
@@ -174,4 +174,4 @@ void dmsort(Iter begin, Iter end) {
174
174
dmsort (begin, end, std::less<>());
175
175
}
176
176
177
- #endif // DROP_MERGE_SORT_H
177
+ #endif // DROP_MERGE_SORT_H
Original file line number Diff line number Diff line change @@ -76,7 +76,37 @@ void test_noncopyable(){
76
76
std::cout << std::is_sorted (std::begin (tab), std::end (tab), cmp) << " \n " ;
77
77
}
78
78
79
+ struct NonDefaultConstructible {
80
+ NonDefaultConstructible () = delete ;
81
+ NonDefaultConstructible (const NonDefaultConstructible&) = delete ;
82
+ NonDefaultConstructible& operator =(const NonDefaultConstructible&) = delete ;
83
+ NonDefaultConstructible (int value) : value(value) {}
84
+ NonDefaultConstructible (NonDefaultConstructible&& other) : value(other.value) {}
85
+ NonDefaultConstructible& operator =(NonDefaultConstructible&& other) {
86
+ value = other.value ;
87
+ return *this ;
88
+ }
89
+
90
+ int value;
91
+ };
92
+
93
+ bool operator <(const NonDefaultConstructible& lhs, const NonDefaultConstructible& rhs) {
94
+ return lhs.value < rhs.value ;
95
+ }
96
+
97
+ void test_non_default_constructible (){
98
+ std::vector<NonDefaultConstructible> tab;
99
+ for (int i = 0 ; i < 10 ; ++i)
100
+ tab.push_back (NonDefaultConstructible (-i));
101
+ dmsort (tab.begin (), tab.end ());
102
+ for (auto &e : tab)
103
+ std::cout << e.value << " " ;
104
+ std::cout << " \n " ;
105
+ std::cout << std::is_sorted (std::begin (tab), std::end (tab)) << " \n " ;
106
+ }
107
+
79
108
int main (){
80
109
test_counts ();
81
110
test_noncopyable ();
82
- }
111
+ test_non_default_constructible ();
112
+ }
You can’t perform that action at this time.
0 commit comments