Lightning Talk: operator for - C++ Generator Ranges Without Coroutine Overhead - Jonathan Müller

  Рет қаралды 2,552

CppNow

CppNow

8 ай бұрын

www.cppnow.org​
/ cppnow
---
Lightning Talk: operator for - C++ Generator Ranges Without Coroutine Overhead - Jonathan Müller - CppNow 2023
Slides: github.com/boostcon/cppnow_pr...
---
If you want to support the range-based for loop for your type, you have to write an iterator for it. Depending on the complexity of the range, this can be really complicated, since you need to awkwardly model a state machine. Luckily, since C++23 we have std::generator, which gives us a way of using coroutines to specify the range - just write a loop and co_yield each value. However, coroutines have significant overhead, may introduce heap allocation, and are in general more difficult for the optimizer to reason about.
A much simpler solution is to write a function that takes a lambda, which is then invoked for each element. This is fast, but a bit awkward since you cannot use the range-based for loop. This talk discusses `operator for`, an upcoming C++ proposal that adds language support for this pattern.
---
Jonathan Müller
Jonathan is a library developer at think-cell. In his spare time, he works on various C++ open source libraries for memory allocation, cache-friendly containers, or parsing. He also blogs at foonathan.net and is a member of the C++ standardization committee.
---
Video Sponsors: think-cell and Bloomberg Engineering
Audience Audio Sponsors: Innoplex and Maryland Research Institute
---
Videos Filmed & Edited By Bash Films: bashfilms.com/
KZbin Channel Managed & Optimized By Digital Medium Ltd: events.digital-medium.co.uk
---
CppNow 2024
www.cppnow.org​
/ cppnow
---
#boost #cpp #cppnow

Пікірлер: 4
@Voy2378
@Voy2378 6 ай бұрын
at 2:54 I presume [=] capture is terrible for performance?
@ashrasmun1
@ashrasmun1 7 ай бұрын
Ok but... why... Seems a bit over the top.
@ultradude5410
@ultradude5410 7 ай бұрын
Nicer code without coroutine overhead
@guiorgy
@guiorgy 7 ай бұрын
Either you have many places in your code that loops over exactly, and exactly, 3 sequences, and you want to simplify the code, or you could make a variasic template with this and make it generic
КАХА и Джин 2
00:36
К-Media
Рет қаралды 3,8 МЛН
The most impenetrable game in the world🐶?
00:13
LOL
Рет қаралды 16 МЛН
How many pencils can hold me up?
00:40
A4
Рет қаралды 16 МЛН
Python's Walrus Operator??
2:39
b001
Рет қаралды 122 М.
C++ Weekly - Ep 427 - Simple Generators Without Coroutines
5:27
C++ Weekly With Jason Turner
Рет қаралды 9 М.
Why didn't the Angular team just use RxJS instead of Signals?
8:15
Joshua Morony
Рет қаралды 84 М.
Learn useRef in 11 Minutes
10:20
Web Dev Simplified
Рет қаралды 613 М.
Python vs C# - which should you choose?
16:02
Chris Hawkes
Рет қаралды 41 М.
demystifying the secret structure you've been using all along
8:03
Low Level Learning
Рет қаралды 91 М.
Обзор игрового компьютера Макса 2в1
23:34
How Neuralink Works 🧠
0:28
Zack D. Films
Рет қаралды 31 МЛН
НЕ ПОКУПАЙ iPad Pro
13:46
itpedia
Рет қаралды 422 М.