forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++]
priority_queue::displace_top, {flat_,}set::displace, `{v…
…ector,deque}::displace_back`
- Loading branch information
1 parent
58de28c
commit 03d304c
Showing
11 changed files
with
593 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
libcxx/test/std/containers/associative/multiset/displace.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <set> | ||
|
|
||
| // value_type displace(const_iterator position); | ||
|
|
||
| #include <functional> | ||
| #include <set> | ||
| #include <utility> | ||
|
|
||
| #include "test_macros.h" | ||
| #include "min_allocator.h" | ||
| #include "MoveOnly.h" | ||
|
|
||
| template<class It> | ||
| It Next(It it, int n) { | ||
| std::advance(it, n); | ||
| return it; | ||
| } | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| { | ||
| using M = std::multiset<int>; | ||
| const int a[] = {1,3,3,4,5,5,8,8}; | ||
| M m(a, a+8); | ||
| assert(m.size() == 8); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.begin())), int); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.cbegin())), int); | ||
|
|
||
| int v = m.displace(Next(m.cbegin(), 3)); | ||
| assert(v == 4); | ||
| assert(m.size() == 7); | ||
| #if TEST_STD_VER >= 11 | ||
| assert((m == M{1,3,3,5,5,8,8})); | ||
| #endif | ||
|
|
||
| v = m.displace(m.cbegin()); | ||
| assert(v == 1); | ||
| assert(m.size() == 6); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 5)); | ||
| assert(v == 8); | ||
| assert(m.size() == 5); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 3); | ||
| assert(m.size() == 4); | ||
| #if TEST_STD_VER >= 11 | ||
| assert((m == M{3,5,5,8})); | ||
| #endif | ||
| } | ||
| { | ||
| using M = std::multiset<int, std::less<int>, min_allocator<int> >; | ||
| const int a[] = {1,2,3,4}; | ||
| M m(a, a+4); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.begin())), int); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.cbegin())), int); | ||
| int v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 2); | ||
| assert(m.size() == 3); | ||
| v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 3); | ||
| assert(m.size() == 2); | ||
| v = m.displace(m.cbegin()); | ||
| assert(v == 1); | ||
| assert(m.size() == 1); | ||
| v = m.displace(m.cbegin()); | ||
| assert(v == 4); | ||
| assert(m.empty()); | ||
| } | ||
| #if TEST_STD_VER >= 11 | ||
| { | ||
| // Verify that it works with move-only types (its raison d'etre). | ||
| using M = std::multiset<MoveOnly>; | ||
| M m; | ||
| for (int i = 1; i <= 8; ++i) { | ||
| m.insert(i); | ||
| } | ||
| assert(m.size() == 8); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.begin())), MoveOnly); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.cbegin())), MoveOnly); | ||
|
|
||
| MoveOnly v = m.displace(Next(m.cbegin(), 3)); | ||
| assert(v == 4); | ||
|
|
||
| v = m.displace(m.cbegin()); | ||
| assert(v == 1); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 5)); | ||
| assert(v == 8); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 3); | ||
| assert(m.size() == 4); | ||
| } | ||
| #endif | ||
| return 0; | ||
| } |
102 changes: 102 additions & 0 deletions
102
libcxx/test/std/containers/associative/set/displace.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <set> | ||
|
|
||
| // value_type displace(const_iterator position); | ||
|
|
||
| #include <functional> | ||
| #include <set> | ||
| #include <utility> | ||
|
|
||
| #include "test_macros.h" | ||
| #include "min_allocator.h" | ||
| #include "MoveOnly.h" | ||
|
|
||
| template<class It> | ||
| It Next(It it, int n) { | ||
| std::advance(it, n); | ||
| return it; | ||
| } | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| { | ||
| using M = std::set<int>; | ||
| const int a[] = {1,2,3,4,5,6,7,8}; | ||
| M m(a, a+8); | ||
| assert(m.size() == 8); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.begin())), int); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.cbegin())), int); | ||
|
|
||
| int v = m.displace(Next(m.cbegin(), 3)); | ||
| assert(v == 4); | ||
| assert(m.size() == 7); | ||
| #if TEST_STD_VER >= 11 | ||
| assert((m == M{1,2,3,5,6,7,8})); | ||
| #endif | ||
|
|
||
| v = m.displace(m.cbegin()); | ||
| assert(v == 1); | ||
| assert(m.size() == 6); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 5)); | ||
| assert(v == 8); | ||
| assert(m.size() == 5); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 3); | ||
| assert(m.size() == 4); | ||
| #if TEST_STD_VER >= 11 | ||
| assert((m == M{2,5,6,7})); | ||
| #endif | ||
| } | ||
| { | ||
| using M = std::set<int, std::less<int>, min_allocator<int> >; | ||
| const int a[] = {1,2,3,4}; | ||
| M m(a, a+4); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.begin())), int); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.cbegin())), int); | ||
| int v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 2); | ||
| v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 3); | ||
| v = m.displace(m.cbegin()); | ||
| assert(v == 1); | ||
| v = m.displace(m.cbegin()); | ||
| assert(v == 4); | ||
| assert(m.empty()); | ||
| } | ||
| #if TEST_STD_VER >= 11 | ||
| { | ||
| // Verify that it works with move-only types (its raison d'etre). | ||
| using M = std::set<MoveOnly>; | ||
| M m; | ||
| for (int i = 1; i <= 8; ++i) { | ||
| m.insert(i); | ||
| } | ||
| assert(m.size() == 8); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.begin())), MoveOnly); | ||
| ASSERT_SAME_TYPE(decltype(m.displace(m.cbegin())), MoveOnly); | ||
|
|
||
| MoveOnly v = m.displace(Next(m.cbegin(), 3)); | ||
| assert(v == 4); | ||
|
|
||
| v = m.displace(m.cbegin()); | ||
| assert(v == 1); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 5)); | ||
| assert(v == 8); | ||
|
|
||
| v = m.displace(Next(m.cbegin(), 1)); | ||
| assert(v == 3); | ||
| assert(m.size() == 4); | ||
| } | ||
| #endif | ||
| return 0; | ||
| } |
Oops, something went wrong.