Live data from Hacker News

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

github.com

11–20 of 174 posts

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

#11

What's the point of adding Option , Result and Rc/Arc when std::optional, std::expected and std::shared_ptr exist?

The Option type seems to have various standard Rust methods like expect() implemented that I don't believe std::optional has.

I haven't checked recent C++ standards, but I don't believe you can use partial classes/extensions in C++ like some other OO languages to add these methods to a native type. Many helper functions commonly used in Rust also only seem to exist in C++23, which not ever project can be compiled under yet.

In normal C++ code, the native types would probably be better to use, but if you're going full Rust style code, you may as well use these new types.

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

#12

What's the point of adding Option , Result and Rc/Arc when std::optional, std::expected and std::shared_ptr exist?

std::optional is fundamentally broken because it has an imolicit conversion (or operator* or something) to T. If you forget to check if it's empty you get UB.

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

#13

This borrow checker runs at runtime, which I find not as interesting. Everything starts to look a lot like std::unique_ptr which I think is mostly unneeded as it ads pointer indirection. Could someone explain to me when one would use this? Is it for educational purposes perhaps?

I think it's more an "can i do this" project, rather than a product that can be used in prod

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

#14
post #5

Earlier quoted context omitted.

Actually it is more like having both Roman and Arabic Numerals on the same source code, depending on the age of the project, and the C and C++ education background of the team.

I don't see any way to express something like Option in C++ Regardless of "age of the project" or other considerations, this doesn't seem like a particularly tricky edge case of generic programming and yet C++ is stumped AFAICT

According[0] to Perplexity.ai, you could use std::optional to get a C++ approximation of your Rust type.

I am neither an expert in modern C++ nor in Rust, but I have witnessed enough of C++'s evolution over time to know that if C++ language devs find a feature desirable enough they will do whatever it takes to frobnicate the language in order to claim support for that feature.

[0] https://www.perplexity.ai/search/is-it-possible-Sd3TML68TfKv...

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

#15

What's the point of adding Option , Result and Rc/Arc when std::optional, std::expected and std::shared_ptr exist?

std::optional is a poor shadow of Option. It's what happens when C++ programmers who've seen a Maybe type in a window (years ago by the way, this isn't inspired by Rust, it was just stuck in the standardization process until C++ 17) but are starved of proper types and basic features like pattern matching try to imitate what they saw.

As a result for example std::optional doesn't exist, because to a C++ programmer it seems as though this might have assign-through semantics (!) and so WG21 decided to kick this can down the road. C++ 26 might get std::optional

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

#16
post #5

Earlier quoted context omitted.

Actually it is more like having both Roman and Arabic Numerals on the same source code, depending on the age of the project, and the C and C++ education background of the team.

I don't see any way to express something like Option in C++ Regardless of "age of the project" or other considerations, this doesn't seem like a particularly tricky edge case of generic programming and yet C++ is stumped AFAICT

That wasn't really the point of my remark, rather C with Classes C++98 style with plenty of C style coding for strings and arrays (Roman Numerals), Modern C++ best pratices with safety tooling (Arabic Numerals).

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

#17
post #14

Earlier quoted context omitted.

I don't see any way to express something like Option in C++ Regardless of "age of the project" or other considerations, this doesn't seem like a particularly tricky edge case of generic programming and yet C++ is stumped AFAICT

According[0] to Perplexity.ai, you could use std::optional to get a C++ approximation of your Rust type. I am neither an expert in modern C++ nor in Rust, but I have witnessed enough of C++'s evolution over time to know that if C++ language devs find a feature desirable enough they will do whatever it takes to frobnicate the language in order to claim support for that feature. [0] https://www.perplexity.ai/search/is-…

While I watch with some desmay, one of favourite languages turning beyond PL/I levels of complexity, it isn't alone in this direction.

One of the reasons I am not able to follow up on C++ as much as I did in the past, isn't directly related to its complexity, rather that my main worktools, the JVM, CLR and Web ecosystems, are reaching similar levels of complexity, specially with the 6 months release candence, and there is only so much one can keep up with.

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

#18

What's the point of adding Option , Result and Rc/Arc when std::optional, std::expected and std::shared_ptr exist?

std::optional is fundamentally broken because it has an imolicit conversion (or operator* or something) to T. If you forget to check if it's empty you get UB.

There is no implicit conversion (except to bool, but that tells you whether the optional contains a value), and operator* / operator-> throw std::bad_optional_access if it’s empty. See https://en.cppreference.com/w/cpp/utility/optional

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

#19
post #14

Earlier quoted context omitted.

I don't see any way to express something like Option in C++ Regardless of "age of the project" or other considerations, this doesn't seem like a particularly tricky edge case of generic programming and yet C++ is stumped AFAICT

According[0] to Perplexity.ai, you could use std::optional to get a C++ approximation of your Rust type. I am neither an expert in modern C++ nor in Rust, but I have witnessed enough of C++'s evolution over time to know that if C++ language devs find a feature desirable enough they will do whatever it takes to frobnicate the language in order to claim support for that feature. [0] https://www.perplexity.ai/search/is-…

std::optional has two values, Option has one, so by my counting that's a 100% error.

It is likely the best that can be done, but that's my point, C++ can't do this because the foundational type system isn't up to the task.

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

#20

Earlier quoted context omitted.

std::optional is fundamentally broken because it has an imolicit conversion (or operator* or something) to T. If you forget to check if it's empty you get UB.

There is no implicit conversion (except to bool, but that tells you whether the optional contains a value), and operator* / operator-> throw std::bad_optional_access if it’s empty. See https://en.cppreference.com/w/cpp/utility/optional

> and operator* / operator-> throw std::bad_optional_access if it’s empty.

Of course not, they’re literally `noexcept`, what they do is UB if empty.

value() will throw.

Post reply on HN