Badge pattern allows us to abstract over friend classes and make friend feature more scoped. Using this simple technique we can specify a badge tag on specific functions we want to gate for particular caller contexts (badge holders). Badge can only be constructed by the specified badge holder binding the tagged functions to that call site.
Synopsis
Declared in <folly/lang/Badge.h>
template<typename Holder>
class badge;
Description
As a rule, it is poor form to pass a badge to arbitrary code. It is poor form for virtual, type‐erased, or template functions to accept badges or to be passed badges.
Example: class ProtectedClass: { ... public: ... static void func(folly::badge<FriendClass>); };
void FriendClass::callProtectedFunc() { ProtectedClass::func({}); // compiles } void OtherClass::callProtectedFunc() { ProtectedClass::func({}); // does not compile! }
See: https://awesomekling.github.io/Serenity‐C++‐patterns‐The‐Badge/
Member Functions
Name |
Description |
|
Construct a badge from an any_badge that includes this holder. |
Friends
Name |
Description |
|
Created with MrDocs