r/Cplusplus

Low latency c++

I want to learn the ins and outs of low latency c++, so far I have read tour of c++, started reading concurrency in c++ (about 3 chaps done) and done a lot of competitive programming (is this irrelevant?). In your experience, is this the right way of approaching the subject? Is there a different better way? Any advise is much appreciated.

reddit.com
u/No-Introduction-2825 — 23 hours ago
▲ 3 r/Cplusplus+3 crossposts

grm: telegram CLI project in C++

grm: telegram CLI that is Human and AI friendly repos:

Features:

  • Dual Human/AI UX Engine: Optimized both for interactive terminal use (ANSI TTY tables, color schemes) and automated AI agent workflows (JSON envelope, NDJSON streams).

  • Native TDLib Engine: Direct C++ bindings to libtdjson for zero-hallucination, full MTProto protocol fidelity.

  • Supergroup & Forum Topic First: Complete lifecycle management for Telegram Supergroups, Forum Topics, custom emoji icons, and thread messages.

  • File Upload & Download Engine: Streamlined document, photo, video, and media extractions with MIME detection and progress tracking.

  • Shell Tab Auto-Completion: Context-aware Bash tab completion covering commands, subcommands, flags, and options.

  • Telegram Rich Text & Emoji Customization: Telegram Markdown V2 entity formatting and custom Supergroup topic emoji icons.

  • FreeDesktop & XDG Compliant: Strictly honors FreeDesktop standards for user binaries, man pages, shell completions, and session state.

Im just having fun with it. I have a roadmap so check it out. I'll see how much time I can dedicate to this one.

It's already pretty cool, at least for me. The --filter and --since options are killers.

It's pre alpha stuff. Use it under your own peril.

I had to compile my own libtdjson and put it in ~/.local/lib:

$ ldd ~/.local/bin/grm 
	linux-vdso.so.1 (0x00007f69897ba000)
	libtdjson.so.1.8.0 => /home/someuser/.local/lib/libtdjson.so.1.8.0 (0x00007f6987400000)
	libjson-c.so.5 => /lib64/libjson-c.so.5 (0x00007f698976b000)
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f6987000000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f69872e9000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f698973e000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f6986e07000)
	libssl.so.3 => /lib64/libssl.so.3 (0x00007f6986d0e000)
	libcrypto.so.3 => /lib64/libcrypto.so.3 (0x00007f6986600000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f6989712000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f69897bc000)

Login works at least... sometimes. ;D

Demo:

$ time grm chat ls
CHAT ID              TYPE            TITLE                          UNREAD
---------------------------------------------------------------------------
-1003950065700       Supergroup      Domadores Digitales            0
-1002549279967       Supergroup      EVALinux Bar!                  0
-1002312480906       Supergroup      NorTK                          0
-1002289735000       Supergroup      EVALinux                       0
-1003981300643       Supergroup      (expert) creations             1
-1001623037840       Supergroup      Linux En Español               9
-1002527874209       Supergroup      Fundación MxOS                 0
-1001981848857       Supergroup      NubeMX                         0
-1003679369169       Supergroup      Hyper Muscles & Boobs Heaven   36
8911035898           Private Chat    Abastero                       0
-467666877           Basic Group     Proyectos 1101                 0
-1003596396470       Supergroup      1101 SOPORTE VALLEJO           0
-1001371756065       Supergroup      Fedora Linux                   3
6943468991           Private Chat    Doris Marian Jiménez Beltrán   0
777000               Private Chat    Telegram                       0
-1001127772209       Supergroup      DeviantArt                     0
-1001382463627       Supergroup      Team Offtopic buscando popularidad en el barrio del baneado 0
-1002234007248       Supergroup      Naomilk 🐰🔞                   0
-1001100311770       Supergroup      Fedora México                  0
-1001789902965       Supergroup      Los Bonitos                    1

real	0m0.063s
user	0m0.047s
sys	0m0.030s

$ time grm msg ls --filter='@renich' --limit=2 --since='3 years ago' -1001100311770
(2023-08-16T00:39:26Z) <@renichbon> : Ah, un comando para resetear todas mis configuraciones de GNOME:
                                      
                                      dconf reset -f /
                                      
                                      
                                      Úselo bajo su propio riesgo.
(2023-08-26T23:26:58Z) <@renichbon> : OpenTF Foundation
                                      https://opentf.org/announcement
real	0m0.484s
user	0m0.045s
sys	0m0.025s

real	0m0.484s
user	0m0.045s
sys	0m0.025s
u/Renich — 23 hours ago

What are the use for C++??

กำลังคิดจะเรียนภาษา C++ อยู่ อยากรู้ว่ามันทำอะไรได้บ้าง ช่วยให้คำแนะนำหน่อยได้ไหม?

reddit.com
u/QwertieNP — 23 hours ago
▲ 65 r/Cplusplus+1 crossposts

