San Diego C++ Meetup – Meeting #69

Hello all,

Summary of San Diego C++ Meetup – Meeting session number 69. Took place on December 10 2024.

This is the last session for 2024!

Event link can be found here.

Topics we covered:

  • Modern C++ Programming: A tutorial/training session by Federico Busato.
  • ADL and the  std::swap idiom: Including a mention of  std::ranges::swap(). The discussion covered ADL, anonymous namespaces, and the global namespace, highlighting the subtleties when mixing them.
  • Mapping a runtime value to compile time: More details on this topic are provided below.
  • Variadic templates and fold expressions: Exploring techniques to eliminate duplicate code.
  • Lightning talk by GC: GC’s slide deck on “Stateless Allocators and Memory Resources” can be found here.

How can I map a runtime value to a compile-time value?

This was the main topic. The idea was as follows: given something like:

How can I take a runtime value n and pass it to the function? func<n> would not work since n is not a compile-time value!

The original problem to solve was the following (values are just for the example, it could be anything): for a range [0…5] map to 128, [6…10] map to 256, [11…max] map to 512.

People attending the session immediately suggested using an array/map/hash-map (aka unordered_map). I did not have any material to demonstrate anything with these elements, but before I show the solution presented in the session, let’s try to solve it first with the unordered_map type (since people claim it has O(1) efficiency).

This obviously cannot work. The compiler will complain: “call to non-‘constexpr’ function ’ … “. CE link.

So, what about trying to embed some constants in the “value” part of the unordered_map?

So the problem is, what do we place instead of the ????

What is the actual type? Even if I use integral_constant, which can be used in constant expression contexts, I don’t have a way to provide the type. std::integral_constant<std::size_t, 128> is different from std::integral_constant<std::size_t, 256>.

The next attempt was using Jason Turner’s idea of a “constexpr map.” For reference, here is Jason’s C++ Weekly:

Here is a link to CE trying to get it working. But again, this only works with compile-time inputs. The requirement was runtime inputs!

Let’s take a look at the actual implementation presented in the session. For this, you need to be familiar with:

  • std::lower_bound: Given the values [5, 10, max] and a needle, we need lower_bound to find the correct item among the values. Note that lower_bound is not a must here; we could also use a linear search like find/ find_if.
  • std::integral_constant<>: An important ingredient in the overall solution. This is where we can actually pass a constant to the template NTTP!
  • std::variant<> + std::visit() + overloaded{} idiom: For more information, check out cppreference and cppstories.com, which has tons of great articles on these.

Here is a CE link to the overall solution. Thanks to GC for suggesting constexpr on the return of lower_bound when working with C++20! My solution needed to compile with C++17.

Here is a simple explanation of what’s going on:

We have an array of variants. The std::variant is of type:

Think of it as mapping some number to std::integral_constant<size_t, some_value>.

Given a needle, find the index in the array of variants. We use:

  • lower_bound
  • overloaded{} idiom
  • std::visit to extract the first value in the pair<>

Once we have the result of lower_bound, given the iterator return value, we can compute the index using std::distance(base, iter).

Invoke a call that takes the index. We use the index with the array: arr[n].

Since arr[n] yield a variant type, we can run std::visit, getting the value and extracting the integral_constant, which is the second type in the pair.

Now, we can pass it to an NTTP by calling func<p.second()>(). The magic happens with integral_constant<>! It can be used as an NTTP!

That’s it for this session. I bet there are some other cool ways to achieve something similar!

Thank you for reading!

Kobi

San Diego C++ Meetup #68 – The Art of Writing Efficient Programs – design choices for Performance (Nov 13 2024)

Hello all!

Here is the summary of the last San Diego C++ Meetup, virtual meeting, took place on Wednesday, Nov 13 2024.

Link to the meetup event page here.

Recording uploaded to the San Diego C++ Meetup channel (sdcppmu)

The agenda:

  1. cppquiz fun – C++ Quiz – 297 – std::async, future .wait() vs .get()
  2. Recommending YT channel – “C++Next by Alex Dathskovsky”
  3. The Art of Writing Efficient Programs – chapter 12 – Design choices for Performance.
  4. Tip: transparent comparator/operators.

More details:

First, Alex’s YT channel mentioned above is something you should checkout. It’s fun, short episodes and packed with good information.

We mentioned few Design choices as mentioned in Fedor G. Pikus book: “The Art of Writing Efficient Programs: An advanced programmer’s guide to efficient hardware utilization and compiler optimizations using C++ examples”:

