-
Notifications
You must be signed in to change notification settings - Fork 758
Closed
Labels
Effort: LowRequires minimal effortRequires minimal effortPriority: LowCan be handled at leisureCan be handled at leisureStatus: In ProgressCurrently being worked onCurrently being worked onType: EnhancementSuggests an improvement or new featureSuggests an improvement or new feature
Description
I want to exchange the content of two gsl::not_null<std::unique_ptr<int>>.
I was pretty sure a swap would work, but couldn't get it working.
#include <memory>
#include <algorithm>
#include <gsl/gsl>
auto main() -> int {
auto a = gsl::not_null<std::unique_ptr<int>> {std::make_unique<int>(0)};
auto b = gsl::not_null<std::unique_ptr<int>> {std::make_unique<int>(1)};
using std::swap;
swap(a, b);
return *a;
}
https://godbolt.org/z/64na6e356
This gives an error:
no matching function for call to 'swap(gsl::not_null<std::unique_ptr<int> >&, gsl::not_null<std::unique_ptr<int> >&)'
I understand that its not possible to move from such a pointer.
However, not even enabling swap for smart-pointers makes std::not_null even less useful.
Is there anything against implementing a custom swap, that takes two not_null pointers and swaps the underlying, as we know they are both not null?
beinhaerter and FeignClaims
Metadata
Metadata
Assignees
Labels
Effort: LowRequires minimal effortRequires minimal effortPriority: LowCan be handled at leisureCan be handled at leisureStatus: In ProgressCurrently being worked onCurrently being worked onType: EnhancementSuggests an improvement or new featureSuggests an improvement or new feature
Type
Projects
Status
Fixed