3 ms·
I don't really see the point when C++ already lets you write void foo(auto& t) { t.bar(); } which can be called with any class that has the .bar() method anyw
by cherryteastain 2y ago
I don't really see the point when C++ already lets you write
void foo(auto& t) { t.bar(); }
which can be called with any class that has the .bar() method anyway.
- Maxatar 2y agoBecause it can also be called with any class that doesn't have the bar method, and good luck deciphering the compiler error for it when it's nested 3 levels deep into some far corner of the STL.
- lbhdc 2y agoThat is what concepts fix. It lets you enforce at build time that `t` does have member `.bar()`.
- deleted 2y ago[deleted]
- Toritori12 2y agoman I love learning good stuff by casually learning HN. I code on cpp as a hobby and kinda new you could use "auto" on templates by didn't know about this.
- asyx 2y agoCheck out concepts. That allows you to enforce the existence of the function. Also works with static functions and such.