Chapter 12 discuss “Design for Performance”. We mentioned:

  1. Choosing APIs for performance. operator[] vs iterator interface, std::deque as an example to have better performance using iterator vs operator[].
  2. Using std::set<> in conjunction with std::vector<>, using member vs non-member functions.
  3. Lock vs non-lock interfaces, runtime vs Template, policy based classes. Also, using decorators (inheritance in this case).
  4. Redundant get-ters/set-ters and when these are actually could be useful.
  5. 13:34 – we mentioned std::span<>! 🙂
  • Transparent operator – using std::less<> which is like std::less<void>, the benefit of using it, how can it save you from debugging subtle bugs.

This is for this session, thank you for reading!

Kobi

San Diego C++ Meetup – Data Structures and Algorithms with C++ STL (#67)

Hello all,

We had a fun evening on Tuesday October 15th, discussing C++ STL, Data structure and various modern techniques. The inspiration coming from a recently published book by John Farrier:

recording:

San Diego C++ Meetup recording

Event page here.

Hey everyone,

Here’s a quick recap of our discussion:

We kicked things off with cppquiz 167. It’s a tough one but packed with important modern C++ concepts like RValue, LValue, and what happens when you pass an RValue to a function. We also touched on std::move and std::forward. Give it a shot and make sure to read the explanation!

C++ Data Structures and STL:

  • We talked about getters and exposing internal data structures from your class. We also introduced alternatives like iterators and discussed how to write them in different ways.

SFINAE and std::void_t:

  • We covered how SFINAE tweaks the compiler’s function candidate list, mentioned C++20 concepts, and how std::void_t can help. We also discussed type_traits, if constexpr, static_assert(), declval, and how cppinsights.io can be useful.

Allocator Interface:

  • How to use it with STL containers.

std::span<> Example:

  • We went through an example of std::span<>.

Gotchas:

  • Comparing two strings or comparing pointers? Check out the last 2-3 minutes of the recording for the full details!

Book Recommendation:

  • I liked the book, though it was a bit basic for me. However, I think it’s great for newcomers to the language/STL to get familiar with various containers, algorithms, and other parts of the Standard Template Library.

Thanks for reading!

Kobi

San Diego C++ Meetup #66 – Modern CMake for C++

Hello everyone,

Last Tuesday (September 17, 2024), we gathered for the 66th meeting of The San Diego C++ Meetup.

The topic was CMake. Yes, CMake can be fun sometimes! 😊

The inspiration for this session came from the relatively new 2nd edition of “Modern CMake for C++” by Rafal Swidzinski.

First off, the book is fantastic! It’s packed with valuable material that can make your life easier if your build system is CMake. Despite considering myself quite knowledgeable about CMake, I learned a lot from it.

This wasn’t my first time giving a talk on CMake. I’ve had several opportunities in the past, ranging from one-hour to multi-hour sessions. It always feels like there’s so much to cover that even 1, 2, or 4 hours isn’t enough to touch on every aspect of CMake. CMake is extensive, and it’s crucial to understand and use it well. Otherwise, your build system can become difficult to improve, extend, and maintain, leading to a lot of frustration.

When discussing CMake (or any topic in a C++ session), my goal is for everyone to learn something new—at least one thing!

The meetup page link: here

And the recording:

San Diego C++ Meetup recording

BTW – We had an excellent session on July 11, 2023, with Alex Reinking, titled “Modern CMake Best Practices for Library Authors” at the San Diego C++ Meetup. It’s definitely worth watching!

Summary of our discussion:

  • Introduction to the book.
  • CMake’s popularity (based on 2023 surveys).
  • Overview of CMake: its purpose and stages (configuration, generation, and build).
  • Simple CMake files and FetchContent.
  • Generators: what they are and how to write agnostic command lines that work with any generator.
  • CMake Cache file (CMakeCache.txt): using the --force option, cache variables, and debugging/tracing CMake build generation with options like --trace, --log-context, --trace-expand, and --debug-output.
  • Cleaning with the --clean-first option.
  • Targets: what they are and how to build them.
  • Installation: a high-level overview (there’s much more to explore here).
  • Running CMake as a script with the -P option.
  • Brief mentions of CTest/CPack and other tools in the CMake suite.
  • CMakeConfigureLog.yaml (introduced in version 3.26) for advanced debugging of the configure stage.
  • Utility modules included with the CMake package, and projects like cmake-awesome and cmake-modules.
  • Find modules.
  • A slide on important elements of the CMake language (the book has an excellent chapter on this).
  • CLion and CMake: debugging CMake with CLion.

Additional topics covered in the book:

  • Generator expressions
  • Dependency graph and how to print it
  • CMake presets
  • Program analysis tools
  • C++20 modules
  • Testing frameworks
  • Generating documentation

Many thanks to Packtpub for their support providing me the material to review!

That’s it for this session!

Happy CMake-ing!

Kobi

San Diego C++ Meetup #65

Hello everyone,

Super late in writing this summary, can’t believe we are 1 week past the session. I’ve been super busy at work and with Family.

What did we have on the Agenda:

  1. Guo Ci, our guest speaker, presented 2 techniques that are being used to optimize C++ code. The first is doing binary searches with equal_range (in std::ranges and std) and the second is customizing the three-way comparison operator (<=>). Slides: guoci SDCPPMU presentation
  • bio: Guo Ci. Guo is a bioinformatician at the University of Michigan, working in labs doing proteomics and genomics research.
  1. Adding Default Constructor using =default; to your class type.

sdcppmu Youtube recording:

Event page from meetup.com

Summary of the discussions:

  1. From Guo Ci talk – demonstrated techniques related to spaceship/comparison operator
    • Changing order of the non-static data members, changes the default operator<=>
    • usage of std::tie and restoring the required order
    • Transformation of the data members before comparison, using make_tuple and std::cref
    • While float provides partial_ordering, what if we want strong_order?
    • Caveats related to std::tuple’s <=>
    • Synth-three-way
  2. Second item from Guo Ci talk – A more generic equal_range
    • An optimized way to reduce algorithm complexity, running on a sorted array
    • Showed benchmarking comparisons
    • Overview from the slides:

Next part of the meeting talked about “Adding Default Constructor using =default; to your class type”. We compared aggregate changes between 17 and 20. For 20, an aggregate cannot have “user-declared or inherited constructors”. 17 could. So 20 is stricter. Examples in the slides from godbolt.

The last part of the session talked about top level const in function deceleration, why clang-tidy complains and the rational behind it.

Thanks for reading!

Kobi

San Diego C++ Meetup #64 – July 16 2024

Hello all!

Summary of the recent San Diego C++ meetup session, took place Tue, July 16 2024 5PM Pacific Time.

Agenda in this meeting:

  1. New C++ Book – C++ Brain Teasers! – by Anders Schau Knatten – image above.
  2. Discussion on Throwing destructors
  3. Yet another hard to find(?) bug

Meetup event page here.

Recording can be found here:

San Diego C++ #64 Meetup recording

Details:

  1. I introduce “C++ Brain Teasers” book by Anders Schau Knatten. The PragProg page has 3 items that can be accessed. Puzzles 2,3,14. We went over each and discussed it. Super fun book, very recommended! Amazon link if you’d like also the colored printed book.
  2. Throwing destructors Discussion – noexcept and C++11, is it a good idea to throw from destructors? what happens when you aggregate a type with “noexcept(false)” ? How to workaround such issue? What do Core Guidelines say? It triggered lots of good discussions.
  3. And finally, a very hard to find(?) bug related to temporaries and lifetime. I saw it in production code few times in the past few months and wanted to share it with the group. Lots of good discussions here as well!

That’s it for July 2024. Working on the agenda for the next meeting!

Thank you for reading!

Kobi

100 C++ Mistakes and How to Avoid Them – by Rich Yonts – San Diego C++ Meetup #63

This month we hosted Rich Yonts, the author of a Manning publication title (MEAP/Beta) – 100 C++ Mistakes and How to Avoid Them

The recording can be found in our San Diego C++ Meetup channel:

San Diego C++ Meetup #63

The meetup even link can be found here.

About Rich Yonts:

Rich Yonts is a Senior Software Engineer at Teradata and a long-time software engineer using C++, Java, and Python. Rich held a number of technical and leadership roles during his many years at IBM and Sony. As an assistant professor, he has dealt with questions and issues of undergraduate and graduate students learning programming. He has deep experience on large code bases and considers himself both a student and a teacher of C++.

Rich cherry-picked few examples from the book and presented to the group.

Here is the summary of the topics:

  1. The challenges when dealing with old codebase in various companies. i.e. dealing with 98/03 and not beyond that.
  2. Narrowing values, uniform initialization to detect narrowing.
  3. Referring to an uninitialized data member and UB.
  4. Post vs pre increment of type instances.
  5. The fit fall of using setter when class invariant is not checked/violated and how to solve it.
  6. Shallow vs deep copy and how to ensure a deep copy with copy constructor and op=.
  7. The benefit of using the “override” keyword.
  8. Using “=delete” keyword to disable a specific function, vs the old 98/03 “method”.
  9. Variadic Templates.
  10. Using sprintf vs iostream vs std::format.

That’s it for June 2024 session.

Thank you for reading!

Kobi

San Diego C++ Meetup #62

Introducing: “Modern C++ Programming Cookbook” – Master modern C++ including the latest features of C++23 with 140+ practical recipes, Third Edition – By Marius Bancila

Meetup session page: san-diego-cpp

Recording (sdcppmu Youtube Channel):

San Diego C++ meetup #62

I continued using “google meet” where I can share the slides directly from my google drive, record a session, chat with attendances and it works beautifully!

Recent session introduced Marius’ newly published book which is really a good one (as usual :)!

The session started with a warm up, c++quiz Question #287. A bit of a tricky one. If you cannot remember the exact constructor diffs of std::string, you are out of luck 🙁

The main session/talk was on “Implementing the higher-order functions map and fold“. Taken from chapter 3 from the book (just part of the chapter). Oh – and we had a raffle of 3 ebooks!

Minutes:

  1. Map, fold implementation.
  2. Various overloads to support different containers that might behave a bit differently in the way we iterate over the items (std::queue<> is one example).
  3. The difference between the presented fold() and “C++17 fold expressions”.
  4. Composing(composing(composing(functions))) – with many examples.
  5. Fold left/right functions.
  6. Functions as first class citizens. Returning functions and composing a chain of functions.
  7. Overload operator* as a syntactic sugar when composing.

That’s it for this session. Next session should be a really nice one. Working on bringing a new speaker with an interesting topic!

Take care,

Kobi

San Diego C++ Meetup – #61 Apr 16 2024

Hello all,

Yet another summary of our latest session of San Diego C++ Meetup. America’s finest city endorsing America’s favorite language 😉

The meetup page can be found here.

San Diego C++ Meetup #61 recording.

Agenda summary

  1. C++ quiz – Arrays and copies during range-for-loop.
  2. The right auto/auto* – When using auto, and the deduced type is pointer, should we use auto? or auto*. Spoiler – use auto*. But why? This items takes us through the reasoning behind it. Hint – it helps readability and correctness especially with const involved.
  3. Does a default virtual destructor prevent compiler-generated move operations? – Fascinating journey investigating the implication of user defined destructor and move operation, talking about Howard’s famous table. Then – what does it mean in base classes when =default is used for virtual destructor. And finally, what is the best way to understand whether a specific class type is move constructible. Hint – it’s not that easy and straightforward, but we introduced a neat trick.
  4. And finall In-Place Construction for std::any, std::variant and std::optional – this item was inspired by Bartłomiej Filipek C++ Stories blog post.

That’s it for this session. Thank you for reading!

Kobi

San Diego C++ Meetup #60 – March 12 2024

Hello everyone,

San Diego C++ Meetup – 5 Years! 60 meetings! took place Tuesday March 12th 2024.

Here is the link to the meetup.com page.

Recently, I’m moving away from Windows+Teams.

Last session, we used Zoom utilizing Andreas Fertig’s account. Andreas was our guest speaker on Feb 2024.

For March, I tried using Google Meet but I missed the fact that I needed premium “GoogleOne” account and it was too late to add it. I have it now for next sessions. Hence the recording did not work.

No worries, after the meeting I spent ~20 minutes to record myself going over the agenda so we have it on record. Here is the recap:

San Diego C++ meetup session #60 – Recap post session recording

Our Agenda:

1. C++ Quiz
2. What is IILE/IIFE ? Deep dive to some of immediate invocation tricks.
3. Strongly typed syntax – How can we achieve a better, less error prone code? NamedType to the rescue!

More details:

C++Quiz – Question 126 was about Lookup rules. Question 29 was about invoking virtual functions in constructors and destructors (Don’t!), and finally Question 312 was about class/struct inheritance and access specifiers – “would this compile?”

The second part was about Immediately Invoked Lambda/Function Expression(IILE/IIFE). Few tricks, why is it useful, should we use std::invoke and benchmarks using Bartek’s cppstroies blog post.

And finally, we discussed C++ and strong types, user defined string literals and finalized with NamedTyped library example.

That’s if for the 60th session update, thank you for reading!

Kobi

Exploring Polymorphism in C++ – San Diego C++ Meetup Feb 2024

Hello everyone,

We had a special guest speaker on Tuesday, Feb 20th 2024. Andreas Fertig!

This is not Andreas’ first appearance in our Meetup and I was super happy to host him again!

This session went over an interesting and extremely useful information – Runtime vs Compile time polymorphism.

The event page can be found here.

Recording, as usual can be found in the San Diego C++ Meetup Youtube channel.

Exploring Polymorphism in C++: Run-time vs. Compile-time by Andreas Fertig – San Diego C++ meetup

Presentation material can be found in our dropbox location (join the meetup to gain access).

Summary of the material discussed:

  1. Cost of runtime polymorphism.
  2. CRTP as an alternative, lower runtime cost alternative.
  3. Policy based design.
  4. Example of policy – std::unique_ptr and the deleter policy.
  5. std::sort and the sorting policy.
  6. Another example of the Policy based idiom, checked array boundaries with multiple types of handling errors – all with Policy design.

That’s it for this month!

Next time, it’d be our #60 session. Yes! 5 years of San Diego C++ Meetup. We have over 1650 members. We started off on March 2019, with around 70 members!

Thanks for reading,

Kobi

San Diego C++ Meetup #58 – Modern C++ Design, chapter 2

Hello all,

Quick summary on a great Tuesday night on Jan 16 where we went over chapter 2 of Andrei’s A. book – Modern C++ design.

meetup-event link

Recording:

San Diego C++ Meetup sdcppmu Youtube recording

Here is the overall summary of what we went over in this session:

  1. Compile time assertions
  2. Partial template specialization.
  3. Local classes.
  4. Map integral constants to types. Compile time dispatch based on numeric values. Boolean conditions.
  5. Type to type mapping. For overloading and function template partial specialization.
  6. Type selection, based on compile time boolean conditions.
  7. Detect convertibilities and inheritance at compile time.
  8. TypeInfo wrapper over type_info. Value semantic and ordering comparisons.
  9. NullType, EmptyType placeholders classes.
  10. The last part – “TypeTraits template to offer multiple general purpose traits to help us tailor the code to specific categories of types” – as I expected – we did not have time since we were already overtime (around 1hr and 10 mins) but feel free to go over the last 4-5 slides with the type_info and the overall type traits class.

Overall, in the past 2 sessions (Dec 2023, Jan 2024) we showed the power of Templates with the great help of Andrei’s book. As I mentioned, the book is unique and even after 20+ years, still ranked top IMO. The first 2 chapters are the basic building blocks, the pillars for a better understanding of Generic programming. Worth investing time and reading it.

Thank you!

Kobi

San-Diego C++ Meetup #57 “What can Class Template Policy Design do for your codebase?”

Hello all,

Short summary on the previous San Diego C++ meetup, the last one for 2023.

It took place on December 12th 2023.

The topic for the meetup was Class Template Policy based design. All based on the first chapter of Andrei’s Modern C++ Design book from 2001.

Here is a link to the meetup event.

Recording on our sdcppmu channel here:

Policy Based Class Design recording on sdcppmu YT channel

The talk goes over the first chapter of Andrei’s book highlighting the huge advantage of using this technique in your code. And in particular, it described the following items:

  1. Templates, specialization of Class Templates, functions, what is template-template parameters.
  2. Examples of how Policy design can improve readability, flexibility of your design.
  3. Static vs Dynamic dispatch/polymorphism.
  4. How to mix different, orthogonal policies
  5. How to mix policies with some dependencies (though this is not a recommended approach).
  6. Enrichment APIs and how Templates do not instantiate functions unless being used.
  7. Customizing structure with Policy Classes.
  8. Examples of Policy classes in the wild. ACE library, Standard library.

Next month will discuss chapter 2 that describes more of the important Template techniques.

That’s if for now.

Have a great holidays, hoping for a better 2024!

Kobi

San Diego C++ Meetup #56 hosting Šimon Tóth – “Patterns of interview solutions”

Hello all,

This post is about the latest San Diego C++ Meetup session, held on Tuesday, November 14 2023. It was a virtual meeting, recorded and uploaded to the sdcppmu Youtube channel. Here is the recording:

San Diego C++ Meetup #56 hosting Šimon Tóth – “Patterns of interview solutions”

Here is a link to the event on meetup.com

This time, we hosted Šimon Tóth who gave a wonderful talk named “Patterns of interview solutions”.

A bit on Šimon:

He can be found on the following Social media: linkedinhachyderm.iosubstackmedium and github.com .

Books on leanpub.com:

Summary of the content presented

The talk is divided to 2 parts. First part presented the available algorithms in C++. Including some from the ranges library. Total of 126 algorithms were bunched into categories and Šimon quickly went over the benefits of each category with some examples.

The second part presented couple interview-like questions and their respective Modern C++ solutions:

  1. Sum of distances to all nodes – Šimon demonstrated solving a problem while looking at it from different persoective.
  2. Longest palindromic substring – showing few ways to improve your algorithms using different methods.

In all of the above, Šimon is using ranges, algorithms and Modern C++ syntax and mechanism.

Hope you enjoy the recording!

Take care,

Kobi

Let’s embed it with C++! – San Diego Meetup #55 October 30th 2023

Hello everyone!

As usual, I’m providing a short summary to the previously held San Diego C++ Meetup session.

But before this, I’d like to promote the next, upcoming one – we are hosting Šimon Tóth that will present his talk – “Patterns of interview solutions“. This will happen on Tuesday, November 14th, 930am Pacific time. Looking forward!

The recording of the October meetup, named “Let’s embed it with C++” can be found here:

“Let’s embed it with C++” recording on youtube, sdcppmu channel.

Here, you can find the past event Link on the meetup.com page.

The original meetup session was scheduled to October 10th but I had an emergency travel to Israel supporting my family as I lost my nephew during the first few hours of October 7th war.

So what did we discussed about during this 1:30 hrs of this session?

The idea was to provide an overview, mostly for beginners to intermediate levels on how can we use Modern C++ features in Embedded environment. The talk was heavily inspired by this excellent book By Christopher Kormanyos:

I also started by mentioning 2 great talks. One from Dan Saks, cppcon2016 – extern c: Talking to C programmers about C++, and the second one from cppcon2022 – Erik Rainey, “Using C++14 in an Embedded ‘SuperLoop’ Firmware”.

High level topics discussed:

  • Using class types for encapsulations, organization of code, as well as namespaces
  • (No)Overhead demonstrated using various features like class types, constexpr, using templates to improve code generation.
  • Showing various code/options side by side using Compiler Explorer and the new CLion feature to “Show assembly” (what a great feature JetBrains!).
  • Discussing the subset of C++ that is useful for embedded. The various trade-offs using STL(Standard Template Library).
  • Using integral macros from “cstdint”. Thinking about portability of your code working with various OS and compiler vendors.
  • static_asserts, limits for more compile time evaluation.
  • Using std::array as a replacement to the C array.
  • Why STL algorithms are a good fit for your programs? How do they compare to raw loops, runtime speed and generated code.
  • The advantage of using User Defined string literals (one of my favorite features of the language!). How does it contribute to strongly typed elements with zero cost abstraction!
  • C++ Core guidelines, using std::span<> (and gsl:: library if you are working on <20 standard).
  • Demonstrating template integer sequences with Modern C++.

Conclusion is that C++ is more than suitable for embedded. You need to know how to use the language correctly, take advantage of templates when applicable, know STL well to avoid pitfalls!

That’s it for now. Hope this session is useful for various people at least as a good introductory session to various Modern C++ features.

Until next time, stay safe,

Kobi

Introduction to Package Management with Conan 2.0 – by Chris McArthur – JFrog

Hello,

We had another great night in San Diego C++ Meetup, the 54th meeting (Sep 12 2023). This time hosting JFrog and specifically having Chris McArthur presenting Conan 2.0.

The session was super informative and easy enough that even if you’re hearing about Conan for the first time, you’d be able to pick it up quickly and start using it in your projects.

The meetup page for this event can be found here.

San Diego C++ meetup #54 – Introduction to Package Management with Conan 2.0 – by Chris McArthur – JFrog

So what did we learn?

  1. Describing what is Conan, how does it solve the gap in C++ wrt package management.
  2. Demo – building a small application pulling in dependencies using Conan.
    • spdlog was used in the first demo
  3. What is conanfile.txt, how to bring in dependencies, installing and integrating into CMake files.
  4. Dependencies graph and the transitive trait of it.
  5. Using VSCode as IDE. Clion has also newer version of their Conan plugin that is worth looking at.
  6. More demos, with more packages, demonstrating different versioning, local caching of the packages. All working flawlessly.
    • glad
    • glfw
    • tinycthread
    • linmath
  7. Using presets
  8. How to use test_requires packages – e.g. bringing gtest package for build and testing – but not for production distribution.
  9. What is Conan lock-file and how to utilize it. CI, Reproducible builds.
  10. Picking up packages from conan-center/conan.io
  11. Writing a simple conanfile.py to distribute an app as a Conan package. (Conan Recipe).
  12. Introducing Conan extension.
  13. Developing Packages Locally.
  14. Resources on the web – ACCU talks, Conan blog, and future talks in Cppcon2023.

Thanks again for Qualcomm for paying the meetup fees, Charles Bergan, for supporting this group.

Thank you for reading!

Kobi

San Diego C++ Meetup #53 – notes

Hello all!

We had a great night on Tuesday August 15. The San Diego C++ meetup #53 took place.

Here is the recording

San Diego C++ Meetup #53 recording

Here is a short summary of the topics and discussions we went through:

  1. Introducing the next month session – JFRog will introduce Conan 2.0. Chris McArthur will present it on September the 12th. Here is a link to the event on meetup.
  2. I introduced the new, 3rd edition of range-v3 booklet. You can find it here. This is by far one of the best and fun resource to use for learning range-v3. The material, content and quality is just premium. Run, don’t walk and purchase it. I love the printed edition. It’s a piece of art! In the meeting we went though the FizzBuzz example that can be found on walletfox website itself.
  3. Next, cppquiz #354 . std::exit() related.
  4. User Type categories – we discussed “Trivial and standard layout“, explaining the differences and why it is important to know about these categories.
  5. And finally, I presented a topic which I really like and close to my heart – properly writing multi-threading code. Well – there are many many things not mentioned in this 40 minute talk. But the goal was to bring some awareness on bad patterns or practices vs better, safer and maintainable patterns. We mentioned associating Mutex to its controller data, showed how Rust is doing it (in one slide), and eventually, went over POSA2Thread Safe Interface“.

Thank you for reading!

See you next time!

Kobi

Modern CMake Best Practices for Library Authors by Alex Reinking – San Diego C++ Meetup #52

Hello everyone,

I’ve been super busy at work hence the delay in this blog post that summarizes our 52nd San Diego C++ Meetup.

This time, we hosted a Qualcommer co-worker – Alex Reinking.

Alex is very knowledgeable in many fields and in specific, he likes build systems. We had an offline chat before he submitted the talk for the July session. We talked about CMake, FetchContent, Package managers and it was very clear to me that Alex would be great speaker in our meetup.

Here is the recording:

San Diego C++ Meetup recording – Alex Reinking talking about Modern CMake

Alex started by taking us through the general idea of CMake as a build generator and also mentioned its popularity in the community.

Few important bullet points and take away:

  1. Under the hood, Package managers do more that you realize. Like patching code and similar.
  2. As a library, we would like to provide the users the best experience when using our library with CMake.
  3. Alex has a very nice demo posted here: alexreinking/sdcppmu-diffuse. Building on Linux and MSVC with Emscripten targeting WebAssembly(Linux)/SDL(Windows).
  4. Always use the latest CMake. This is something that I like in CLion which is usually bundled with the latest, or almost latest CMake.
  5. CMake’s find_package() is the one true way to locate dependencies.
  6. FetchContent is nice but it will clutter your CMake “env”, unless upstream project is written well enough.
  7. Halide (see Alex’s Bio) has CMake helper functions like “add_halide_generator“, “add_halide_library“) – a generator that must run on the host system, even when cross compilation is involved.
  8. Alex walks us through the path of getting your library “FetchContent” friendly for consumers.
  9. Interesting discussion on Why we should not create 2 targets (shared and static for example).
  10. Why not GLOB for sources.
  11. Discussion on what to place and NOT to place in your CMakeLists.txt. For example – compile options – probably should go into Presets.
  12. Other CMake related constructs that were new to me: ALIAS for add-Library, BASE_DIRS + target_sources, GenerateExportHeader, CMakeDependentOption, CMakePackageConfigHelpers, configure_package_config_file, write_basic_package_version_file.

