🌳 Помните времена, когда приходилось писать
std::vector<std::vector<int> > с пробелом? Давайте посмотрим, как изменилась работа с типами за 25 лет!✏️ Пошаговая эволюция:
1️⃣ C++98 - Боль и страдания
//Verbosity nightmare
std::vector<std::pair<std::string, int> > vec; // пробел обязателен!
for (std::vector<std::pair<std::string, int> >::iterator it = vec.begin();
it != vec.end(); ++it) {
// работаем с *it
}
2️⃣ C++11 - Первые облегчения
// auto и range-based for
std::vector<std::pair<std::string, int>> vec; // >> теперь OK!
for (auto& item : vec) {
// намного чище!
}
3️⃣ C++17 - Магия template argument deduction
// Не нужно указывать типы
std::vector vec{std::pair{"hello", 42}, {"world", 24}}; // CTAD!
std::optional opt = some_function(); // тип выводится автоматически
// Structured bindings
for (auto [name, value] : vec) {
std::cout << name << ": " << value << "\n";
}
4️⃣ C++20 - Concepts и constraints
#include <concepts>
template<std::integral T> // Концепты!
auto process(T value) {
return value * 2;
}
// Abbreviated function templates
auto add(std::integral auto a, std::integral auto b) {
return a + b;
}
5️⃣ C++23 - Еще больше удобства
// if consteval для compile-time проверок
constexpr auto get_value() {
if consteval {
return 42; // compile-time версия
} else {
return expensive_runtime_calc(); // runtime версия
}
}
// Multidimensional subscript operator
matrix[1, 2, 3] = value; // вместо matrix[1][2][3]
💔 Частые ошибки:
❌ Злоупотребление auto: auto x = 5u; может быть неочевидным
✅ Явные типы для API: std::uint32_t count = get_count();
❌ Игнорирование concepts: старые template error messages
✅ Используйте standard concepts: std::integral, std::floating_point
Библиотека C/C++ разработчика #буст