San Diego C++ Meetup Apr 11 2023 – #49

Summary of the last San Diego C++ Meetup – held on April 11 2023. This was our 49th meeting since inception on March 12 2019.

Sorry again for the delay posting this summary. I had some technical issues uploading the recording last week and finally found some time to write the summary.

Recording can be found here:

San Diego C++ meetup recording – April 11 2023

Discussion points:

C++Quiz.

Three fun C++Quiz questions. One related to UB when writing to const, another one related to copies made when using range for loop with auto and the last one was related to references and alias.

Walletfox slide – C++ Functional programming

I really love Walletfox (Ruzena Gurkaynak) work. The website has FP slides, Ranges-v3 booklet that can be purchased online (ebook + printed) which is highly recommended!

We discussed one slide related to Curring and “Partial” (like bind1st and similar but modern style).

Why I cannot emplace_back

This came up during code review. I was demonstrating the differences between vector::emplace_back of a simple struct vs unique_ptr<> “hosting” this struct. More info in the recording.

Using std::tie in C++

I love C++17 [structured, binding] but when I have no choice or when it falls short, I use std::tie. Also std::tie has other few applications that makes it easy to write code. I demonstrated few.

PImpl pattern

The final course was PImpl pattern. One of my favorite and a very useful pattern. We went through the definitions in cppreference, and mostly went over Herb’s GOTW #100/101.

That’s it for April meeting summary.

Thank you!

Kobi

San Diego C++ Meetup Mar 21 2023 – #48

Amir in his Daily life

Yet another apology on the delay in posting the summary of the latest San Diego C++ Meetup. Super busy at work.

It’s finally Friday night and I have some time to sit down and write the summary.

4 years. Total of 48 meeting. Missed just one session, March 2020 when COVID started. I was not ready yet for the whole virtual meeting thing and here we are today. 3 years later – all virtual.

The first year was in person, we were just building up the group in San Diego. XCOM-LABS were generous enough to provide the space, first in La Jolla UTC and then Miramar area – yeah, where you can find Top-Gun 🙂

For the past 3 years, Qualcomm is sponsoring (paying the meetup.com fees) this group, especially my VP, Charles B which is a big supporter.

For meeting #48, we had Amir Kirsh. This is not Amir’s first appearance in the group and we really like his talks.

You can find the meetup page here, the YouTube channel has many past recording including the latest one with Amir.

Talk abstracts:

C++ Incidental Explorations by Amir Kirsh
This talk will guide us through some interesting discussions of C++ using questions from StackOverflow for inspiration. With these questions as our starting point, we will try to learn C++, explore some of the corners of the language, get lost down a few rabbit holes, and become familiar with some topics usually reserved for “language lawyers”. We finish by exploring whether, and how, ChatGPT might help with writing C++ in the future.

Summary: This was a unique session. Exploring Stackoverflow C++ questions, discussing about various ways to analyze C++ questions, searching for unique questions and finally, we had a nice discussion on GPT, ChatGPT and how this can help us, especially in the context of programming and C++.

Among the many topics covered, we discussed Chrono library, auto as an optimization opportunity, overload resolution, const RValue – is it useful?, Iterator class, Reverse Iterator tricks, UB in accessing unwound stack address, — > “operator” , sorting, class owning a member of its own type and many more. All in just 90 minutes!

Amir’s Bio: Amir Kirsh is a Lecturer at the Academic College of Tel-Aviv-Yaffo and a Visiting Lecturer at Stony Brook University, as well as Developer Advocate at Incredibuild. Amir also serves as one of the organizers of the CoreCpp meetup group and CoreCpp conference in Tel-Aviv, as well as a member of the Israeli ISO C++ National Body.

Thank you Amir! and see you all next time!

Kobi

San Diego C++ Meetup Feb 15 2023 – #47

Apologize about the delay in posting this. Here are the minutes from the last San Diego C++ Meetup, held on Wed Feb 15 2023 5PM Pacific time. Thank you everyone for joining!

The meetup was recorded and uploaded to sdcppmu YouTube channel here:

San Diego C++ Meetup #74 Youtube recording

So what did we have in this meeting?

First – I presented an interesting Req in Qualcomm ML/AI Cloud group. The req number is 3046377 and you can find it on Qualcomm jobs website.

Next, we went over 4 cppquiz questions. The idea here, besides fun, is to learn new elements and constructs in the language. The cppquiz questions were 333,312,318 and 319. We learned about post increment, struct/class inheritance and members visibility, operator void(), casting to void and finally, ternary operator with class inheritance and implicit conversion using implicit constructor.

