Remix.run Logo
▲ rtpg a day ago

C++ lets you do this kind of stuff as well.

Primitive types and composite types having the same capabilities is a bit of a value statement for C++ and Rust IMO, and it's missing in a lot of languages downstream (IMO) of the "every variable is a reference to a slot/pointer" philosophy taken by most every managed language

▲tialaramex a day ago | parent | next [-]

C++ doesn't have methods/ "member functions" on the primitive types.

One reason is that C++ doesn't know where to put them, for user defined class, struct or union types these "member functions" as their name suggests live inside the class/ struct/ union definition but for a primitive where would these live?

In Rust they're just impl blocks, for example the method we're discussing here is:

    impl bool {    
        pub const fn toggle(&mut self) {
            *self = !*self;
        }
    }
▲pjmlp a day ago | parent [-]

Only because Unified Call Syntax is yet to land into the language, after several failed attempts.

▲aw1621107 21 hours ago | parent [-]

And I think there's a decent chance that it never will, at least in the form it has been proposed in in the past (i.e., member function syntax being effectively turned into free function calls). P3027 "UFCS is a breaking change, of the absolutely worst kind" [0] argues quite strongly that that particular form of UFCS is basically completely broken.

[0]: https://isocpp.org/files/papers/P3027R0.html

▲pjmlp 21 hours ago | parent [-]

As WG21 goes, it is a matter of advocacy, persistency, and getting the required votes in the room, at least if the process doesn't change even with how C++26 contracts turned out to be.

▲aw1621107 19 hours ago | parent [-]

I mean, sure, but that's basically a tautology since that's how everything made it into the standard into the first place. Those are necessary but not sufficient conditions.

▲tialaramex 19 hours ago | parent | next [-]

I'm with you on this and would point at std::hive as an example of the results.

▲pjmlp 19 hours ago | parent | prev [-]

Not really, in first place it was basically CFront 2.0, alongside C++ARM akin to the K&R C book, with last minute addition of HP STL implementation.

The only piece that wasn't really available and was made in a waterfall design approach was export templates, with the known outcome that no one other than EDG has even bothered implementing it.

Post C++98 is when we got into the "advocacy, persistency, and votes" strategy.

▲aw1621107 9 hours ago | parent [-]

You still needed "advocacy, persistency, and votes" to get stuff into C++98. It's just that some things need a lot more of the former to get the latter than others.

▲ a day ago | parent | prev [-]
[deleted]