diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-02 14:24:52 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-02 14:24:52 +0200 |
| commit | 66ffd2ad8c793c4eea1527848fe4772e42595718 (patch) | |
| tree | 9d86601b57270172d76d5e617218507864ee4f54 /libs | |
| parent | b84c4c9d8c90f3d3fd5a60de282278912fad2f04 (diff) | |
| download | teachos-66ffd2ad8c793c4eea1527848fe4772e42595718.tar.xz teachos-66ffd2ad8c793c4eea1527848fe4772e42595718.zip | |
kapi: extract common bus code
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/include/kstd/bits/unique_ptr.hpp | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/libs/kstd/include/kstd/bits/unique_ptr.hpp b/libs/kstd/include/kstd/bits/unique_ptr.hpp index f50335c..3d803b4 100644 --- a/libs/kstd/include/kstd/bits/unique_ptr.hpp +++ b/libs/kstd/include/kstd/bits/unique_ptr.hpp @@ -46,10 +46,8 @@ namespace kstd template<typename U> requires(std::is_convertible_v<U *, T *>) unique_ptr(unique_ptr<U> && other) noexcept - : pointer(other.pointer) - { - other.pointer = nullptr; - } + : pointer{std::exchange(other.pointer, nullptr)} + {} /** * @brief Deleted copy assignment operator to enforce unique ownership. @@ -62,10 +60,8 @@ namespace kstd * @param other Unique pointer to move from. */ unique_ptr(unique_ptr && other) noexcept - : pointer(other.pointer) - { - other.pointer = nullptr; - } + : pointer{std::exchange(other.pointer, nullptr)} + {} /** * @brief Move assignment operator. Transfers ownership from other to *this as if by calling reset(r.release()). @@ -78,8 +74,7 @@ namespace kstd if (this != &other) { delete pointer; - pointer = other.pointer; - other.pointer = nullptr; + pointer = std::exchange(other.pointer, nullptr); } return *this; } @@ -134,9 +129,7 @@ namespace kstd */ auto release() -> T * { - T * temp = pointer; - pointer = nullptr; - return temp; + return std::exchange(pointer, nullptr); } /** @@ -150,8 +143,7 @@ namespace kstd */ auto reset(T * ptr = nullptr) -> void { - delete pointer; - pointer = ptr; + delete std::exchange(pointer, ptr); } /** |
