Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Result

A Rust-like Result type implementation in C++.

Example Usage

#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;
}

Building

Using Nix (Recommended)

  1. 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
  2. Enable Nix experimental features:

    mkdir -p ~/.config/nix
    echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
  3. Enter the Nix Shell:

    nix develop

    Optionally add --allow-dirty

Using Meson

  1. 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
  2. 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

License

MIT License - see LICENSE file for details

About

Bring the venerable Rust Result type to C++!

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages