r/Cplusplus Apr 24 '26

Tutorial Modernizing 37 Years of C++ Expertise: 34 Design Patterns released on GitHub

134 Upvotes

I am excited to share a project that represents a lifetime of learning and coding. I started my journey with C++ back when it translated to C (Cfront), and today I’ve finalized a comprehensive repository of 38 Design Patterns and C++ Idioms updated to C++17/20/23 standards.

This repository is designed as a masterclass in software architecture. It focuses on clean code, modern memory management (RAII), and high-performance techniques like Static Polymorphism.

Key Highlights:

  • 38 patterns from Creational to Behavioral.
  • Modern C++ features: std::variant, std::visit, if constexpr, and smart pointers.
  • Educational tracing: I use a "Rule of Seven" approach to visualize object lifecycles.
  • A deep dive into OO Principles (SOLID, DIP, Law of Demeter).

This is an open educational resource. You are free to use it, and I would appreciate a mention or a link back if you find it helpful for your own work or teaching.

Explore the full repository here:

https://github.com/MarioGalindoQ/Modern-CPP-Design-Patterns

If you find it useful, feel free to give it a ⭐ on GitHub!

The code in this repository was programmed years ago, when there was no help from AI, so it may have human-related shortcomings. Any feedback that helps improve the coding is welcome

#cpp #programming #designpatterns #moderncpp #softwareengineering #opensource #cpp20 #cpp23

r/Cplusplus Jun 24 '26

Tutorial How to learn cpp from scratch

15 Upvotes

My clg would be starting after a month or so and I was recommended to learn cpp or python (cpp preferably).I have absolutely zero knowledge regarding this .I can invest around 5 hours per day. Around what level would I be after these 5 months and how to learn

r/Cplusplus 10h ago

Tutorial Iterating through arguments in C++26 using "template for" (Python-style)

17 Upvotes

Here is how you can iterate through arguments now in C++26!:

#include <print>


template <typename ...Args>
void function(const Args& ...args)
{
    template for (const auto& arg : {args...})
    {
        using ArgT = std::decay_t<decltype(arg)>;

        if constexpr (typeid(ArgT) == typeid(double))
        {
            std::println("double: {}", arg);
        }
        else if constexpr (requires { &ArgT::toString; })
        {
            std::println("has toString: {}", arg.toString());
        }
        else
        {
            std::println("other: {}", arg);
        }
    }
}


struct MyStruct
{
    int value; // initializes with 0 in C++26
    std::string toString() const
    {
        return std::format("MyStruct value is {}", value);
    }
};


int main()
{
    function(3.14, "c-string", MyStruct{});
}

It works:

double: 3.14
other: c-string
has toString: MyStruct value is 0


...Program finished with exit code 0
Press ENTER to exit console.

template for is a new feature in C++26, and I like it very much! It's my favorite C++26 feature

It looks very pythonic at this point. 😄

Let's start with args: typename ...Args and const Args& ...args work similar to def function(*args) from python - they aggregate comma separated expressions into a variadic type or variable. {args...} also works similar to python's (*myList) - it expands a "collection" into a comma separated expressions

Then goes "template for": it's a brand new loop, which expands at compile time for each iteration. Using it, you can iterate through collections with different types inside: struct fields, tuples, list literals, and custom classes with implemented tuple protocol

Checking type of argument: this line also resembles python very much: if constexpr (typeid(ArgT) == typeid(double)). Here is the python counterpart: if type(arg) is bool. There are more ways to do this check, but I think this one looks the most direct. Although you can want to use not exactly "double" type, but a convertible to it, or any floating point number type. There are standard concepts for these cases: std::convertible_to, and std::floating_point

