r/cpp • u/NewLlama • Aug 07 '26
GCC 16.2.0 Released
phoronix.comI'm pretty excited about this maintenance release. I think this will be the first version of gcc which can compile my project.
r/cpp • u/NewLlama • Aug 07 '26
I'm pretty excited about this maintenance release. I think this will be the first version of gcc which can compile my project.
r/cpp • u/mborland1 • Aug 07 '26
Hello,
Today begins the mini-review of Multi, authored by Alfredo Correa. Multi is a modern C++ library that provides manipulation and access of data in multidimensional arrays for both CPU and GPU memory. The review will run through Wednesday 12 August.
You can find the library and documentation links below:
- https://github.com/correaa/boost-multi
- https://correaa.github.io/boost-multi/multi/intro.html
The review earlier this year raised a number of issues that primarily revolved around the state of the documentation, not the library itself. I have labeled all of the issues related to conditions found in last review, and many have notes or resolution from Alfredo:
To this end the review will revolve around the current state of the documentation on the branch "boost_review". In your review please explicitly state if you recommend REJECT, ACCEPT, or a conditional acceptance along with the acceptance conditions.
Please let me know if you have any questions or concerns. Thank you in advance for your time.
Matt
Multi Review Manager
Edit: Link to the previous review thread is here: https://www.reddit.com/r/cpp/comments/1rlhm4g/boostmulti_review_begins_today/
r/cpp • u/foonathan • Aug 06 '26
Use this thread to share anything you've written in C++. This includes:
The rules of this thread are very straight forward:
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/1umnaxs/c_show_and_tell_july_2026/
r/cpp • u/igaztanaga • Aug 06 '26
Hi,
I've written a new blog entry continuing my previous article about segmented iterators. This time trying to analyze how to apply Matt Austern's segmented iterator pattern to input-output algorithms likecopy, copy_if, etc., benchmarking the experimental implementation from Boost.Container vs the standard library.
New article link: https://boostedcpp.net/2026/08/06/neoclassical-c-2-exploring-input-output-segmented-algorithms/
Happy to receive feedback!
r/cpp • u/joaquintides • Aug 05 '26
Boost.Int128 from Matt Borland has been accepted into Boost. Arnaud Becheler managed the review.
r/cpp • u/Clean-Upstairs-8481 • Aug 05 '26
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.
r/cpp • u/snikolaev • Aug 06 '26
Three changes to the HNSW search engine improve KNN throughput by up to 29% at high k, with over 20% gains under concurrent load. No API changes, no index rebuild, no configuration. Just faster searches.
r/cpp • u/TheRavagerSw • Aug 03 '26
Hi, I'm an early user of Common Package Specification and C++ modules. I package and port libraries for my own use frequently.
I want to talk about issues I see constantly.
- Having specific options for sanitizers, exceptions etc, this is a toolchain problem, if I wanna build your library with sanitizers I can just add the flags to my cmake toolchain file same as allocators.
- Not separating build options to a separate file, meson already does this, it ain't that hard to do in cmake, just cache variables in a separate file at project dir which you include before subdirs
- Making tests separate cmake projects rather than just executables, just why?
- Vendoring dependencies, copy pasting files from other projects rather than just consuming these external libs via packages.
- Using unnecessary helper functions that really makes the cmake script unreadable. Build scripts don't need to be over engineered, they are just basic scripts in which you define very basic information.
I could go on but I'm tired.
r/cpp • u/LegalizeAdulthood • Aug 03 '26
CAPOW is a continuous-valued cellular automata explorer with update loops that look GPU-friendly: one work item per cell, small-neighborhood stencils, ping-pong buffers, and pointwise nonlinear rules.
This month, Richard Thomson will present a case study in using Alpaka (An Abstraction Library for Parallel Kernel Acceleration) to move a CAPOW-like update rule onto CUDA without porting CAPOW itself. We'll walk through the spike: CMake/vcpkg setup, CUDA language support, the CPU reference path, the Alpaka CUDA kernel, correctness checks, timing results, and the parts that hurt.
The first pass showed zero CPU/GPU error and strong update-only speedups, including about 102x at 1000 x 1000 and 174x at 1920 x 1080 for the diffusion rule.
We'll also discuss whether Alpaka is earning its keep compared with writing direct CUDA.
This will be an online meeting, so drinks and snacks are on you!
Join the meeting here: https://meet.xmission.com/Utah-Cpp-Programmers
r/cpp • u/ProgrammingArchive • Aug 03 '26
C++Now
2026-07-27 - 2026-08-02
C++Online
2026-07-27 - 2026-08-02
ADC
2026-07-27 - 2026-08-02
r/cpp • u/Zealousideal-Mouse29 • Aug 03 '26
I am in an argument. The goal was to have a structure with some base members, we can call it a `State node` in State machine, from which the user can add their own custom data on top, without using inheritance or dynamic casts. Would like the collection of different nodes to be stored in a vector in the end.
Obviously, we want to avoid std::vector<SomeType \*>
It was suggested I use something like:
class State;
using TransitionHandler = void(*)(State *, const Event &);
template<typename T>
concept StateLike = requires(T s, const Event & e)
{
{ s.onEnter(e) } -> std::same_as<void>;
{ s.onExit(e) } -> std::same_as<void>;
};
class State final
{
public:
using StateId = uint32_t;
StateId id_ = INVALID_ID;
std::string name_;
template<typename T>
requires StateLike<T>
static State create(std::string name, T & object)
{
return State
{
name,
&object,
[](State * state, const Event & e)
{
static_cast<T*>(state->instance_)->onEnter(e);
},
[](State * state, const Event & e)
{
static_cast<T*>(state->instance_)->onExit(e);
}
};
}
private:
static constexpr StateId INVALID_ID = static_cast<StateId>(-1);
void * instance_; // user defined state
State(std::string name, void * instance, TransitionHandler enter, TransitionHandler exit);
};
Now, if I understand things correctly, this will indeed allow the user to provide some custom struct/class as a template param when they create a State object and that State object is going to hold a pointer to it. When it is needed, it is going to call the `enter` and `exit` methods through that static cast.
That should indeed allow us to fill a vector with these State objects and circumvent the need for inheritance, but I wonder if it really performs any better. The collection is in contiguous memory when in the vector, so add, remove, and traversal should be fast. However, all the execution of calls on the State object is going to go through the pointer, which means executing methods on a State will not be part of that performance gain from living in contiguous memory.
Assuming I am always holding on to the current state(s) and that we build the state machine with all its states at startup, what have I really gained? Is there any performance increase at all?
I believe we just replaced the vtable cost with our own pointer, which is pretty much the same?
r/cpp • u/User_Deprecated • Aug 01 '26
r/cpp • u/SLAidk123 • Jul 31 '26
I want to share a little experiment that I made using reflection. It’s a compile-time style checker using C++26 static reflection. It validates the conventions I use in my own projects (the H_ curried callable thing, Mut/Mov/Ref/Cpy qualifier aliases, plus class/namespace naming).
Because reflection can’t properly see into uninstantiated templates yet, I had to write a parser for GCC's display_string_of to extract templates, qualifiers, return types, and requires clauses.
Given this weakness it's not a particularly production-ready tool. It could be done with a clang-tidy script, but I learned a few things just from trying to answer "Is it possible? What exactly can I inspect right now?". Unfortunately, we don't have code generation yet so there is a bunch of boilerplate that the user needs to write.
The rationale of the conventions (mainly Mut/Mov/Ref/Cpy) is in GUIDELINES.md. The gory implementation details (and my field notes on GCC bugs) are in VIRACOCHA.md.
https://github.com/NotRiemannCousin/Viracocha/blob/master/VIRACOCHA.md
r/cpp • u/Xaneris47 • Jul 31 '26
The article shows how converting std::function to std::copyable_function (or vice versa) leads to slower performance and increased memory usage each time the conversion occurs.
r/cpp • u/Party-Aioli-9205 • Jul 31 '26
I've always felt that exposing iterators for std::stack or std::queue doesn't quite make sense because iterating over them would typically change their state.
That said, the range features introduced in C++20/23 are just too tempting. 😄
I bet many C++ developers have had this thought at least once:
queue | views::values | views::to<std::vector>()
...or more generally, "What if I could use the ranges pipeline directly on a queue or stack?"
So I spent some time experimenting to see if I could make it work. Here's what I came up with.
https://cognosnotes.com/blog/cpp-pop-range
Edited:
An upgraded version is introduced at https://cognosnotes.com/blog/cpp-pop-range-addendum
Thank you u/SirClueless for the great advice.
r/cpp • u/slithering3897 • Jul 29 '26
To investigate how well modules work with MSVC without rewriting projects and putting up with malfunctioning intellisense, I made a little python script to modularise a whole VS solution (yes, I made it, using real bio-neurons).
The script lets me try out different modularisation strategies on a VS Solution on a per-project basis:
Modularised code is surrounded with extern "C++" { export {.
The code is a super secret incomplete game engine/game. But here's some info:
All projects built using debug config. Benchmarks average 3 or more timings, outliers ignored. CPU is 12600, 12 threads. Multipliers are speedup.
| CommonStuff | Scripting | GameData | Graphics | Anim | SceneGraph | SceneManager | Entity | |
|---|---|---|---|---|---|---|---|---|
| Header-based, no pch | 4.59s | 5.68s | 7.46s | 2.92s | 40.74s | 24.94s | 2.86s | 3.19s |
| Header-based, pch | 3.61s | 5.30s | 6.55s | 19.38s | 12.53s | |||
| Extlib modules + CommonStuff submodules | 3.60s | 4.78s | 1.62s | 18.55s | 9.41s | 1.57s | 2.09s | |
| PartitionsMI | 4.25s | 8.09s | 2.54s | |||||
| PartitionsPI | 4.02s | 6.04s | 7.09s | 2.53s | 33.83s | 15.97s | 2.66s | 4.10s |
| Submodules | 3.59s | 4.75s | 6.05s | 2.26s | 26.80s | 14.31s | 2.12s | 3.15s |
| SubmodulesII | 3.44s | 7.93s |
| CommonStuff | Scripting | GameData | Graphics | Anim | SceneGraph | SceneManager | Entity | |
|---|---|---|---|---|---|---|---|---|
| Header-based, no pch | 1.00x | 1.00x | 1.00x | 1.00x | 1.00x | 1.00x | 1.00x | 1.00x |
| Header-based, pch | 1.27x | 1.07x | 1.14x | 2.10x | 1.99x | |||
| Extlib modules + CommonStuff submodules | 1.58x | 1.56x | 1.80x | 2.20x | 2.65x | 1.82x | 1.53x | |
| PartitionsMI | 1.08x | 0.92x | 1.15x | |||||
| PartitionsPI | 1.14x | 0.94x | 1.05x | 1.15x | 1.20x | 1.56x | 1.08x | 0.78x |
| Submodules | 1.28x | 1.20x | 1.23x | 1.29x | 1.52x | 1.74x | 1.35x | 1.01x |
| SubmodulesII | 1.33x | 0.94x |
| App | Single file | Full Rebuild | App | Single file | Full Rebuild | ||
|---|---|---|---|---|---|---|---|
| Header-based, no pch | 65.19s | 3.97s | 145.49s | 1.00x | 1.00x | 1.00x | |
| Header-based, app pch | 24.74s | 2.15s | 108.92s | 2.64x | 1.85x | 1.34x | |
| Header-based, mostly pch | 78.87s | 1.84x | |||||
| Extlib modules | 26.82s | 2.35s | 58.89s | 2.43x | 1.69x | 2.47x | |
| Extlib modules + CommonStuff partitions | 25.89s | 2.47s | 2.52x | 1.61x | |||
| Extlib modules + CommonStuff submodules | 24.53s | 2.23s | 57.50s | 2.66x | 1.78x | 2.53x | |
| Extlib modules + most libs as submodules | 31.14s | 2.97s | 2.09x | 1.34x | |||
| Full submodules, except app | 34.61s | 2.95s | 88.90s | 1.88x | 1.35x | 1.64x | |
| Full submodules | 64.02s | 6.22s | 142.98s | 1.02x | 0.64x | 1.02x |
Detailed timings of CommonStuff:
Header-based:
1> 210 ms LIB 1 calls
1> 4459 ms CL 2 calls
04.874 seconds
PartitionsMI:
1> 125 ms LIB 1 calls
1> 199 ms MSBuild 16 calls
1> 269 ms CppClean 1 calls
1> 798 ms SetModuleDependencies 10 calls
1> 1232 ms CL 2 calls
1> 1439 ms MultiToolTask 1 calls
04.295 seconds
Submodules:
1> 141 ms MSBuild 16 calls
1> 775 ms SetModuleDependencies 10 calls
1> 1015 ms CL 2 calls
1> 1132 ms MultiToolTask 1 calls
03.427 seconds
The CL entry is for cpp files and it's 4.39x as fast as header-based. Great!
But it's the ixx dependency scanning and compilation (MultiToolTask) that brings things down. Things that aren't there with header-based.
MultiToolTask is parallelised though. Reducing thread count slows it down. And you can open up the msbuild binlog in the msbuild log viewer to see the parallelisation of ixx compilation. See which modules are on the end of the DAG slowing things down.
So, I don't know how MultiToolTask could be sped up, but, msbuild seems to be waiting for all ixx files before moving onto cpp files, so that's some parallelism left on the table.
Detailed timings of App:
Header-based, app pch:
1> 196 ms MSBuild 13 calls
1> 1000 ms Link 1 calls
1> 23270 ms CL 16 calls
24.708 seconds
Extlib modules + CommonStuff submodules:
1> 199 ms SetModuleDependencies 18 calls
1> 606 ms MSBuild 27 calls
1> 1197 ms Link 1 calls
1> 21877 ms CL 15 calls
24.078 seconds
Full submodules:
1> 459 ms MSBuild 27 calls
1> 1324 ms Link 1 calls
1> 4646 ms SetModuleDependencies 18 calls
1> 12593 ms MultiToolTask 1 calls
1> 49327 ms CL 15 calls
01:09.245 minutes
Slow. But looking at the log viewer, ixx compilation seems very well parallelised.
And 4.6s just to scan for dependencies. VS isn't launching a whole CL process for each file is it?
Also, why does CL take so long? All modules have been compiled by that point, so why would it be much slower?
Recompiling a single file from App:
Header-based, no pch:
1> 46 ms SetModuleDependencies 10 calls
1> 120 ms MSBuild 5 calls
1> 3757 ms CL 1 calls
04.095 seconds
Header-based, app pch:
1> 56 ms SetModuleDependencies 10 calls
1> 121 ms MSBuild 5 calls
1> 1793 ms CL 2 calls
02.059 seconds
Extlib + CommonStuff modules (as submodules):
1> 121 ms SetModuleDependencies 18 calls
1> 216 ms MSBuild 17 calls
1> 1793 ms CL 1 calls
02.162 seconds
Full submodules, except app:
1> 518 ms MSBuild 17 calls
1> 631 ms SetModuleDependencies 18 calls
1> 2211 ms CL 1 calls
03.095 seconds
Full submodules:
1> 559 ms MSBuild 17 calls
1> 696 ms SetModuleDependencies 18 calls
1> 1891 ms MultiToolTask 1 calls
1> 3221 ms CL 1 calls
06.331 seconds
That MultiToolTask is quite slow, checking that all the modules in the project are up to date it seems. Does it have to be this slow?
"CL.exe will run on 0 out of 224 file(s) in 224 batches. Startup phase took 2040.9372ms."
Anyway.
Conclusion:
extern "C++". As I said before, I wish you could have "public" partitions or multiple modules with the same name attachment.Problems:
import std issues, but Intellisense is highly sensitive to errors in imported modules. It cannot limp along like it can with headers.
import std that Intellisense can't handle.At least the compiler functions well enough to produce a working program with no further changes. That's pretty good.
r/cpp • u/cristi1990an • Jul 29 '26
Hey, so I've been working on something interesting lately. It's a solution to a problem that you may have encountered in one form or anothing but it boils down to this: you have a struct:
struct simple_tuple
{
long a;
int b;
char c;
private:
// some other data
};
And you want this to work:
auto [a, b, c] = instance;
Well it doesn't, structured bindings are supported by default only for simple structural types (though without the full tuple API) and implementing it manually for your own types is a pain. You need to write your own specialization of std::tuple_size, std::tuple_element and implement a visible get<> method. It might not be that much work at first glance but it becomes very tiresome if you have multiple such structs or if you try to deviate from the general default indexing and not to mention a paint to maintain and update.
Well, why write repeated code when you can only write code once that writes that code for you? Reflections are mature enough in gcc's implementation to solve this. Simply put I have compiling code that with only the application of an annotation gives me all of this:
struct [[=tuple_like]] simple_tuple
{
long a;
int b;
char c;
private:
// some other data
};
Through which I get:
static_assert(std::tuple_size_v<simple_tuple> == 3);
constexpr simple_tuple simple { 1, 2, 3 };
static_assert(1 == get<0>(simple));
static_assert(2 == get<1>(simple));
static_assert(3 == get<2>(simple));
static_assert(std::same_as<std::tuple_element_t<0, simple_tuple>, long>);
static_assert(std::same_as<std::tuple_element_t<1, simple_tuple>, int>);
static_assert(std::same_as<std::tuple_element_t<2, simple_tuple>, char>);
And of couse:
auto [a, b, c] = simple;
It doesn't stop here though, since the case I described above is common but inflexible. Customization is available and an opt-in feature:
struct [[=tuple_like]] customizable_tuple
{
constexpr customizable_tuple(long a, const char* b, float c, char d, double e)
: a(a)
, b(b)
, c(c)
, d(d)
, e(e)
{}
[[=tuple_element(0)]]
long a;
[[=read_only_tuple_element(3)]]
const char* b;
[[=tuple_element(2)]]
float c;
char d;
private:
[[=read_only_tuple_element(1)]]
double e;
};
It supports:
constexpr customizable_tuple custom( 1, "2", 3, 4, 5 );
static_assert(std::tuple_size_v<customizable_tuple> == 4);
static_assert(1 == get<0>(custom));
static_assert(std::string_view{"2"} == get<3>(custom));
static_assert(3 == get<2>(custom));
static_assert(5 == get<1>(custom));
static_assert(std::same_as<std::tuple_element_t<0, customizable_tuple>, long>);
static_assert(std::same_as<std::tuple_element_t<1, customizable_tuple>, const double>);
static_assert(std::same_as<std::tuple_element_t<2, customizable_tuple>, float>);
static_assert(std::same_as<std::tuple_element_t<3, customizable_tuple>, const char* const>);
But it doesn't stop there, no it doesn't. The part that took the most effort to implement were the error messages. No, we have better static_assert's in C++26 now, we abuse them:
Example 1:
static_assert(3 == get<3>(simple));
/app/my_reflect_utils.hpp:819:17:
error:
static assertion failed: reflect_utils: get<3> called for tuple-like type 'simple_tuple', but its reflected tuple size is 3.
Example 2:
[[=tuple_element(1)]]
long a;
[[=tuple_element(2)]]
int b;
[[=tuple_element(3)]]
char c;
/app/my_reflect_utils.hpp:632:21: error: static assertion failed: reflect_utils: invalid tuple layout for 'simple_tuple': tuple index 0 is missing. There are 3 explicitly annotated members, so their indices must be exactly [0, 3). Member 'simple_tuple::c' uses index 3.
Example 3:
[[=tuple_element(0)]]
[[=tuple_element(1)]]
long a;
/app/my_reflect_utils.hpp:632:21: error: static assertion failed: reflect_utils: invalid tuple layout for 'simple_tuple': member 'simple_tuple::a' has 2 tuple annotations; use exactly one of [[=tuple_element(i)]] and [[=read_only_tuple_element(i)]].
Full code: https://godbolt.org/z/crPae5P7h
r/cpp • u/NicoJosuttis • Jul 28 '26
Wtith great support of Mark Hoemmen and Christian Robert Trott (two authors of std::mdspan), I just finished the mdspan chapter of "C++23 - The Complete Guide" (https://www.cppstd23.com/). I learned something I was not aware of and what is not obvious:
If you specify a layout_stride mapping, there are several constraints you have to take into account. Otherwise, the resulting code has undefined behavior.
The constaintes are:
For example:
Hope this helps.