do not click

Meeting C++ 2023   |  Online   |  Training   |  Books   |  Survey   |  Job fair   |  Advertising   |  Jobposting   |  Login

Meeting C++ 2023 - To pass and return — the story of functions, values and compilers

Conference | Live Schedule | Talks | Get your ticket | Set your timezone

Dawid Zalewski

On Day 3 at 15:10 in Track B (Opal Room)

We heard it all, pass by const-reference if you intend to read, by value if you want to take. Return by … now, with return it gets complicated. More often than not, it is return by value and hope for the copy-elision to kick in. However, in some corner cases, you might consider returning an rvalue reference to improve performance or wrapping things in a tuple when multiple values are at play. Oh, and there are also universal references as parameters, and structured bindings or std::tie for accessing tuple’s elements returned by functions. After some digging, you might even discover parameter packs or the fact that capturing into a lambda is actually passing arguments to the constructor of an unnamed object.

If you feel lost after reading this, do not despair. Together, we will look under the hood of optimisers, study the standards, and come up with a set of guidelines on how to pass and return objects to and from functions.

We’ll start with values and discover how compilers help us achieve optimal runtime behaviour by playing tricks with the stack or removing function calls altogether. After this, we’ll delve into the captivating word of references and pointers, showing how and when to use them. Finally, we’ll learn how to pass and return multiple values, by writing code that’s both readable and surprisingly performant.

Please login to comment

Copyright Meetingcpp GmbH Imprint Piwik Opt out Privacy Policy