[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 1787423616300.png (362 KB, 1900x1908)
362 KB PNG
Modern C++ makes Rust obsolete. Here is your pattern matching you wanted so much, but with better performance, 20x faster compile times and smaller output binaries.

So, Rustaceans, time to switch back?
>>
please dont use blue for your file borders, it gives the illusion that im "watching" the thread in 4channext

unwatched & hidden.
>>
cpp is a big poopshit behemoth with the most convoluted type system full of so many landmines and edge cases. rust is also probably dogshit but i havent touched it unlike cpp. m

i wish there was an actually simple language that didnt need all this bullshit for basic metaprogramming
>>
>>109621527
C++ was literally invented to make programming more shit.
>>
>>109621558
There’s been one of those for most of a century now
>>
>>109621632
which is?
>>
>>109621527
At least use an overload pattern as a visitor instead of this if constexpr shit
>>
>>109621527
>Here is your pattern matching you wanted
wrong
>but with better performance
wrong
>20x faster compile times
wrong
>smaller output binaries.
wrong

0/4 (0%) F

Impressive!

Congratulations Ranjeet. You have been accepted for a senior architect position at MicroJeet Corporation. WELCOME ABOARD.
>>
>>109621527
This is fucking unreadable, nigger. I've just had to code something fairly simple in C++23 (optimise terribad O(n2) string replacement into something sane) and it was very painful. Never mind the fact that in Rust I could've just added "aho-corasick" as a dep and call it a day, instead of having to write my flat SIMD-accelerated trie from scratch :V

Face it, sepples is obsolete. Maybe Rust is a tranny language, but at least it's not like shoving an iron bottle brush.
>>
>>109621766
>Never mind the fact that in Rust I could've just added "aho-corasick" as a dep and call it a day
Are you a webshitter or something? Gluing dependencies is NOT programming.
>>
>>109621527
this is even uglier than rust code
>>
>>109621766
I'd rather shit broken glass programming in the white man's language than dilate with the Rusties.
>>
>>109621808
#include <variant>
#include <iostream>
#include <type_traits>

struct Circle {double radius;};
struct Rectangle {double width, height;};
struct Point {};

template<class>
inline constexpr bool always_false_v = false;

using Shape = std::variant<Circle>;

void processShape(const Shape& shape) {
// pattern matching in C++!!!
std::visit([](auto&& arg) {
using T = std::decay_t<decltype(arg)>;

if constexpr (std::is_same_v<T, Circle>) {
std::cout << "Circle radius: " << arg.radius << '\n';
}
else if constexpr (std::is_same_v<T, Rectangle>) {
std::cout << "Rectangle area: " << arg.width * arg.height << '\n';
}
else if constexpr (std::is_same_v<T, Point>) {
std::cout << "Point has no area\n";
}
else {
// triggers at compile-time if a variant type was unhandled
static_assert(always_false_v<T>, "Unhandled variant alternative!");
}
}, shape);
}

int main() {
auto c = Circle { .radius = 1.0 };
processShape(c);
return 0;
}

merge this SAAR for gorgeous looks. compiles clean even with "-Wall -Wextra". this is pattern matching and better than rust SAAR.
>>
>>109621527
>modern
>still using #include
>>
>>109621527
This is as ugly as rust though
>>
>>109621527
enum Shape {
Circle { radius: f64 },
Rectangle { width: f64, height: f64 },
Point,
}

fn process_shape(shape: &Shape) {
match shape {
Shape::Circle { radius } => println!("Circle radius: {radius}"),
Shape::Rectangle { width, height } => println!("Rectangle area: {}", width * height),
Shape::Point => println!("Point has no area"),
}
}


I know which one I'd rather look at.
>>
>header files
>ugly naming conventions
>constexpr boilerplate slop
>your pattern matching just boils down to if else flow control anyways
>[]auto&& arg (???lmao)
>ugly bit shifting into cout instead of a normal print function
>std namespacing bloat

If you hate Rust so much at least look into Carbon lang.
>>
>>109621906
"looks" is a secondary consideration when you're doing serious coding, not fizzbuzz /g/eeting.

C++ is worse because:
1. no sum types
2. no exhaustive checking (see >>109621829 for a joke example where the only change from retarded op is removing variants instead of adding some).
3. run-time overhead due to virtual calls (retarded op didn't know, or "just pretended").
4. dispatching on types is not "pattern matching". that's like calling if-elsing on "v.type_id()" in rust pattern matching lol. expressive languages like rust have extensive support for patterns (both refutable and irrefutable) beyond trivial type dispatch or enum variants matching.

and that's a very non-exhaustive list, just like C++ tard "checks".
>>
>>109622023
>no exhaustive checking
variants can be checked with constexpr. See
      else {
// triggers at compile-time if a variant type was unhandled
static_assert(always_false_v<T>, "Unhandled variant alternative!");
}

enums can be checked in switch statements by the compiler. gcc will emit a warning if you have -Wall.
Dumb tranny, learn before you make dumb critics like this.
>>
>>109621527
header files are dog shit. I am not maintaining two files because the compiler is retarded. Speaking of compilation I am not going to hunt down which build system you use to compile your project and spend hours debugging your shit code because you didn't bother to document it properly.
>>
>>109622038
gorgeous exhaustively checked pattern matching SAAR. all compile-time checked saar.
>>
>>109622227
forgot to post PR saar.
merge asap saar.
-Wall -Wextra clean saar.
https://godbolt.org/z/n1WEafWxq
>>
>>109622023
>1. no sum types
You can implement these with template metaprogramming.
>2. no exhaustive checking (see >>109621829 for a joke example where the only change from retarded op is removing variants instead of adding some).
Wrong—if constexpr exhaustively checks.
>3. run-time overhead due to virtual calls (retarded op didn't know, or "just pretended").
This is an implementation detail. The optimizer devirtualizes these calls.
>4. dispatching on types is not "pattern matching". that's like calling if-elsing on "v.type_id()" in rust pattern matching lol. expressive languages like rust have extensive support for patterns (both refutable and irrefutable) beyond trivial type dispatch or enum variants matching.
Yes it is, retard.
>>
>>109622282
>—
lol
>>
>>109622282
nice opinion, did your corporate overlord pick it for you?
>>
>>109621527
AI makes both rust and C++ obsolete.
>>
>>109621527
>if constexpr
>else if constexpr
>else if constexpr
>else
why is else not constexpr?
>>
>>109621527
imagine if c++ was made by people who are not deeply fucked in the head:

switch(type_of(shape)) {
case Circle: ...
case Rectangle: ...
case Point: ...
default: compilation_error("Unsupported shape");
}
>>
>>109621527
This is everything wrong with modern c++. Would not touch.
>>
>#include
Lil bro still doesn't have 1 (one) functional module implementation.
>>
>>109622609
jeet detected
>>
File: 1758049171049538.jpg (6 KB, 181x184)
6 KB JPG
>>109621527
>Modern C++
>>
>>109621527
>const Shape& shape
Why do people do this? It's literally the worst possible way to format this expression.
>gluing & to the type instead of the variable
>fallback const placement instead of canonical const placement
nigger code
>>
>>109621527
just use rust for max type safety or C for max raw power and flexibility
>>
>>109623681
or just use rust and write it c-style. You get the same performance. "unsafe" isn't scary.
>>
>>109621527
I hate Rust and Rust users, but C++ is a piece of shit. There's no design to the language at all, it's a standards committee bolting more shit haphazardly onto the language year after year.

The first time I read modern Sepples and saw that everyone just spams the 'auto' keyword everywhere to infer types, I realized the language was designed 100% to allow retarded jeets to DESIGN THE LOW LEVEL SYSTEMS CODES SAAR. It's basically Java.

It'd be nice if Rust actually killed off C++, but Rust's borrow checker is so painful that Rust users spend their time writing trivial TUI apps and bragging about them because it feels like an "accomplishment."
>>
>>109625697
>yet another cnile filtered by the borrow checker
jej
>>
>>109625697
Type inference is based
>>
>>109625701
>>109625703
>immediate Rust tranny and Sepples jeet shilling
You people are the AIDS of online programming communities.
>>
File: obsessed.jpg (89 KB, 529x378)
89 KB JPG
>>109625711
>immediate tranny posting
>>
>>109621527
>just want C with built-in objects
>"that's just C++ bro"
>NOOOOOO YOU CANT USE IT LIKE C WITH OBJECTS YOU HAVE TO WRITE MODERN C++ AND FUNCTIONAL PROGRAMMING AUTISM
Objective-C should have won. Fuck you.
>>
>>109621527
I'm never dealing with header/impl files again
>b-b-but modules!
ABI still a mess across compilers and barely supported
>>
>>109622550
else is part of the branch (that is constexpr)
>>
File: 1787468104905795[1].jpg (564 KB, 3516x3340)
564 KB JPG
bruh
>>
File: 1766838972308804.gif (1.12 MB, 320x180)
1.12 MB GIF
>>109625913
This nigga implicitly copied!
>>
>>109621527
I remember seeing some C++ standards proposal years ago that had an actual pattern matching syntax for std::variant and user-defined types. What happened to it? I think it had backing from some big names in the committee.
>>
>>109621527
>Modern C++ makes Rust obsolete.
C makes Rust obsolete

Fixed that for you. C++ is an abomination, a stupid one.
>>
>>109626539
cope neckbeard
>>
>>109621527
>Modern C++ makes Rust obsolete
Delusional
>>
>>109625722
>Objective-C
based beyond belief. Apple should have told Lattner to go fuck himself and ship objc 3.0 instead of swift.
>>
>>109625697
>Rust's borrow checker is so painful
skill issue. It goes away after 2 weeks. It's like learning to ride a bike or drive. You gotta fuck up at some point.
>>
>>109621766
>using dependencies
enjoy your supply chain "attack"



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.