Skip to content

Commit 5c16b11

Browse files
committed
Add readme entry
1 parent 57c73c3 commit 5c16b11

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

lectures/std_function.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
`std::function`
22
--
3+
4+
<p align="center">
5+
<a href="https://youtu.be/blah"><img src="https://img.youtube.com/vi/blah/maxresdefault.jpg" alt="Video Thumbnail" align="right" width=50% style="margin: 0.5rem"></a>
6+
</p>
7+
38
- [`std::function`](#stdfunction)
49
- [Overview](#overview)
510
- [The problem: storing callables](#the-problem-storing-callables)
@@ -255,10 +260,10 @@ On the contrary, `std::function` is for situations like UI callbacks and event h
255260
256261
However, what I just said is just a rule of a thumb. When performance really matters - we should always measure the alternatives and pick the option that suits us best!
257262
258-
## Type Erasure (How it works under the hood)
263+
## Type erasure (how it works under the hood)
259264
Finally, I want to briefly talk about how `std::function` actually works under the hood. How can it store an arbitrary callable (say a lambda or a functor) without knowing its exact type at compile time? How does it all get cleaned up neatly without [leaking memory](memory_and_smart_pointers.md)?
260265
261-
This is achieved using a design pattern called **Type Erasure**.
266+
This is achieved using a design pattern called **type erasure**.
262267
263268
> 💡 Note that you don't have to know this to use `std::function`! It is also very unlikely that you'll ever need to implement your own type-erased wrapper. Still, it is a pretty cool pattern worth knowing about. It's used in several places in the standard library, including `std:shared_ptr`, `std::any`, and, as we'll see, in `std::function` itself.
264269

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,23 @@ Headers with classes
785785
----------------------------------------------------------
786786
</details>
787787

788+
<details>
789+
<summary>Storing callables with <code>std::function</code></summary>
790+
791+
----------------------------------------------------------
792+
[![Video thumbnail](https://img.youtube.com/vi/blah/maxresdefault.jpg)](https://youtu.be/blah)
793+
794+
- [`std::function`](lectures/std_function.md#stdfunction)
795+
- [Overview](lectures/std_function.md#overview)
796+
- [The problem: storing callables](lectures/std_function.md#the-problem-storing-callables)
797+
- [Enter `std::function`](lectures/std_function.md#enter-stdfunction)
798+
- [Performance considerations](lectures/std_function.md#performance-considerations)
799+
- [Type erasure (how it works under the hood)](lectures/std_function.md#type-erasure-how-it-works-under-the-hood)
800+
- [Summary](lectures/std_function.md#summary)
801+
802+
----------------------------------------------------------
803+
</details>
804+
788805
## PS
789806

790807
### Most of the code snippets are validated automatically

0 commit comments

Comments
 (0)