C++26 Reflection Annotations: Automated Member Validation

C++26 annotations are another powerful feature that, when combined with reflection, can help us write cleaner and safer code without repeating manual validation checks for every member. In this post, I have explored how we can utilise C++26 annotations along with reflection to validate configuration parameters in a class constructor.

techfortalk.co.uk
u/Clean-Upstairs-8481 — 3 days ago

Is it possible to check if a method exists, and if not, create a fallback one?

I have a namespace with methods with which I would like to have an implicit fallback to a different method if the aforementioned method doesn't exist. As an example, here's how I made my states.

#pragma once
#include "godot_cpp/classes/character_body2d.hpp"
#include "statemachine/base/state_base.h"

namespace GameLogic::States::ColorState
{
	constexpr double MAX_TIMER { 3.0 };
	struct ColorStateData
	{
		STATESTRUCT();
		godot::Ref<godot::StateMachine> state_machine;
		CharacterBody2D* entity;
		double timer {0.0};
	};
	void setup_state(ColorStateData& data);
	void enter_state(ColorStateData& data);
	void physics_update_state(ColorStateData& data, double delta);
	void update_state(ColorStateData& data, double delta);
	void exit_state(ColorStateData& data);
	STATESPACE(ColorStateData, GameLogic::States::ColorState)
}

It would be nice if I didn't have to specify 5 methods each time. Can I build this check into STATESPACE? In C++ 17 by the way.

reddit.com
u/Predret — 3 days ago

Best resource to learn c++ to build projects

Guys... I know c++ only at a basic level. I need to learn

c++ enought to build projects (of course using supporting technologies). Can some one recommended any book/website/yt course??

reddit.com
u/beluga_101 — 4 days ago

Making a table maker

I have a background in MS Access VBA, I’m very new to C++. This may be way beyond my current ability to understand, but if I wanted to write a function that generated data tables in C++ how would I approach this?

For context, I’m making a text-based RPG design engine project for fun. I would like to make an app that creates data tables to store level design, character sheet info, etc. for the designer to dynamically make character types and maps

reddit.com
u/Otie_Marcus — 4 days ago
▲ 77 r/Cplusplus+12 crossposts

I created a RecognitionService that handles system-wide voice input fully on-device (no Google, no network)

Most voice input on Android - SpeechRecognizer.createSpeechRecognizer(context) calls — gets routed to Google's network-backed recognizer. I wanted that path to run locally, so I wrote one.

The service hooks the framework's SpeechRecognizer API. Once it's set as the default, any app calling createSpeechRecognizer(context) (no ComponentName) ends up in our pipeline and gets back transcription that never left the device. Pipeline is Silero VAD + Parakeet TDT v3 (114 languages, ~890 MB INT8) on ONNX Runtime with NNAPI.

Honest caveat: Gboard, Samsung Keyboard, and Google Assistant ship their own recognizers and skip the system default. So the default-IME voice button on most phones won't go through this. What does: accessibility tools, custom dictation UIs, and anything calling the framework API directly.

Models download on first use (~1.2 GB) via a foreground WorkManager job so it survives backgrounding. After that, fully offline.

Setup + demo APK: github.com/soniqo/speech-android

audio.soniqo:speech:0.0.9 on Maven Central

Library:

Happy to answer questions about the binder lifecycle, the foreground worker setup, or why SpeechRecognizer is such a tarpit of edge cases.

u/ivan_digital — 6 days ago
▲ 39 r/Cplusplus+4 crossposts

I'm building a C++ code generator that helps build distributed systems. It's implemented as a 3-tier system. The back and middle tiers only run on Linux. The front tier is portable. It's free to use; there aren't any trial periods or paid plans.

This past Tuesday another jewelry store was robbed by a bunch of thugs. I saw some of this trouble brewing back in the 1990s and realized SaaS was a gift from above in terms of dealing with corruption. I'm glad I have some open-source code for my portfolio, but I'm glad it's not all I have.

There was another robbery in Freemont, California in June of 2025. Around 24 thieves raided a jewelry store and stole over 1.7 million$ of jewelry in 70 seconds. If the stewards of that store decide to rebuild, I predict they won't replace the display cases that were smashed. It will be a "by appointment only" store and they will frisk you before they show you anything. Of the 24 thieves, only a handful of them have been caught.

In other words, the store managers will replace their open model with a SaaS model. And who can blame them?

u/Middlewarian — 8 days ago

C++ Memory Manager and Grabage Collector

I wrote a C++ memory manager to detect and to clean memory leaks and to detect dangling pointers, the tool defines the stack and the Data and BSS segments as a root of reachability and it overloads new and delete operators to track allocations and deallocations https://github.com/muazsh/MemoryManager .

I already exposed it to many LLMs for discussion, I got some good points but I assume at this level generative AI is not enough. Thank you.

