Last active
February 18, 2023 17:00
-
-
Save nboutin/fb6f29916eb582e57037842e0ef557ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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