Skip to content

Instantly share code, notes, and snippets.

@chiiph
chiiph / defer2.go
Created December 26, 2012 20:14
Another defer example
func b() {
for i := 0; i < 4; i++ {
defer fmt.Print(i)
}
}
__block int variable = 1;
int anotherVariable = 2;
void (block^)() = ^{
variable++; // actually modifying variable
anotherVariable++; // modifying a copy
}
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();
}
});
int nonModifiable = 42;
int modifiable = 23;
auto myLambda = [=, &modifiable]() mutable { modifiable++; nonModifiable++; };
myLambda(); // modifiable == 24, nonModifiable == 42