Live data from Hacker News

C++20 Reference Card

bfilipek.com

41–48 of 48 posts

Re: C++20 Reference Card

#41
post #33
post #26

Earlier quoted context omitted.

Damn it looks good. I wish it could target and consume .NET or Java.

What does that even mean? "Target" I guess could mean that it could compile to code for those virtual machines? That would make some sense although for a language that sets out to compete with/replace C it would be a bit strange. For "consume" I don't know ... do you mean "call into", or something?

Correct on both cases.

With .NET I'd love integration with existing types and generics too.

Actually, I was just thinking aloud. I don't really mean for Zig authors to target .NET, but rather have .NET Core runtime and C# to have the concept of compile-time values and types.

Re: C++20 Reference Card

#44

Earlier quoted context omitted.

> capabilities similar to -- and at least as powerful as -- type templates, value templates, constexprs, concepts, and conditional compilation (preprocessor), with a single feature and keyword are you sure ? zig does not seem to have something that looks like concepts (an issue is open : https://github.com/ziglang/zig/issues/1268 ) nor a way to put restrictions on a given type passed to a function or series of functi…

Here's the C++ example from the article: template concept SignedIntegral = std::is_integral_v && std::is_signed_v ; template // no SFINAE here! void signedIntsOnly(T val) { } Here's the equivalent Zig code. You can run this with `zig test example.zig`. const std = @import("std"); const assert = std.debug.assert; fn signedIntsOnly(val: var) void { comptime assert(std.meta.trait.isSignedInt(@TypeOf(val))); } test "conc…

> assert(std.meta.trait.isSignedInt(@TypeOf(val)));

well yes, that's my point. You could also write

    void signedIntsOnly(auto val) {
        static_assert(std::is_integral_v && std::is_signed_v); 
    }
in C++ but it's quite preferable to refactor this inside the types themselves (for the same reason that you want to refactor any other kind of code in general - besides you don't want to go read the implementation of your functions every time do you ? IDEs show us only prototypes for a reason).

How would you for instance specialize a generic function in Zig ? Does zig accept

    fn complexmathoperation(val: var) void {
        if(isInt(@TypeOf(val))) { 
        }
    }
and in another module

    fn complexmathoperation(val: var) void {
        if(isSomeKindOfLibrarySpecificMatrix(@TypeOf(val))) { 
        }
    }
and properly dispatches between both ?

I'd be hard pressed to say that it is "as powerful" given what I'm seeing for now.

Re: C++20 Reference Card

#45
post #33
post #26

Earlier quoted context omitted.

Damn it looks good. I wish it could target and consume .NET or Java.

What does that even mean? "Target" I guess could mean that it could compile to code for those virtual machines? That would make some sense although for a language that sets out to compete with/replace C it would be a bit strange. For "consume" I don't know ... do you mean "call into", or something?

Not strange at all, apparently many still aren't aware that C++/CLI exists.

CLR was designed from the start to support C++.

Back in the 2000, "Everything.NET" Microsoft, there was the goal of having everything on top of .NET, it just did not play out that way due to the endless Windows/Office vs .NET politics across MS teams.

Using C++/CLI is much more productive for interop than manually writing P/Invoke declarations.

Or using C++/WinRT to wrap C++ API into COM/UWP libraries.

Likewise on Java, microEJ and Android world, with Android Studio, Eclipse, Netbeans and Oracle Studio you can easily do mixed language development and debugging with C and C++.

Any systems programming language that wants a place at the table on these platforms, needs to cover these workflows as well as C++ does.

Re: C++20 Reference Card

#46

Earlier quoted context omitted.

Here's the C++ example from the article: template concept SignedIntegral = std::is_integral_v && std::is_signed_v ; template // no SFINAE here! void signedIntsOnly(T val) { } Here's the equivalent Zig code. You can run this with `zig test example.zig`. const std = @import("std"); const assert = std.debug.assert; fn signedIntsOnly(val: var) void { comptime assert(std.meta.trait.isSignedInt(@TypeOf(val))); } test "conc…

> assert(std.meta.trait.isSignedInt(@TypeOf(val))); well yes, that's my point. You could also write void signedIntsOnly(auto val) { static_assert(std::is_integral_v && std::is_signed_v ); } in C++ but it's quite preferable to refactor this inside the types themselves (for the same reason that you want to refactor any other kind of code in general - besides you don't want to go read the implementation of your function…

> besides you don't want to go read the implementation of your functions every time do you ? IDEs show us only prototypes for a reason

The IDE can be changed to show you assertions in addition to the signature, just as it also shows doc comments. That the signature is special isn't some law of nature, it's just habit (and users of untyped languages don't even have those).

> How would you for instance specialize a generic function in Zig ? ... and properly dispatches between both ?

No, you'd need a single definition with a comptime branch.

> I'd be hard pressed to say that it is "as powerful" given what I'm seeing for now.

What you're seeing is personal taste. In my taste, that Zig doesn't allow overloading and has clear dispatch is clearer is more preferable (in fact, it's touted as one of Zig's biggest strengths); in yours, it is less preferable. That's perfectly OK, but it's got nothing to do with expressive power (which has a pretty good and precise definition: https://youtu.be/43XaZEn2aLc). There is a reason why some languages are more complicated while others are simple -- some people aesthetically prefer the more complex languages while others prefer simpler ones. What is impressive about Zig is that despite being simple, it's not giving up power, at least in those aspects I mentioned. C, another simple language, cannot do those things.

Re: C++20 Reference Card

#47

Direct links: C++20 Features https://mcusercontent.com/e93417593cbf4da3dba03d672/files/42... Language Features of C++17 https://gallery.mailchimp.com/e93417593cbf4da3dba03d672/file...

[author here] you can always unsubscribe at any time, I think it's a fair trade. So please consider removing that comment with the links.

Re: C++20 Reference Card

#48

Earlier quoted context omitted.

I use it everyday, and I'm still very eager to stop using it due to its growing complexity. I'm trying to gradually replace C++ with Rust as my primary language, but it's still a lot easier to get a well-paying job in C++ than in Rust.

Rust is both more complex and uglier than modern C++. If your complaint is having to learn new stuff, then Rust isn't the solution.

i’m not disagreeing with you (i’m learning rust, so don’t have a strong opinion yet) but am curious how you feel that way?
Post reply on HN