This file contains 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
func b() { | |
for i := 0; i < 4; i++ { | |
defer fmt.Print(i) | |
} | |
} |
This file contains 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
__block int variable = 1; | |
int anotherVariable = 2; | |
void (block^)() = ^{ | |
variable++; // actually modifying variable | |
anotherVariable++; // modifying a copy | |
} |
This file contains 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
std::shared_ptr<GameObject> gameObject { std::make_shared<GameObject>("Bomb") }; | |
cocos2d::CCLabelTTF *myLabel = cocos2d::CCLabelTTF::create("Explode!", "Arial", 30.0f); | |
auto myLambda = [gameObject]() | |
{ | |
if (gameObject.use_count() > 1) | |
{ | |
gameObject->explode(); | |
} | |
}); |
This file contains 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
int nonModifiable = 42; | |
int modifiable = 23; | |
auto myLambda = [=, &modifiable]() mutable { modifiable++; nonModifiable++; }; | |
myLambda(); // modifiable == 24, nonModifiable == 42 |
NewerOlder