A Rust-like Result type implementation in C++.
#include <result.h>
Result<int, std::string> divide(int a, int b) {
if (b == 0) {
return Err("Division by zero");
}
return Ok(a / b);
}
int main() {
auto result = divide(10, 2);
if (result.is_ok()) {
std::cout << "Result: " << result.unwrap() << std::endl;
} else {
std::cout << "Error: " << result.unwrap_err() << std::endl;
}
return 0;
}-
Install Nix:
# Remove any existing Nix installation sudo rm -rf /nix # Install Nix using the official installer sh <(curl -L https://nixos.org/nix/install) --daemon
-
Enable Nix experimental features:
mkdir -p ~/.config/nix echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
-
Enter the Nix Shell:
nix develop
Optionally add
--allow-dirty
-
Build the project:
# Configure debug build meson setup build --buildtype=debug # Configure release build meson setup build --buildtype=release # Build the project meson compile -C build # Run all tests meson test -C build
-
Run specific examples:
# All binaries are in the build/ directory ./build/arithmetic ./build/error_handling ./build/optional ./build/result_chain
All build artifacts, including binaries and intermediate files, are kept in the build/ directory. This includes:
- Compiled binaries
- Build configuration files
- Test results
- Meson's internal state
MIT License - see LICENSE file for details