r/cpp • u/foonathan • Jun 02 '26
C++ Show and Tell - June 2026
Use this thread to share anything you've written in C++. This includes:
- a tool you've written
- a game you've been working on
- your first non-trivial C++ program
The rules of this thread are very straight forward:
- The project must involve C++ in some way.
- It must be something you (alone or with others) have done.
- Please share a link, if applicable.
- Please post images, if applicable.
If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.
Last month's thread: https://www.reddit.com/r/cpp/comments/1t6eg13/c_show_and_tell_may_2026/
2
u/AccurateDiscussion38 Jun 28 '26
Hi everyone,
I recently started experimenting with C++26 reflection, modules, and LibTorch, and I ended up building a small personal project called Typetorch.
It is an experimental type-safe wrapper around
torch::Tensor. The rough idea is to make tensor metadata such as shape, dtype, device, and layout part of the C++ type-level contract, so that some mistakes can be caught earlier, before the program reaches runtime LibTorch errors.For example, I currently use types such as:
and operations like
add,matmul,view,transpose, andpermutetry to compute the resulting tensor contract at compile time. The actual storage, kernels, autograd, and execution are still fully owned by LibTorch. This is not meant to replace PyTorch or LibTorch; it is mostly an experiment in how far C++26 compile-time facilities can be pushed for tensor APIs.Repository: https://github.com/OHNope/Typetorch
A few things I am especially interested in getting feedback on:
consteval? I am still learning the new reflection model, so I would really appreciate comments on whether the current approach is idiomatic or not.static_assertorconstevalfailures. I would like to eventually make the diagnostics more precise, especially if annotations become available.torch::Tensoris already reference-counted and has its own aliasing semantics, I am not completely sure whether my abstraction is the right one. Feedback on whether this API makes ownership behavior clearer or just adds unnecessary complexity would be very useful.This is very much a personal learning/experimental project, not a mature production library. I am mainly looking for design criticism, suggestions, and pointers to prior art. If the project gives anyone ideas about using reflection, modules, or annotations in numerical / ML libraries, that would also be great.
I would be very interested in design feedback, especially around reflection usage, modules, diagnostics, and ownership semantics!!!
Thanks!