Avoiding unnecessary temporary object creation in C++ is crucial for improving performance and reducing resource usage. This talk delves into common scenarios where temporary objects are created and provides practical strategies for improving code.
We'll cover some best practices identified during code reviews within our organization.
We’ll begin with techniques for reducing temporary objects in commonly used types like std::string and std::vector, and then extend our journey to other STL types such as std::pair, std::tuple, std::optional, std::expected, std::variant, std::initializer_list, as well as other sequence and associative containers.
std::string
std::vector
std::pair
std::tuple
std::optional
std::expected
std::variant
std::initializer_list
Attendees will also learn to avoid costly operations by using transparent comparators and moving constant objects with global lifetimes to compile-time data structures.
This session includes code examples to demonstrate these principles in action. By the end of the talk, attendees will be equipped with actionable takeaways to enhance the efficiency of their C++ codebases.
View Slides
Chandranath Bhattacharyya has been a professional programmer since 2000, with most of his career focused on C++. He currently works at Microsoft on the Edge browser team and is a dedicated internal educator. Over the past five years, he has delivered around 40 C++ talks to an internal audience of more than 100 engineers, emphasizing clear explanations of language features and practical best practices.
He has also begun presenting at public C++ conferences, including one talk at C++Now 2025 and two talks at CppCon 2025. Chandranath serves as a reviewer for submissions to C++Now, C++OnSea, and CppCon.
Kathleen is a software engineer working at Microsoft on the Edge browser. She is very excited about presenting at her first C++ conference. In her free time, she likes to do triathlons and try new foods.