Next, we discussed the following use case how-to-prevent-stdfunction-to-bool-conversion-in-c-function-overloading . We demonstrated usage of C++20 concepts (std::invocable) as well as enable_if_t.

The next topic is a very interesting one. Polymorphic arrays pitfalls. segmentation-fault-in-operator-delete . It talks about allocating an array of a derived class type and assigning it to a base class pointer. When we do pointer arithmetic, it’s all messed up, and obviously delete []p will also fail. A good picture of what’s going on can be found here:

polymorphic array done wrong

We demonstrated few alternatives. For example, std::vector<p*> would be a good approach and instead would look like:

Vector polymorphic done right

More info and details in the actual recording.

The last one was about template instantiation, RValue binding to const& vs non const& and the implications. Also mentioned (again) implicit conversion in the same context. The details can be found here: why-does-removing-const-from-the-constructor-parameter-stop-the-class-from-being-instantiated . The actual code is here:

What, The Heck

Long story short, when you have const& the compiler can create temp of What<int> with the which is passed, so it tries to instantiate What<T>(The) and check if this Heck(const What<int>&) can be used . If there is no const, you cannot do such RValue/temp binding hence no need to instantiate What<T>. Though we did mention that Heck(The) constructor will be a better match anyway since it does not require any user defined conversion to happen.

That’s it for this #47 session of sdcppmu. See you next month with a special guest. Will be announced soon!

San Diego C++ Meetup Jan 17 2023 – Coroutines

Hello everyone!

On Tuesday, Jan 17 2023 we hosted the 46th session of San Diego C++ Meetup.

This time, I gave a talk on C++20 Coroutines which I named “YACRT – Yet Another Coroutine Talk”. There are many good talks out there and I decided to have another one for the San Diego C++ group.

Here is the recording:

During the talk, I’ve described both Generators and non-Generators techniques, focusing on thread context, the C++20 Coroutine API and the various customization points. I had few CLion gdb/debugger screenshots to demonstrate the various parts of the runtime call flow.

Generators – I showed simple Generator with co_yield.

For non-generators, I was inspired by this blog post Pablo A io_uring and coroutine post which has 3 parts. It talks about the combination of Coroutines and Linux 5.x Kernel’s io_uring feature which is by itself really cool feature to be aware of. Here is a simple diagram. You basically submit work (read/write from/to FD) and the kernel is doing it on your behalf! You just query for completion and carry-on.

io_uring

And what did I implemented for this session? A Coroutine function that is reading bytes from a UDP socket on a dedicated thread once we are suspending an Awaiter, when done – resuming the coroutine and then submitting a request to the kernel for file write. That’s the second co_await/Awaiter. The resume of this co_await happens in main function where we wait on the Kernel operation completion using a blocked function API. Here is a simple diagram of the main parts:

coroutine function and the pieces

Obviously, you’d need to watch the recording in order to get the full sense of what’s happening.

It was the first time for me presenting on C++20 coroutine and it’s not easy. Lots of moving parts and details to be aware of. It took me 2 hours to go over 60 slides!

Thanks for reading!

Kobi

San Diego C++ Meetup Hosting Amir Kirs – To Move Or Not To Move!

Hello everyone!

Tonight (Dec 6 2022) we hosted Amir Kirsh from Incredibuild.

Amir went over the various use cases of using std::move, also highlighting std::forward usage, various pitfalls and he provided us with good set of guidelines on when to use and not to use std::move.

Highly recommended!

Here is the recording (can be found in Youtube channel sdcppmu)

Our event link on meetup.com can found here: San Diego C++ Meetup

Amit Kirsh

San Diego C++ Meetup – #44 – RxCpp and Boost.Asio

Today, Monday, November 14, we had our #44 San Diego C++ Meetup.

Unfortunately, there seem to have some issues in the posted link on meetup and many could not attend. Giant apology on this one. Not sure what happened and how but would pay extra attention next time (Dec 2022 here I come …).

Tonight, we discussed few interesting C++ Quiz questions, talked about RxCpp book from packt –

And also talked about Boost.Asio from the excellent Boost book:

here is the recording:

Enjoy!

Kobi

San Diego C++ Meetup – October 17 2022

Hello everyone,

Yet another great evening meeting others and discussing C++.

Agenda can be found in the even link here: sdcppmu-event

Recording, in the Youtube channel at sdcppmu:

Great discussion points on const vs non const function – how to avoid duplication of code.

How “deducing this” makes the syntax shorter.

Martin shared the following: volatile: The Multithreaded Programmer’s Best Friend

We also discussed the blog post update: use-case-of-utilizing-stdset-instead-of-stdmap and heterogeneous lookup. See more here:

abseil-tips-144

and cppstories-heterogeneous-lookup-cpp14 , https://www.cppstories.com/2021/heterogeneous-access-cpp20/

Thank you!

Kobi

San Diego C++ Meetup #42 – September 22 2022

Yet another fun night in San Diego C++ Meetup (sdcppmu).

Recording can be found in our sdcppmu Youtube channel.

sdcppmu #42

Here is the agenda link:

https://www.meetup.com/san-diego-cpp/events/288596469/

We had quiz, C++ book which is https://www.amazon.com/Template-Metaprogramming-everything-templates-metaprogramming/dp/1803243457

We also discussed life time extension in the context of C++11 range for loop.

One thing that we discovered during the meeting is MSVC non-conformance with binding RValue to a non const reference. See the twitter discussion here: https://twitter.com/kobi_ca/status/1573155334696628224?s=20&t=2LZMv2JdfxLcbE7piQ76tA

Enjoy the recording!

Kobi

San Diego C++ Meetup #41

Super fun evening in San Diego, America’s finest city with the finest programming language (C++, if you had any doubts).

We learned tons of stuff and we are ready to Rock’n Roll using C++ at work and … home!

What did we discuss tonight?
1. Goals we would like to achieve in San Diego C++ Meetup. We would like to make sure members learn new fun constructs in C++.
2. C++ Quiz – few fun questions.
3. Template Function specialization (Beginners-Intermediate).
4. Correct way to printf() – Using std::string_view with printf (Beginners).

San Diego C++ Meetup #40

Yet another fun evening in San Diego, America’s finest city with the finest programming language.

We discussed:

  1. Welcome slides – goals we would like to achieve in San Diego C++ Meetup
  2. C++ Quiz – few fun questions
  3. Going over C++ Stackoverflow posts
  4. unique_ptr, shared_ptr and std::initializer_list<>

San Diego C++ Meetup #39 Featuring Nick Ristuccia from JFrog and the Conan team!

From the Command Line, to Make, to CMake, to Conan By Nick Ristuccia from JFrog!

This session examines the layers of tooling used to produce C/C++ applications and make developers’ lives easier. Surveys say a major pain point facing C/C++ developers is long build times. One way to save time is to only re-build an artifact when a change occurs. Although the command line offers the precision of specifying what to build, doing this and tracking changes manually can quickly become a daunting and error-prone proposition. Make as a build system allows developers to specify and execute command-line statements depending on what file changes are detected. However, these statements may be particular to one compiler or operating system. CMake provides the missing flexibility for a makefile file. One CMake file can generate what’s needed for a variety of build systems, compilers, and operating systems. Another major pain point facing C/C++ developers is managing all the libraries needed by an application. Libraries provide the functionality programs need. But it gets tricky when libraries depend on other libraries that depend on other libraries in a spaghetti-like formation. The goal of Conan as a package manager is to alleviate this burden. ConanCenter, for example, features over 1000 recipes. The promise of a recipe is to untangle the spaghetti and list the dependencies for a given library.

Nick started in the video games industry, developing titles for console and mobile. Disappointed by the oppressive corporate feel of traditional technical training, Nick’s passion is to create more engaging and powerful learning experiences through game-based learning and other playful techniques. As a Curriculum Developer at Oracle, he focused on Java programming and certification. As a Developer Advocate at JFrog, his focus is on C++, Conan, and other JFrog technologies.

Recording:

San Diego C++ Meetup #38 Featuring Amir Kirsh from Incredibuild

Meetup session May 24 20212

Six ways for implementing max: a walk through API design, dangling references and C++20 constraints

Abstract:
API design in C++ is harder than in other languages, as the lifetime of the arguments and return value shall be considered carefully. While it gives programmers the full power in expressing their intent, it raises all sorts of concerns that should be considered. In this talk we would analyze a very simple function: max, we would see that selecting the proper API is not as simple as it may seem and discuss several alternatives. The discussion would take us through lvalue, rvalue and forwarding references, the rules of moving from a local, variadic templates design, the differences between returning auto and decltype(auto) and C++20 constraints.

Bio:
Amir Kirsh is a C++ lecturer at the Academic College of Tel-Aviv-Yaffo and Dev Advocate at Incredibuild. He is also the Co-organizer of Core C++ conference and a member of the Israeli ISO C++ NB.

Meeting event: https://www.meetup.com/San-Diego-CPP/events/285561768/

Recording:

My Best C++11, 14 and 17 Features

From the 37th San Diego C++ Meetup:

Recently I was hosted twice in cppcast podcast with Rob and Jason. I mentioned how using C++17 makes it easy to develop Modern C++ code. I will go over various features that are proven to work well. We built a software with no memory issues, no UBs etc… – the name of the talk is: “My best C++11,14 and 17 features that helped me write a better code”. (Beginners to Intermediate)

Yacob (Kobi) Cohen-Arazi

36th San Diego C++ Meetup

As always good times at the SDCPPM (also on Twitter)! Learned something new last night and met great people! Thanks again for organizing this Kobi!

For those new to this Meetup: we meet once a month for few hours to discuss C++ features, techniques, questions asked no the net, and more. Sometimes we have guest speakers give presentations on various topics (Conan Package Manager, C++20 Concepts to name a few). Join us! Join to listen in, chat and exchange your experience coding in C++, or be a speaker and teach us something cool! All backgrounds and experience levels welcome!

Agenda

  1. Welcome slides – goals we would like to achieve in San Diego C++ Meetup
  2. C++ quiz
  3. Welcome slides – goals we would like to achieve in San Diego C++ Meetup
  4. C++ quiz (Beginners to Intermediate)
  5. Supporting creators – introducing Patreon (All levels)
  6. Book of the Month – Practical C++ Design(2nd edition), From Programming to Architecture By Adam B. Singer (All levels)
  7. Stackoverflow discussion – Is there a way to pass auto as an argument in C++? (Beginners to Intermediate)
  8. r/cpp_questions – One function – multiple datatypes? (Beginners)
  9. Discuss few slides from walletfox website (Beginners to Intermediate)
  10. My best C++11,14 and 17 features that helped me write a better code (Beginners to Intermediate)

32nd San Diego C++ Meetup

Agenda:

1. Welcome slides – goals we would like to achieve in San Diego C++ Meetup
2. C++ quiz
3. Do you know what your std::remove(_if) does?
4. Stackoverflow questions and discussions
4a. How does the C++ compiler evaluate recursive constexpr functions so quickly?
4b. How to check if int32_t number can fit in int8_t and int16_t?
5. Quora question discussion – Arrays, references and pointers
6. Book – Large-Scale C++ Volume I: Process and Architecture by John Lakos
7. Discuss few slides from walletfox website
8. Talk – My Quest for a Quick QuickSort

Event link on Meetup.


= delete; // not just for special member functions

During the 29th San Diego C++ Meetup fellow C++ enthusiast and contributor to my blog, Kobi, brought up something interesting about deleted functions and I wanted to share this little gem with you…

To my surprise the = delete; postfix can be applied not only to special member functions like constructors or assignment operators, but to any free standing or member function!

Why would you want such sorcery you ask? Imagine you have a function like this:

void foo(void*) {}

On its own foo can be called with a pointer to any type without the need for an explicit cast:

foo(new int); // LEGAL C++

If we want to disable the implicit pointer conversions we can do so by deleting all other overloads:

template<typename T> void foo(T*) = delete;

Or the short and sweet C++20 syntax:

void foo(auto*) = delete;

To cast a wider net and delete all overloads regardless of the type and number of parameters:

template<typename ...Ts> void foo(Ts&&...) = delete;

Kobi found this on stack overflow of course 🙂


Example program:
delete.cpp


San Diego C++ Meetup

San Diego C++ Meetup 25th meeting featuring JFrog and Conan!

https://www.meetup.com/San-Diego-CPP/
https://www.meetup.com/San-Diego-CPP/events/277115020/

Agenda

Welcome slides – goals we would like to achieve in San Diego C++ Meetup
This meeting – Hosting JFrog: Conan Package Manager for C++ in Practice

If time permits:
* Shout Out to a great C++ blog – “Vorbrodt’s C++ Blog”
* 3 cppquiz questions
* 2 years of San Diego C++ Books recommendations – a recap!
* An additional New book for this month – “Ace the Trading Systems Developer Interview” With an example of one of the questions

Featuring:
* Conan Package Manager for C++ in Practice

The Conan package manager for C++ is useful in both simple and advanced development environments. Join the Conan team to see it in action, with a simple demo using OSS libraries and tools from ConanCenter, and a more complete demo showing how to create and upload a package including different binaries for different platforms to a private repository. Also, learn about many other unique and innovative advanced Conan features along the way.

Jerry Wiltse Bio: Jerry is a member of the Conan development team, and has been dedicated to build engineering for C and C++ since 2016. He is an avid open-source enthusiast but also deeply focused on enterprise development environments. He is also the narrator and creator of the Conan learning track on the JFrog Academy.