More information can be found in the recording.

Thank you!

Kobi


Abstract
In this talk, we will discuss the best practices as of the latest CMake version for writing C and C++ libraries that are easy for everyone to consume. We will build a toy application that demonstrates switching between static and shared library types, dependency management, creating accurate CMake config packages, and cross-compilation involving code generators. We will see how writing CMake lists that are minimal and declarative leads to more correct and maintainable builds.

Bio
Alex is a research scientist at Qualcomm Compiler Labs. He got his Ph.D. in Programming Languages from UC Berkeley in 2022. Since 2020, Alex has served as an open-source maintainer for Halide, a popular DSL for optimizing image and tensor processing; in this capacity, he has overhauled the build system, CI infrastructure, and the release process. Alex has contributed build system improvements to prominent open-source projects, including WABT, tinyxml2, and Herb Sutter’s cppfront, and has found and fixed large CMake bugs. His blog page: https://alexreinking.com

Link to the event

Ben Deane – San Diego C++ Meetup! June 13 2023 #51

Hello all,

It was yet another exciting night this time hosting Ben Deane!

His talk named “Applicative – the Forgotten Functional Pattern

Here is the recording:

Ben is a great speaker and he loves Functional programming 🙂

First – the Abstract:

Abstract

Monads get all the press. Functors are often presented as a prerequisite to monads. Applicative (functor) almost never gets mentioned. But it’s massively useful – to the point where a lot of the time when we think about a “monadic interface” what we really want is an applicative interface.
This talk will put applicative in the limelight, showing how it works and why it’s so powerful, with lots of examples grounded in code; there are no category theory diagrams in this talk. Attendees will come away with a solid understanding of the applicative pattern and its many uses. And as a byproduct, their opinions of monads will probably change too.
Optionals. Expected. Ranges. Futures. Parsing. Validation. Error Handling. Transforms. Functions themselves. These are all examples where thinking in terms of applicatives (and importantly, NOT just reaching for “a monadic interface”) helps us write simpler, more composable code. If you’re kind of fuzzy about functors and monads, what’s missing is probably the third piece of the puzzle: applicative.

Summary

I’d classify this talk as intermediate++. Ben mentioned many concepts like optional, ranges, Monads and std::expected just to name a few.

Throughout the talk, Ben presents Haskell syntax and C++. The Haskell part is easy to grok though if you are seeing this syntax for the first time, you might want to pause the recording and make sure you understand it since the sub-sequence slides will build on top of it. There are also some heavy generic programming slides that might need more attention when you go through the recording. No spoilers here on the conclusion and the take away (regarding Monads vs Applicative)

Overall I learned a ton from this talk and have some homework to go and explore more on this domain.

We have an incredible future ahead of us in terms of new syntax and new language and library capabilities.

I’d end with a meme 😉

About BEN DEANE

Principal Software Engineer at Intel
Ben has been programming in C++ for this whole millennium. He spent just over 20 years in the games industry working for companies like EA and Blizzard; many of the games he worked on used to be fondly remembered but now he’s accepted that they are probably mostly forgotten. After getting more interested in modern C++, in the teens he started giving internal company talks and then talks at various conferences, spreading ideas about types, algorithms and declarative and functional techniques. In 2018 he left the games industry and worked in finance for a short spell, writing high-frequency trading platforms using the most modern C++ that compilers could support. Now he is a Principal Software Engineer at Intel where he puts monads inside your CPU.

