Skip to content
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
merged 15 commits into from
Feb 22, 2025

Conversation

matthew-mccall
Copy link
Collaborator

@matthew-mccall matthew-mccall commented Feb 20, 2025

Description

This pull request introduces a series of improvements and updates:

  • MatchCast Refactoring:

    • Splits the Case into separate check and transformer lambdas for improved readability and maintainability.
    • Adds stricter type compatibility validation between checks and transformers.
  • Boost Dependency Update:

    • Replaces custom lambda_traits with Boost's callable_traits to improve reliability and code cleanliness.
  • consteval Implementation:

    • Adds the consteval keyword to the MatchCastImpl::Case method, enforcing compile-time evaluation for safer, predictable code.
  • C++23 Standard Upgrade:

    • Updates the project to target C++23.
    • Refactors error handling by replacing std::variant with std::expected in FromString.
  • Boost Any Replacement:

    • Substitutes std::any with boost::any across the codebase for enhanced type safety and performance.

Checklist

  • Code has been tested locally
  • Related documentation has been updated
  • No new warnings have been introduced

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.
@matthew-mccall matthew-mccall self-assigned this Feb 20, 2025
@matthew-mccall matthew-mccall added the enhancement New feature or request label Feb 20, 2025
github-actions and others added 10 commits February 20, 2025 15:11
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.
@matthew-mccall matthew-mccall merged commit 37d35e0 into open-algebra:master Feb 22, 2025
8 checks passed
@matthew-mccall matthew-mccall deleted the qol-improvements branch February 22, 2025 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants