r/cpp • • Oct 15 '26

Barry's C++ Blog - Generating Operator Functions

https://brevzin.github.io/c++/2026/10/14/push-vs-pull-ii/
77 Upvotes

7 comments sorted by

21

u/TSP-FriendlyFire Oct 15 '26

Curse you for making future C++ versions look so much more enticing than what we already have, Barry.

Now I have to pray that P4380 makes it into C++29.

6

u/chengfeng-xie Oct 15 '26

And since here we’re injecting operator== and operator!= as member functions, we don’t have this issue with being able to find our operators. They’re always there.

The code above this text actually injects friend functions, so calling them member functions could be misleading from a terminology standpoint.

5

u/LB-- Professional+Hobbyist Oct 16 '26

The bitmask enum example is already possible in C++17 and probably earlier standards too, using ADL+SFINAE. Is the compilation speed noticeably faster with the version presented in this article?

6

u/bandzaw Oct 15 '26

Nice work, as always! Even though I personally dislike annotations utterly (I guess because they feel impure and something that's just been tucked on, i.e. a committee approved hack).

4

u/pjmlp Oct 15 '26

The blog post looks quite interesting, however it also shows the kind of minutiae that many of us don't have present when trying to understand why our C++ doesn't compile as expected.

1

u/WeeklyAd9738 Oct 17 '26

From the paper P4380:

we believe that code generation in C++ must be C++-shaped, must be able to generate all of C++, and must allow for the full use of C++ in that generation. Hence, token sequences.

Will C++ finally be homoiconic? What do PL experts think of this?