-
Notifications
You must be signed in to change notification settings - Fork 2
refactor(c++): ♻️ adhere to rule of zero #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
robertodr
wants to merge
5
commits into
main
Choose a base branch
from
refactor-rule-of-zero
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8cc401a
refactor(c++): :broom: put `MonomialPropagator` on the Rule of Zero
robertodr 5a9bcd0
chore(cpp): remove unused virtual keyword
robertodr 0bb22c0
style: sort entries in cspell.json
robertodr 1cdd329
refactor: slightly better backport of std::indirect
robertodr 8df5a32
Merge branch 'main' into refactor-rule-of-zero
robertodr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
| // Copyright 2026 Algorithmiq | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| namespace monoprop { | ||
|
|
||
| /// An allocator-free C++23 subset of C++26 `std::indirect`. | ||
| // | ||
| // The pointee has value semantics: copying copy-constructs a distinct T, while moving transfers the | ||
| // allocation and leaves the source valueless. T may be incomplete where indirect<T> is named, but must | ||
| // be complete wherever an operation constructs, copies, or destroys the pointee. | ||
| // | ||
| // This subset deliberately omits allocators, comparisons, hashing, value assignment, and constructors | ||
| // that adopt an existing pointer. Copy assignment replaces the allocation rather than preserving its | ||
| // address, so T need only be copy-constructible, not copy-assignable. | ||
| template <typename T> | ||
| class indirect { | ||
| public: | ||
| /// The owned value type. | ||
| using value_type = T; | ||
|
|
||
| /// Construct a value-initialized `T`. | ||
| explicit indirect() : ptr_(std::make_unique<T>()) {} | ||
|
|
||
| /// Construct `T` directly from `args`. | ||
| template <typename... Args> | ||
| explicit indirect(std::in_place_t, Args &&...args) : ptr_(std::make_unique<T>(std::forward<Args>(args)...)) {} | ||
|
|
||
| /// Copy-construct an independent `T`, or preserve a moved-from state. | ||
| indirect(const indirect &other) : ptr_(other.ptr_ ? std::make_unique<T>(*other.ptr_) : nullptr) {} | ||
|
|
||
| /// Replace the owned value with an independent copy of `other`. | ||
| auto operator=(const indirect &other) -> indirect & { | ||
| if (this != std::addressof(other)) { | ||
| indirect replacement(other); | ||
| ptr_.swap(replacement.ptr_); | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| /// Transfer ownership and leave `other` valueless. | ||
| indirect(indirect &&) noexcept = default; | ||
|
|
||
| /// Transfer ownership and leave `other` valueless. | ||
| auto operator=(indirect &&) noexcept -> indirect & = default; | ||
|
|
||
| /// Destroy the owned value, if present. | ||
| ~indirect() = default; | ||
|
|
||
| /// Access the owned value; the object must not be valueless. | ||
| auto operator*() noexcept -> T & { return *ptr_; } | ||
|
|
||
| /// Access the owned value; the object must not be valueless. | ||
| auto operator*() const noexcept -> const T & { return *ptr_; } | ||
|
|
||
| /// Access the owned value; the object must not be valueless. | ||
| auto operator->() noexcept -> T * { return ptr_.get(); } | ||
|
|
||
| /// Access the owned value; the object must not be valueless. | ||
| auto operator->() const noexcept -> const T * { return ptr_.get(); } | ||
|
|
||
| /// Return whether ownership was transferred from this object. | ||
| [[nodiscard]] auto valueless_after_move() const noexcept -> bool { return ptr_ == nullptr; } | ||
|
|
||
| private: | ||
| std::unique_ptr<T> ptr_; | ||
| }; | ||
|
|
||
| } // namespace monoprop |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.