Skip to content

Replace std::variant with std::expected for the Result class #41

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

Merged
merged 8 commits into from
Mar 29, 2025

Conversation

hugsy
Copy link
Owner

@hugsy hugsy commented Mar 28, 2025

Description

Since we moved to C++23, this PR is one of a few to update code features to a more recent equivalent.

For this PR we replace using std::variant with std::expected for the Result class.
As a result:

  • Ok doesn't really have any meaning, but keep for quality (like Rust's Result)
  • Unwrapping the value is still done through Value() but expands to a xvalue of .value()
  • Unwrapping the error is done through .error()
  • ValueOr() is now the monadic .value_or()
  • Success/Failed are simplified with .has_value() or !.has_value()

@hugsy hugsy requested a review from Copilot March 29, 2025 03:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the internal implementation of the Result class to use C++23’s std::expected instead of std::variant, and adjusts related usage throughout the codebase. Key changes include:

  • Updating the build workflow to use Ubuntu 24.04 instead of 22.04 and removing a Windows ARM configuration.
  • Upgrading the LLVM/clang toolchain from version 17 to 18.
  • Commenting out output population steps in the workflows which might reflect deprecated or transitional code paths.
Files not reviewed (19)
  • CMakeLists.txt: Language not supported
  • Modules/Assembly/Include/Disassembler.hpp: Language not supported
  • Modules/Assembly/Source/Disassembler.cpp: Language not supported
  • Modules/Binary/Include/Win32/PE.hpp: Language not supported
  • Modules/Binary/Source/Win32/PE.cpp: Language not supported
  • Modules/CTF/Source/Linux/Process.cpp: Language not supported
  • Modules/CTF/Source/Linux/Remote.cpp: Language not supported
  • Modules/CTF/Source/Win32/Process.cpp: Language not supported
  • Modules/CTF/Source/Win32/Remote.cpp: Language not supported
  • Modules/Common/Include/Error.hpp: Language not supported
  • Modules/Common/Include/Formatters.hpp: Language not supported
  • Modules/Common/Include/Handle.hpp: Language not supported
  • Modules/Common/Include/Log.hpp: Language not supported
  • Modules/Common/Source/Error.cpp: Language not supported
  • Modules/Common/Source/Utils.cpp: Language not supported
  • Modules/Common/Tests/perf_pwn_common.cpp: Language not supported
  • Modules/Common/Tests/tests_pwn_common.cpp: Language not supported
  • Modules/FileSystem/Include/Win32/FileSystem.hpp: Language not supported
  • Modules/FileSystem/Source/Win32/FileSystem.cpp: Language not supported

@hugsy hugsy merged commit e1bfa50 into main Mar 29, 2025
8 checks passed
@hugsy hugsy deleted the hugsy/use-expected branch March 29, 2025 03:09
@hugsy hugsy linked an issue Mar 29, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace Result from std::variant to std::expected
1 participant