2024-11-19

Livecoding 2024-11-19/intro.cpp, according to notes

Notoriously did not reach the goal (there has no goal been set), but touched the following topics as the pointless todo-list was morphed to something even more pointless.

std::map, And Pitfalls

std::map, when filled using tdl["something"] = Item("... blah ..."), requires class Item to have a default constructor. This is not entirely obvious, to say the least.

Problem: std::map::operator[]() creates a node with a default-constructed value, which is then overwritten with Item("... blah ...").

Solution: use std::map::insert(), or even better in our case at least, use an initializer list and a const todo_list object.

Demo of the pitfall (std::map::operator[]()) in 2024-11-19/map-pitfall-no1.cpp

Brace Initialization

Discussed the differences between {} and (). See 2024-11-19/brace-init.cpp

Smart Pointers, And Move Semantics

While using std::shared_ptr<> in 2024-11-19/intro.cpp, we approached the topic in

While we were at it, we discussed related topics like

Pythonicity

Nothing more to say; morphed 2024-11-19/intro.cpp into something more readable.

Lambda

Transformed 2024-11-19/intro.cpp into something that is more to the point. Talk about interfaces, the cost of virtual (RTTI is not free), and readability in general.

For what a lambda really is, see the old school functor demo (2024-11-19/functor.cpp).

Use cases for lambda: