Created
November 11, 2018 04:27
-
-
Save isaac-weisberg/cf2be7e3cafa24932f11109c1871a341 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
| #include <tuple> | |
| auto foo(int initialBaz) { | |
| int baz = initialBaz; | |
| auto getBaz = [&] { | |
| return baz; | |
| }; | |
| auto setBaz = [&](int newValue) { | |
| baz = newValue; | |
| }; | |
| // Keep in mind, this one is copied compared to new std::tuple, | |
| // which requires explicit template arguments | |
| return std::make_tuple( | |
| getBaz, | |
| setBaz | |
| ); | |
| } | |
| void usage() { | |
| auto fooObject = foo(3); | |
| auto currValue = std::get<0>(fooObject)(); // 3 | |
| std::get<1>(fooObject)(5); | |
| auto newValue = std::get<0>(fooObject)(); // 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment