Show newer

@soft youd think id get used to softism eventually, but no, it keeps surprising me

@vantiss at least the VAs sound like they're having a blast

Hi @vaporeon_, a while ago we talked about the fact that references were introduced to C++ in order to enable operator overloading. You asked why you have to introduce references to enable this and I said that you didn't and it was an unnecessary complication.

I've been thinking about this and I don't agree anymore.

In C++, operators used with class types are syntactic sugar for method calls:

#include <iostream>

class NumWrapper {
public:
int val;
NumWrapper(int n) : val(n) {}
NumWrapper operator+(NumWrapper& r) { return NumWrapper(this->val + r.val); }
};

int main() {
NumWrapper l(3);
NumWrapper r(4);

std::cout << (l + r).val << "\n";
std::cout << l.operator+(r).val << "\n";
}

So why not make the overload method take pointers instead?

class NumWrapper {
public:
int val;
NumWrapper(int n) : val(n) {}
// why didn't c++ implement operator overloads like this?
NumWrapper operator+(NumWrapper* r) { return NumWrapper(this->val + r->val); }
};

Well, imagine we used an rvalue as one of the + operands. Then a pointer to an rvalue would be passed to the overload function. rvalues normally have their addresses hidden from the programmer (you can't give them to &). Then operator overloading would circumvent this feature and allow the programmer to access the address of an rvalue.

I currently believe that references were introduced so that C++ could have a pointer-like language construct that does not expose the addresses of rvalues.

@monorail very "I watched Bill Nye the Science Guy as a kid"-coded

@aescling @monorail @Lucy to be fair, the fact that I watched Bill Nye the Science as a kid also makes me feel old

@coriander also good job blotting out the license plates, very ehtical of you

@coriander @monorail @rockario the decimal point should be moved to the right by one spot my mistake

@amy @coriander @monorail @rockario I just found a 40 minute video that explains how the fuck a game can be beaten in 0.000005 seconds

@coriander @monorail @rockario if an NES game runs at 60 fps, which reddit tells me is usually the case, then 1 frame is 1666.666.... microseconds

if the game runs at 30 fps then the length would be twice that number

this might be worse than when disco elysium called me The World's Most Laughable Centrist how could this happen to me.

Show thread
Show older
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.