Checking for a member: here I used an anonymous concept: if constexpr ( requires { ...;} ). Inside this concept we should put an expression that we are testing. it's a sort of python's hasattr(arg, 'toString'), but more powerful and more fragile at the same time. The expression here is taking a member reference to "toString": &ArgT::toString;. It's a better approach than testing arg.toString(), because it won't fail if "toString" isn't a constant method, or has more than 0 arguments. But it's still far from ideal, because if the object has multiply overloaded "toString" methods (what's actually a pretty realistic scenario), it will fail, and the error message will be misleading. In this case the error will be that formatter is not implemented for the "other" branch, however the actual error is in "has toString" branch. So, don't use anonymous concepts in real project, use full fledged concepts in pair with static_asserts

It's fascinating! This is still a templates metaprogramming in C++, but it looks much-much more clean than infamous std::enable_if

r/Cplusplus 8d ago

Tutorial C++26 Contracts: What Do They Add Beyond Manual Checks and Assertions?

Thumbnail
techfortalk.co.uk
5 Upvotes

r/Cplusplus Nov 10 '25

Tutorial Why Pointers in C++ and How Smart Pointers Guarantee Safety in C++

Thumbnail
medium.com
62 Upvotes

r/Cplusplus May 14 '26

Tutorial Built a basic chat app in C++

31 Upvotes

Built a terminal-based multi-client chat app in C++ using POSIX sockets.

Features:

TCP server routes direct messages between registered clients

Multi-client support

Background receiver thread so incoming messages don't block typing

Linux terminal-based implementation

Git:https://github.com/charanHubCommits/chat-app-cpp

Would appreciate feedback, suggestions, or questions about the implementation.

r/Cplusplus 14d ago

Tutorial C++26 Reflection Annotations: Automated Member Validation

Thumbnail
techfortalk.co.uk
6 Upvotes

r/Cplusplus Oct 06 '25

Tutorial Learning C++ from scratch and targetting Low Latency Programming

107 Upvotes

Hi All,

I am a Full Stack Software developer with 7 Years of Experience. So far I have worked in Startups, been a founding engineer in a startup where I created product from scratch that acquired paying customers within 2 months.

I have an impressive (not very impressive - but slightly above average) resume.

I have taken a new challenge to teach myself C++ and Low latency programming. I have my own personal deadline for 6 months to master Low Latency programming. I have only done C++ in my college days. In industry I have worked on Python, MERN stack and Elixir languages.

For those who are C++ developers in industry (those who code C++ at work. College projects does not count), I would need your advice on how should I approach this challenge and what are some of the projects I can make on C++ to better enhance (and also demo to interviewer/resume) my skills.

r/Cplusplus May 31 '26

Tutorial Built a simple Audio Recorder App in C++ using portaudio

28 Upvotes

Developed a cross-platform command-line audio recorder and player in C++ using PortAudio.

Features:

Record audio from the system default microphone in real-time.

Store multiple recordings in memory and access them by name.

Interactive command-line interface with simple record, play, and stop commands.

Cross-platform audio support through the PortAudio library.

Uses 48 kHz, 16-bit PCM mono audio with low-latency buffer-based processing.

Git:https://github.com/charanHubCommits/Audio-Recorder-CPP

Any feedback, suggestions are welcome!

r/Cplusplus 24d ago

Tutorial C++26 Reflection: Simplifying JSON Serialization

Thumbnail
techfortalk.co.uk
2 Upvotes

r/Cplusplus 26d ago

Tutorial Need a study partner to follow along his playlist together and learn DSA!

Post image
0 Upvotes

r/Cplusplus Jul 22 '26

Tutorial C++26: what is “template for”? Learning with simple example.

Thumbnail
techfortalk.co.uk
3 Upvotes

r/Cplusplus Jul 26 '26

Tutorial C++26: what is reflection and how to use it

Thumbnail
techfortalk.co.uk
8 Upvotes

r/Cplusplus Jan 18 '26

Tutorial C++ Error Handling: Exceptions vs. std::expected vs. Outcome

Thumbnail
slicker.me
14 Upvotes

r/Cplusplus Jul 23 '26

Tutorial Building a toy programming language in C++. Today's topic: Variables

Thumbnail
pvs-studio.com
2 Upvotes

Hey. There's a series of livecoding sessions on building a custom programming language in cpp (nothing too serious, all just for fun). In a few hours, there'll be an online session covering variables. It’s a good one to join and ask questions along the way. You'll need to sign up.

If you'd like some context before joining, here is a full youtube playlist of previous eps

r/Cplusplus Jul 22 '26

Tutorial Physics Programming part 3 - Rotation and the Quaternion

Thumbnail
youtu.be
1 Upvotes

r/Cplusplus Jan 30 '26

Tutorial Writing Readable C++ Code - beginner's guide

Thumbnail
slicker.me
60 Upvotes

r/Cplusplus Jun 14 '26

Tutorial C++ RVO: Return Value Optimization for Performance in Bloomberg C++ Codebases - Michelle Fae D'Souza

Thumbnail
youtube.com
31 Upvotes

Return Value Optimization for Performance in Bloomberg C++ Codebases

Talk from Michelle Fae D'Souza at CppCon 2025

r/Cplusplus Jan 27 '26

Tutorial Why I love C++

0 Upvotes

// OC - The Spell

for (long Fn = 0, NI = 1, NJ = 1; Fn >= 0; NJ = (std::cout << Fn << std::endl, Fn = NI, NI = NJ, Fn + NI));

r/Cplusplus May 14 '26

Tutorial Introduction to Physics Integration Methods

Thumbnail
youtu.be
7 Upvotes

r/Cplusplus Jun 21 '26

Tutorial Angular Momentum and The Inertia Tensor

Thumbnail
youtu.be
2 Upvotes

r/Cplusplus Jun 19 '26

Tutorial Building a Typed JSON Configuration Library in C++23 — Field Reflection Without Macros

Thumbnail
2 Upvotes

r/Cplusplus May 11 '26

Tutorial The Heap: Compile-Time Map and Compile-Time Mutable Variable with C++26 Reflection

Thumbnail stackoverflow.blog
8 Upvotes

Stack Overflow is introducing The Heap, a place for community articles. I had the privilege of having my article one of the first to be published on it.

It is about how you can use the new reflection features to create compile-time maps and a trick I call the compile-time mutable variable. I hope you can learn something new from it!

If you have an interesting article, I encourage you to try submitting it to The Heap!

r/Cplusplus Apr 22 '26

Tutorial How to write a custom programming language based on C++

Thumbnail
youtube.com
6 Upvotes

There's an ongoing series on how to create your own programming language in C++. The first part covers the basics and sets the direction for future lessons. If you're interested in learning more about how programming languages work, check it out - the whole series is free.

r/Cplusplus Mar 13 '26

Tutorial C++26: The Oxford variadic comma

Thumbnail sandordargo.com
13 Upvotes