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
int f() { | |
Foo foo; | |
return foo.bar(); // foo automatically destroyed | |
} |
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
int f() { | |
Foo* foo = new Foo(); | |
int x = foo->bar(); | |
delete foo; // How inconvenient! | |
return x; | |
} |
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
int f() { | |
Foo* foo = new Foo(); | |
return foo->bar(); // Leak! | |
} |
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
int f() { | |
Foo foo = new Foo(); | |
return foo.bar(); | |
} |
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
// Pseudo-code | |
struct VirtualTerminal { | |
string buffer; // Currently visible output | |
string computeTransition(string const& prev, string const& next) { | |
const string deleteLine = "\e[2K\r\e[1A"; | |
return repeat(count("\n", prev), deleteLine()) + next; | |
} | |
VirtualTerminal flip(std::string const& str) const { |
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
running task: download | |
progress(75%): [xxxxxxxxx ] | |
Tasks Done: 1/5: [x ] |
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
running task: download | |
progress(50%): [xxxxxx ] | |
Tasks Done: 1/5: [x ] |
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
struct Text { | |
Style style; | |
std::string text; | |
Image render() const { | |
std::vector<Pixel> pixels(text.size(), Pixel{ style }); | |
for (int i = 0; i < text.size(); ++i) { | |
pixels[i].c = text[i]; | |
} | |
return Image{ width, height, pixels }; |
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
struct Renderable { | |
virtual Image render(unsigned const width) const = 0; | |
virtual ~Renderable() {} | |
}; | |
template<class T> | |
struct Model : Renderable { | |
T data; | |
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
enum class Color { /* ... */ }; | |
enum class Font { /* ... */ }; | |
struct Style { | |
Color bg; | |
Color fg; | |
Font font; | |
}; | |
struct Pixel { |