Show newer

@luci
Timur Doumler
@timur_audio
The Cpp2 compiler, called Cppfront, is not a full compiler, but actually translates Cpp2 code into Cpp1 (today's C++) which can in turn be consumed by any conforming C++ compiler. The C++ output is tuned to be human-readable.
1/13

New syntax, for example
auto main() -> int { ... }
becomes
main: () -> int = { ... }
Cpp2 grammar is context-free, you never need to do sema in order to parse Cpp2 code. Lots of syntax cleanups but overall syntax doesn't look wildly different (unlike Carbon).
2/13

The different grammar makes it easy for the compiler to distinguish Cpp2 code from Cpp1 code. The compiler can compile either pure Cpp2 code or you can have Cpp2/Cpp1 mixed mode in the same file. In pure Cpp2 mode, you can't have headers (use modules), there are no macros.
3/13

Cpp2 gets the defaults right, for example any function is [[nodiscard]] by default. Pattern matching is built in (using his "is" and "as" syntax from wg21.link/p2392)
4/13
wg21.link
P2392R1: Pattern matching using "is" and "as"

Lambda syntax is a lot shorter and looks pretty much like regular functions but unnamed. No capture clause, instead you just capture in the body of the lambda, using a $ postfix. Lambdas always capture by value. There is also string interpolation (also using a $ character). 5/13

A function can now return multiple return values like this:
f: () -> (i: int, s: std::string)
which gets translated to returning an instance of an unnamed struct with two members that can bind to a structured binding at the call site.
6/13

Cpp2 is a safe language. Pointer arithmetic doesn't exist. You use span, which is bounds-checked. There are no owning raw pointers, no naked new/delete, therefore also no memory leaks/dangling pointers.
7/13

Instead of naked new, you get shared.​new and unique.​new, which returns a shared_ptr and unique_ptr, respectively. There is a plain "new" which by default returns a unique_ptr.
8/13

Type safety: he replaced all C and C++ casts with the "as" keyword, which eliminates all unsafe casts. No unions, only variant. Cpp2 has contracts: pre and post conditions and assertions.
9/13

Interop with C++ is seamless. You can "just" use C++ in Cpp2, including the standard library. No thunking, no wrapping, no marshalling, you get direct calls. There is an option to inject bounds checks into all containers. Cpp2 itself has bounds safety built-in.
10/13

Lifetime safety. Static lifetime analysis not yet fully implemented, but pointers can't be null in Cpp2. Initialisation safety: you can have an uninitialised variable but you cannot use it. Static analysis of definite first/last use of a variable. It's composable too.
11/13

All types (including pointers, memory buffers, etc) follow the same initialisation rules. You don't need std::move and std::forward anymore. Move is automatic on definite last use.
12/13

Reflection, generation, metaclasses, and zero-overhead exceptions are coming in a future version. @mattgodbolt
already added Cpp2 support in @CompileExplore
. And finally, here is Herb's Cpp2/Cppfront GitHub repo with more info: github.com/hsutter/cppfront
13/13

lawyers 

@icedquinn
It's only alive if it can be convicted of guilt and have it's face smeared on TV for the lawyers publicity.

No one cares if I'm you're not somebody to be milked.

¿No se supone que tienen prohibidísimo prestar sus armas ahí para la foto? Una vez le pedí a uno el arma y su casco para tomarme una foto porque ya saben joven y estúpida, al final sí me los prestó pero me pidió no compartir la foto. 🤡

@icedquinn agreed, a Mac is not a Personal Computer. It is an Apple prison.

@hackaday@botsin.space
well this was damn interesting...

@hackernews@die-partei.social
would this interest you at all @lynne ?

@stux
war brings peace
love brings hate
money brings poverty
housing boom causes homelessness

hmmm.... is this all coincidence?

Show older
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.