-
Notifications
You must be signed in to change notification settings - Fork 26
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
Refactor MatchCast
for type safety, C++23, and Boost enhancements
#159
Merged
matthew-mccall
merged 15 commits into
open-algebra:master
from
matthew-mccall:qol-improvements
Feb 22, 2025
Merged
Refactor MatchCast
for type safety, C++23, and Boost enhancements
#159
matthew-mccall
merged 15 commits into
open-algebra:master
from
matthew-mccall:qol-improvements
Feb 22, 2025
Conversation
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
Refactored the codebase to use `boost::any` instead of `std::any` to enhance type safety and performance. Updated all relevant files, interfaces, and method implementations, including serializers and expressions, to align with the new type. Added `Boost::any` to the CMake build configuration.
Switched target C++ standard to C++23 in CMakeLists and replaced `std::variant`-based `ParseResult` with `std::expected` for cleaner error handling in `FromString`. Adjusted related tests and `Expression::Accept` to use `std::expected`. Updated Eigen dependency to the nightly version.
This ensures that the method is evaluated at compile time, enforcing safer and more predictable behavior. The change improves the compile-time guarantees of the `Case` method usage.
Replaced custom lambda_traits with Boost's callable_traits for cleaner and more robust type handling in MatchCast. Updated CMake configuration to fetch callable_traits and adjusted related logic accordingly.
This update improves readability and maintainability by splitting each `Case` into a check lambda and a transformer lambda. It also introduces concepts to validate compatibility between checks and transformers, ensuring stricter type safety. Additionally, it prepares for potential optimizations by decoupling the logic for matching and transformation.
Introduce `TypedVisitor` to replace previously generic `Visitor` implementations for enhanced type safety and clarity. Updated `InFixSerializer` and `Expression` to leverage the new paradigm, transitioning to `std::expected` for error handling and reducing redundancy in serialization logic.
This refactoring replaces the generic `any` return type with strongly-typed `std::expected` for better type safety and error handling in `TeXSerializer`. Methods now use `TypedVisitor` and rely on `transform` and `and_then` for operation chaining. Simplified arithmetic and operand serialization logic, improving code clarity and maintainability.
Replaced `Visit` methods with strongly typed `TypedVisit` methods to enforce return types. Integrated Microsoft's GSL for safer pointer handling and updated method contracts to use `std::expected` for error propagation. Adjusted CMake configuration to fetch and link GSL.
Simplified lambdas by removing unused `[this]` captures in multiple `TypedVisit` functions. This improves code clarity and avoids misleading usage of instance-specific context where it is not required.
Simplified lambdas by removing unused `[this]` captures in multiple `TypedVisit` functions. This improves code clarity and avoids misleading usage of instance-specific context where it is not required.
404Naz
approved these changes
Feb 22, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This pull request introduces a series of improvements and updates:
MatchCast
Refactoring:Case
into separate check and transformer lambdas for improved readability and maintainability.Boost Dependency Update:
lambda_traits
withBoost's callable_traits
to improve reliability and code cleanliness.consteval
Implementation:consteval
keyword to theMatchCastImpl::Case
method, enforcing compile-time evaluation for safer, predictable code.C++23 Standard Upgrade:
std::variant
withstd::expected
inFromString
.Boost Any Replacement:
std::any
withboost::any
across the codebase for enhanced type safety and performance.Checklist