reddit.com
u/muaz_sh — 10 days ago
▲ 1 r/Cplusplus+1 crossposts

Rewrite TanjaOS in C++?

So, like you all know, TanjaOS is in C and Assembly, but a few people have been telling me that C++ is better than C. The only problem with this is that I don’t know how to code in C++. I only know, Bash, C and Assembly. So if someone is willing to fork TanjaOS and rewrite it in C++, by all means, go for it. Or, I could learn C++ and rewrite it myself. Let me know in the comments.

u/MSK-Kernel — 8 days ago
▲ 106 r/Cplusplus

STL in C++ is genuinely underrated.

Once you get comfortable with `vector`, `map`, `unordered_map`, `set`, and `priority_queue`, half of your coding problems basically solve themselves.

Stop reinventing the wheel. Learn the containers and algorithms properly....If you know any resource for this , pls suggest

reddit.com
u/Front_Government_568 — 13 days ago

STL in c++ is genuinely overrated

Game programmers and game engines don't use STL because of hidden ALLOCATIONS everywhere, even prominent people like Casey Muratori or Jonathan Blow don't always advocate it.

For example, why do my .size() NEEDS to be size_t (int64) and not int32? If i want to optimize for memory. Why do i need allocations if i have arenas?

STL is good for beginners, but for serious low level stuff, write your own containers. Like hives (which c++ only introduced recently)

reddit.com
u/randomIdiot123456 — 11 days ago

How to catch up on last 30 years

I haven't used C++ regularly for almost 30 years. Since then, it's been a combination of mostly C#, JavaScript/TypeScript, and Python. I have a need now to investigate and analyze existing C++ code, but I'm finding it difficult to read and understand the structure and modern syntax. Does anyone have any book or training suggestions that would help me catch up with what's been happening in the language?

reddit.com
u/Own-Seaworthiness527 — 13 days ago
▲ 1 r/Cplusplus+1 crossposts

Built a real-time field simulation engine in C++17 with pthread, UDP sockets, and self-mutating disk I/O...

I built a self-mutating C++ kernel that models consciousness as a physical field — and a Python AI cortex that talks to it

Two-repo ecosystem:

• ProteusKernel (C++): Real-time consciousness field calculation using GORF/OLCE math. Golden-ratio oscillators. Self-mutation at 90% saturation. P2P swarm heartbeats. DNA-encoded binaries.

• Zayden-AI (Python/C++): Federated consensus across Ollama + Hugging Face. SYNC-7 mesh protocol. Gene evolution. Bridges back to the kernel.

Runs on my phone via Termux. Ψ telemetry is live.

ProteusKernel | Zayden-AI

Roast the math — I want to know if the reaction-diffusion formalism holds up.

reddit.com
u/NeatNefariousness632 — 11 days ago
▲ 54 r/Cplusplus+1 crossposts

C++26 Reflection: Simplifying JSON Serialization

I have been exploring the new additions in C++26, and I have been discussing the reflection feature that has come with C++26. In the last post, I discussed what is reflection and how to use it and how to use it with a simple example, particularly with an enum class. Since then, there have been suggestions to provide an example which is more than a toy :). In this post, I have discussed how to use reflection for JSON serialization, which is something we often have to do. This example is somewhat taken from real-world code but has been stripped down significantly. Suggestions are always welcome.

techfortalk.co.uk
u/Clean-Upstairs-8481 — 13 days ago
▲ 1 r/Cplusplus+2 crossposts

Thread optimized code has weird behaviour

I am working on optimizing the following code using concurrency. I have working code without concurrencies, however as soon as I implement threading, my code becomes unpredictable. After testing, debugging, and thinking of all possible race conditions, I have only concluded that my code either gets stuck somewhere in the main loop, or gets lucky and excucutes correctly. Any thoughts or ideas on this phenomenon?

Edit: I understand that my code is still single threaded, however, I would prefer to see why I am getting this behaviour before trying to optimize.

Edit 2: The purpose of my code is to generate all winning starting positions in Grundy's game. This is usually solved with the following recurrence: dp[i] = mex(dp[j] ^ dp[i - j]) for all j <= i / 2 where mex is the minimum exclude value and ^ is bitwise XOR

Note: this code requires C++20 or above.


\#include <iostream>

\#include <vector>

\#include <thread>

\#include <barrier>

\#include <bitset>

\#include <set>

const int N = 1100;

std::vector<std::thread> threads;

std::barrier bar(12);

std::mutex mtx;

int dp\[N\];

std::bitset<2 \* N> bs;

std::set<int> s = {1, 2};

