| 1 | // { dg-do run { target c++11 } } |
| 2 | // C++11 23.3.4.6 Operations [forwardlist.ops] |
| 3 | |
| 4 | #include <forward_list> |
| 5 | #include <testsuite_hooks.h> |
| 6 | |
| 7 | void |
| 8 | test_stable() |
| 9 | { |
| 10 | std::forward_list<double> a{1.5, 2.0, 3.5, 4.1}; |
| 11 | std::forward_list<double> b{1.0, 2.5, 3.0, 4.3, 4.2, 5.0}; |
| 12 | |
| 13 | a.merge(b, std::less<int>{}); |
| 14 | |
| 15 | // result is sorted with respect to std::less<int>, so 1.0 and 1.5 are |
| 16 | // equivalent, and stability guarantee means the element from a comes first. |
| 17 | const std::forward_list<double> r { 1.5, 1.0, |
| 18 | 2.0, 2.5, |
| 19 | 3.5, 3.0, |
| 20 | 4.1, 4.3, 4.2, |
| 21 | 5.0}; |
| 22 | |
| 23 | VERIFY(a == r); |
| 24 | } |
| 25 | |
| 26 | void |
| 27 | test_lwg3088() |
| 28 | { |
| 29 | // LWG 3088: forward_list::merge behavior unclear when passed *this |
| 30 | // PR libstdc++/103853 |
| 31 | std::forward_list<int> c1{ 1, 2, 3 }; |
| 32 | const std::forward_list<int> c2 = c1; |
| 33 | c1.merge(c1); |
| 34 | VERIFY( c1 == c2 ); |
| 35 | c1.merge(c1, std::less<long>{}); |
| 36 | VERIFY( c1 == c2 ); |
| 37 | c1.merge(std::move(c1)); |
| 38 | VERIFY( c1 == c2 ); |
| 39 | c1.merge(std::move(c1), std::less<long>{}); |
| 40 | VERIFY( c1 == c2 ); |
| 41 | } |
| 42 | |
| 43 | int |
| 44 | main() |
| 45 | { |
| 46 | test_stable(); |
| 47 | test_lwg3088(); |
| 48 | } |