Last active
February 18, 2023 17:00
-
-
Save nboutin/fb6f29916eb582e57037842e0ef557ea to your computer and use it in GitHub Desktop.
Revisions
-
nboutin revised this gist
Feb 18, 2023 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,16 @@ // 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_; -
nboutin revised this gist
Feb 18, 2023 . 1 changed file with 12 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // https://www.youtube.com/watch?v=nLSm3Haxz0I class MyWidget::Tinkerable { @@ -9,6 +10,14 @@ class MyWidget::Tinkerable : 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); } -
nboutin created this gist
Feb 18, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ 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) };