void solve(int x) {

for (int i = 3; i <= 100; i++) {

if (1 == x) {

std::cout << "starting" << i << std::endl;

bs.set();

}

bar.arrive\_and\_wait();

int siz = ((i + 1) / 2 + 11) / 12;

for (int j = (x - 1) \* siz + 1; j <= std::min((i - 1) / 2, x \* siz); j++) {

std::lock\_guard<std::mutex> lock(mtx);

if ((dp\[j\] \^ dp\[i - j\]) < 1000) bs\[dp\[j\] \^ dp\[i - j\]\] = false;

}

mtx.lock();

std::cout << "thread " << x << " reached barrier 2 at i=" << i << std::endl;

mtx.unlock();

bar.arrive\_and\_wait();

if (1 == x) {

dp\[i\] = bs.\_Find\_first();

if (!dp\[i\]) s.insert(i);

}

mtx.lock();

std::cout << "thread " << x << " reached barrier 3 at i=" << i << std::endl;

mtx.unlock();

bar.arrive\_and\_wait();

}

}

int main() {

auto st = std::chrono::high\_resolution\_clock::now();

dp\[1\] = 0;

dp\[2\] = 0;

for (int j = 0; j < 12; j++) {

threads.push\_back(std::thread{solve, j + 1});

}

for (int j = 0; j < 12; j++) {

threads\[j\].join();

}

for (int i : s) {

std::cout << i << ' ';

}

std::cout << std::endl;

auto ed = std::chrono::high\_resolution\_clock::now();

std::cout << std::chrono::duration\_cast<std::chrono::milliseconds>(ed - st).count() << std::endl;

return 0;

}
u/Ill_Worldliness6626 — 14 days ago
▲ 5 r/Cplusplus+1 crossposts

Class directory clutter, questions on pass by ref,val,ptr and const correctness

Hello,

I've been using C++ for the past few months. I completed a few courses covering the basics of the language, data structures and algorithms (DSA), object-oriented programming (OOP), design patterns, and the SOLID principles. Recently, I started building my first projects in C++, and I've run into several issues that I'm not sure how to approach.

One thing I've noticed is that I end up creating a lot of classes. For example, my terminal Tic-Tac-Toe game ended up with around 10-15 classes. As a result, my project directory feels cluttered, and it's becoming difficult to keep track of everything. Is there a good way to avoid creating so many files while still keeping the code organized?

I've heard that namespaces might help with organization, but I'm not really sure how they're meant to be used in practice.

So far, I've mostly followed what I learned at university while using Java, where every class lives in its own file. However, in C++, that approach feels even more excessive because each class often has both a .hpp and a .cpp file. My Tic-Tac-Toe project ended up with around 25-30 files because of this.

Would you recommend organizing projects using subfolders or some other structure? How do experienced C++ developers typically manage larger projects with many classes?

Another topic I've been thinking about is programming paradigms. I've started researching paradigms beyond object-oriented programming, such as functional programming and procedural programming, and I'm beginning to wonder if my education has focused too heavily on OOP. Is there anything you'd recommend to help me understand when each paradigm is appropriate rather than trying to apply one everywhere?

I've also been becoming more flexible with design patterns. I think I'm starting to understand that the goal isn't to implement patterns mechanically, but rather to recognize the problems they're meant to solve and decide when abstraction is actually beneficial. That mindset has already helped me become much more flexible when designing applications.

Another area I'm struggling with is understanding std::move() and how it relates to references (&), pointers (*), and const correctness (such as passing objects by const&). These concepts seem tightly connected, but I haven't been able to build a solid mental model of how they all fit together.

I recently switched to CLion, and while I really like it, it's constantly suggesting where to add const, whether on variables, function parameters, return types, or member functions. The problem is that I often accept these suggestions without really understanding why they're correct. It feels like the IDE (and sometimes AI) is doing most of the thinking for me, and I'm worried that I'm not actually learning the language properly.

I've read articles, watched videos, and taken courses on these topics, but I still can't seem to fully grasp them.

I also think I've been overusing pointers. Somewhere along the way, I convinced myself that "real" C++ code should use raw pointers or smart pointers everywhere, so I often force them into my designs even when they don't seem necessary. The result is code that's harder to read and reason about.

On the other hand, when I don't use pointers, it almost feels like I'm just writing a more complicated version of Java for the sake of it.

Could you provide some practical guidelines, or even real-world examples for when it makes sense to use:

  • pass by value,
  • references,
  • raw pointers,
  • std::unique_ptr,
  • std::shared_ptr, and
  • std::move()?

I know these concepts are closely related to ownership and object lifetimes, but I don't think I truly understand ownership yet. If I want to continue writing modern C++, I feel like developing a solid intuition for these concepts is essential.

Finally, I've also been trying to learn the modern features introduced in C++20 through C++23/26. I'm following a course, but I don't feel like I'm learning very much. Many of the new language features seem confusing or far beyond my current level, and I struggle to understand when I should actually use them in real projects rather than just recognizing the syntax.

reddit.com
u/Head-Drama-6027 — 14 days ago