-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce gsl::swap for swapping gsl::not_null (#1160)
fixes: #1129 * create gsl::swap<T>(T&, T&) which wraps std::swap * specialize gsl::swap<T>(gsl::not_null<T>&, gsl::not_null<T>&) * add tests
- Loading branch information
1 parent
8a0e3d8
commit 2724630
Showing
5 changed files
with
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <gsl/pointers> | ||
|
||
#include <memory> | ||
|
||
TEST(pointers_test, swap) | ||
{ | ||
// taken from gh-1129: | ||
gsl::not_null<std::unique_ptr<int>> a(std::make_unique<int>(0)); | ||
gsl::not_null<std::unique_ptr<int>> b(std::make_unique<int>(1)); | ||
|
||
EXPECT_TRUE(*a == 0); | ||
EXPECT_TRUE(*b == 1); | ||
|
||
gsl::swap(a, b); | ||
|
||
EXPECT_TRUE(*a == 1); | ||
EXPECT_TRUE(*b == 0); | ||
} | ||
|
2724630
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there also be code for swapping
strict_not_null
s?