Thank you!

Kobi

San Diego C++ Meetup May 16 2023 – #50 – C++ Horizons by Bryce Adelstein Lelbach

Hello everyone!

Our San Diego C++ meetup 50th anniversary was celebrated hosting Bryce Adelstein Lelbach – a very known persona in the C++ community and the chair of the Standard C++ Library Evolution group.

Bryce gave a talk on C++ future, cutting edge features. Here is the list of the 3 items presented.

  • Reflection/injection – facilities for extracting information from the program, performing compile-time computations based on that information, and injecting new program entities based on those computations.
  • Pattern matching – a new expressive selection mechanism that matches values against patterns and binds variables when matches are successful.
  • Senders – a framework for asynchronous programming that enables us to write generic code that can run on any type of execution resource, from a single thread to a cluster of GPUs.

Bryce believes that in the next decade, the above three major new C++ features will reshape how we write C++ code. This came with a lot of very interesting examples.

Here is the recording in San Diego C++ Meetup’s YouTube channel:

Bryce Bio:

Bryce Adelstein Lelbach has spent over a decade developing programming languages and software libraries. He is a Principal Architect at NVIDIA, where he leads programming language standardization efforts and drives the technical roadmap for NVIDIA’s HPC and Quantum compilers and libraries.

Bryce is passionate about C++ and is one of the leaders of the C++ community. He is the chair of INCITS/PL22, the US standards committee for programming languages and the Standard C++ Library Evolution group. He also serves as editor for the INCITS Inclusive Terminology Guidelines.

Bryce served as the program chair for the C++Now and CppCon conferences for many years. On the C++ Committee, he has personally worked on concurrency primitives, parallel algorithms, executors, and multidimensional arrays. He is one of the founding developers of the HPX parallel runtime system.


This is for this month. Hope you’ll enjoy this excellent recording.

Kobi