Live data from Hacker News

Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20

github.com

171–174 of 174 posts

Re: Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20

#171

Earlier quoted context omitted.

C++ has pattern matching through overloading.

How do you figure?

I don't understand the question.

Here is the first example I found on Google if that helps you understand.

    std::variant package;

    std::visit(overload{
        [](Fluid& )       { std::cout 

Re: Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20

#172

Earlier quoted context omitted.

How do you figure?

I don't understand the question. Here is the first example I found on Google if that helps you understand. std::variant package; std::visit(overload{ [](Fluid& ) { std::cout

But that's not really even a pattern match? Here's what a pattern match looks like: [This is from day 10 of last year's Advent of Code.]

            match (state, pipe) {
                (State::None, Pipe::Ground) => {
                    if inside {
                        n += 1;
                    }
                }
                (State::None, Pipe::Vert) => {
                    inside = !inside;
                }
                (State::None, Pipe::Se) => {
                    state = State::South;
                }
                (State::None, Pipe::Ne) => {
                    state = State::North;
                }

                // Horizontal lines make no difference to anything
                (State::North | State::South, Pipe::Horiz) => {}

                // U-turns
                (State::South, Pipe::Sw) | (State::North, Pipe::Nw) => {
                    state = State::None;
                }

                // Form a vertical line
                (State::South, Pipe::Nw) | (State::North, Pipe::Sw) => {
                    inside = !inside;
                    state = State::None;
                }

                _ => {
                    panic!("Unexpected sequence {state:?} {pipe:?}");
                }
            }

Re: Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20

#173

Earlier quoted context omitted.

You don't have to write this, it already exists as the (unsafe of course) method Option::unwrap_unchecked Because all Rust's methods can be called as free functions, you can literally write Option::unwrap_unchecked for the same behaviour, or you can some_option.unwrap_unchecked() (in both cases you will need to be in unsafe context for this to be allowed and should write a SAFETY comment explaining why you're sure it…

I see. I didn't know that method existed despite spending ~4.5 years writing Rust.

Ha, same. I very very rarely write code in unsafe contexts which is why, I guess.

Re: Rusty.hpp: A Borrow Checker and Memory Ownership System for C++20

#174

Earlier quoted context omitted.

I don't understand the question. Here is the first example I found on Google if that helps you understand. std::variant package; std::visit(overload{ [](Fluid& ) { std::cout

But that's not really even a pattern match? Here's what a pattern match looks like: [This is from day 10 of last year's Advent of Code.] match (state, pipe) { (State::None, Pipe::Ground) => { if inside { n += 1; } } (State::None, Pipe::Vert) => { inside = !inside; } (State::None, Pipe::Se) => { state = State::South; } (State::None, Pipe::Ne) => { state = State::North; } // Horizontal lines make no difference to anyth…

This is the exact same thing except you're visiting two arguments at a time.

Guess what, the same syntax I gave supports exactly that as well.

Post reply on HN