CppCon 2018: Dan Saks “Making New Friends”

preview_player
Показать описание


A friend of a class is a function or class that is not a member of that class, but nonetheless has access to all members of that class. The conventional wisdom is that granting friendship is something you do should sparingly. This lecture introduces a distinctive use for friend function declarations in class templates that's not about granting access to non-public members. Rather, it's about using a template as a
factory for "making" new friends. Along the way, this session explains various subtleties about operator overloading, overload resolution,
template instantiation, and name lookup for friend functions.


Dan Saks, Saks & Associates
President



*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

Fantastic talk. The kind of talk you attend CppCon for. I'm sorry I missed it in person.

bzzr
Автор

What's NOT to like about this talk? I learned a lot of useful stuff in just one hour. Thanks!

krytharn
Автор

Thanks a lot for presenting this useful technique. I never heard about it before. The talk was structured very well, was easy to follow and gives a concise guideline in the end. I'm sure I can use this someday.

fbnode
Автор

15:28 I see a clear typo/mistake: os.put(r) should be r.put(os).
And it's corrected immediately on video! Nice.

MichalMaruska
Автор

Also useful for *non-operator* non-member functions associated with a class template and considered by ADL, like begin(), end(), and swap().

oktal
Автор

11:10 Doesn't returning a parameter break NRVO?

ultradude
Автор

I thought it was making "new" ( the operator ) friend

zhaoli
Автор

or just provide public getters for nom/den

dennisrkb
Автор

One would see why C programmers would not want to use C++.
There is too much going on.
A language shouldn't require 5 years of experience to make you productive.

ovndfbs