mattkretz / wg21-papers

my papers to WG21 — the C++ committee
5 stars 7 forks source link

added compatiblity-usecase as motivation #79

Closed MFHava closed 3 years ago

MFHava commented 3 years ago

Hi,

@bernhardmgruber recently mentioned you're looking for additional convincing use-cases for non-member subscript operators. I think compatibility layers once P2128 is adopted would be a good addition - hope the prose is good enough to convey the basic idea (though it probably should be reworked and merged with the motivation instead of being presented in one of the examples).

Best, Michael

PS: My TeX skills are extremely rust, hope it isn't too broken.

mattkretz commented 3 years ago

Thanks! I will handle the LaTeX stuff (and references), np. Personally, I think the point isn't very strong motivation. It's kind of like saying: "we need this to temporarily work around historical issues". The point would be stronger if the "temporarily" part wasn't so obvious.

BTW, did I mention hidden friends before? It's nice for "deducing this":

struct A {
    friend auto& operator[](auto& a, int i) {
        return a.d[i];
    }
    float d[100] = {};
};

See: https://godbolt.org/z/ov9sPchez And we could finally support the surprising [] semantics of C-arrays :stuck_out_tongue_winking_eye: :

int a[100];
void f() {
    assert(&a[1] == &1[a]);
}
MFHava commented 3 years ago

It's kind of like saying: "we need this to temporarily work around historical issues". The point would be stronger if the "temporarily" part wasn't so obvious.

Well, given the way these things tend to move, "temporarily" pretty much means "this will enable us to leverage non-member subscript a decade earlier than if we wait till everybody drops pre-C++23 as their target version".

BTW, did I mention hidden friends before? It's nice for "deducing this": It's not in the draft I've seen - but probably should be...

See: https://godbolt.org/z/ov9sPchez And we could finally support the surprising [] semantics of C-arrays 😜 : Now you make me question whether that is a good idea after all 🤔

mattkretz commented 3 years ago

It's kind of like saying: "we need this to temporarily work around historical issues". The point would be stronger if the "temporarily" part wasn't so obvious.

Well, given the way these things tend to move, "temporarily" pretty much means "this will enable us to leverage non-member subscript a decade earlier than if we wait till everybody drops pre-C++23 as their target version".

I agree. But in Evolution, sometimes discussion about real-world issues doesn't carry enough weight and might sometimes even evoke negative comments.