Skip to content

Instantly share code, notes, and snippets.

@nboutin
Last active February 18, 2023 17:00
Show Gist options
  • Save nboutin/fb6f29916eb582e57037842e0ef557ea to your computer and use it in GitHub Desktop.
Save nboutin/fb6f29916eb582e57037842e0ef557ea to your computer and use it in GitHub Desktop.
// https://www.youtube.com/watch?v=nLSm3Haxz0I
class MyWidget
{
void tinker_with(int amount);
public:
class Tinkerable;
Tinkerable get_tinkerable(){
return Tinkerable(*this);
}
};
class MyWidget::Tinkerable
{
MyWidget& widget_;
std::scoped_lock<std::mutex> lock_;
friend MyWidget;
explicit Tinkerable(MyWidget& widget)
: widget_(widget), lock_(widget_.mutex_) {}
public:
void tinker_with(int amount){
widget_.thinker_with(amount);
}
};
void tinker(MyWidget& widget)
{
auto tinkerable = widget.get_tinkerable();
tinkerable.tinker_with(123);
tinkerable.tinker_with(456);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment