The Ranges library modernizes algorithms with composable, lazy views:
#include <ranges>
#include <vector>
#include <iostream>
using namespace std;
int main() {
vector<int> nums = {1,2,3,4,5,6,7,8,9,10};
// Pipeline: filter even, square, take first 3
auto result = nums
| views::filter([](int n) { return n % 2 == 0; })
| views::transform([](int n) { return n * n; })
| views::take(3);
for (int n : result) cout << n << " "; // 4 16 36
cout << endl;
return 0;
}
Coroutines (Overview)
Coroutines are functions that can be suspended and resumed, enabling cooperative multitasking and generators without callbacks:
// Coroutines require co_await, co_yield, co_return keywords
// and a coroutine framework (std::generator in C++23)
// This pattern enables:
// - Async I/O without threads
// - Lazy generators
// - Stateful state machines
Modules (Overview)
Modules replace header files with a faster, cleaner compilation model:
// math.cppm (module file)
export module math;
export int add(int a, int b) { return a + b; }
// main.cpp
import math;
int main() { return add(3, 4); }
Quiz
What do C++20 Concepts do?
A) Replace virtual functions
B) Constrain template parameters with named requirements
C> Add runtime type checking
D> Replace inheritance
Answer
B) Concepts give template parameters named, readable constraints with better error messages.
Summary
Concepts — constrained templates with readable type requirements.
Ranges — composable, lazy pipelines with | operator.
Coroutines — suspendable functions for async and generators.
Modules — replace headers with fast, clean compilation units.