Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/14_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ size_t size(T (&arr)[N]) {
```
Важный момент в non-type параметрах шаблона: **всё, что вы подставляете в шаблон, должно быть известно на этапе компиляции**. Потому что только на этапе компиляции существуют типы, в частности, шаблонные типы.
В *C++20* нестатический шаблонный параметр может быть объявлен как auto, позволяя выводить тип из аргумента. Например:
```cpp
template <auto N> struct S {
static constexpr auto value = N;
};
```

Comment on lines +213 to +219

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

непонятно что хотел сказать автор

## Template template parameter.
Хочется обёртку над контейнером. Зачем-то.
```c++
Expand Down
4 changes: 4 additions & 0 deletions src/15_stl.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ using reference = Reference;
v.erase(it, v.end()); // чистим хвост, так как физический размер вектора остался тем же (подробнее на cppreference)
```

В *C++20* ассоциативные контейнеры `(std::map, std::unordered_map, std::set, std::unordered_set)` получили метод `contains(key)`, который возвращает `bool`, проверяя наличие ключа. Это удобнее и читаемее, чем `count(key) > 0` или `find(key) != end()`.

Начиная с *C++20*, для всех контейнеров появилась функция `std::erase_if`. Например, std::erase_if(v, pred); выполняет удаление за один вызов, что проще, чем комбинация `remove_if + erase`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::erase_if(v, pred); стоит сделать моноширинным


В *C++20* появился `operator<=>` (three-way comparison) сразу говорит, "меньше, равно или больше" и в возвращаемом значении говорит, какой *order* даёт (`partial`, `weak`, `strong`).
Так же в *C++20* появились `range`, и какие-то алгоритмы в STL могут поменяться.

Expand Down