r/cpp • u/tartaruga232 • Apr 04 '26
Options for Organizing Partitions
abuehl.github.ioI'm looking forward to getting grilled. Thanks in advance for your time and your patience!
r/cpp • u/tartaruga232 • Apr 04 '26
I'm looking forward to getting grilled. Thanks in advance for your time and your patience!
r/cpp • u/gruenich • Apr 04 '26
C++26 is a different language compared with when Qt introduced QString and QStringView. For example C++17 introduced std::string_view. Is there any advantage left over what std offers? What about compatibility, could a potential Qt 7 just drop their own code and make QString* a type alias of std::string*?
r/cpp • u/ProgrammingArchive • Apr 04 '26
r/cpp • u/Felixzsa • Apr 03 '26
https://github.com/felixaszx/coro-fiber
I did some experiments with this. The result is very surprising. I tested this on my Ryzen 7700X (8c/16t) Windows 11.
This is barely optimized. But, its is able to outperform boost::fiber in single-thread context switching (~20ns vs ~60ns, LLVM 21, std=c++20, the timer takes ~20ns). And even with the work stealing algorithm across all 16 threads trying to steal 1 fiber, it can still maitain at ~22ns of context switching.
I guess this is really uncommon since most of the time we expect our fiber to have some real workload rather than infinitely yielding to some other fibers. I am looking for some advices about how to improve the scheduler, right now it is just doing round robin locally or steal from other thread's queue if empty.
r/cpp • u/emilios_tassios • Apr 03 '26
In this week’s lecture, Dr. Hartmut Kaiser focuses on the implementation of distributed parallelism using HPX to solve large linear algebra systems (LLAS) equations. The lecture highlights essential foundational concepts by revisiting both the SPMD and CSP models from previous discussions, setting the stage for advanced problem-solving in high-performance environments.
A core discussion demonstrates how to implement a Jacobi method for distributed computation, specifically addressing the practical challenges of managing data dependencies across partitions. Finally, critical strategies for optimizing performance are explored, offering a comprehensive approach to handling complex, distributed mathematical operations.
If you want to keep up with more news from the Stellar group and watch the lectures of Parallel C++ for Scientific Applications and these tutorials a week earlier please follow our page on LinkedIn https://www.linkedin.com/company/ste-ar-group/
Also, you can find our GitHub page below:
https://github.com/STEllAR-GROUP/hpx
r/cpp • u/SolidNo1299 • Apr 03 '26
I come from a C background and now am working with a large codebase in C++. The biggest "culture" shock is the absolute mind-numbing amount of choices to accomplish a task which I have heard a lot about. And I know a lot of opinions are thrown out there (some good, some bad, but mostly subjective). I want to see if there is an overwhelming consensus on stuff that every style of C++ should adopt and if anybody could list at least some pillars of good habits that devs here almost always agree on?
I know the mature decision is to prioritize readability and use the right abstraction when it is needed, but what are some core things I need to memorize? The only things I know that is (almost) universally agreed upon:
malloc()/free() or any C-like string manipulation (theres always a better C++ alternative that does the same thing)using namespace std;new/delete justifiable in rare cases? (again, not quite sure)But in other cases, for example, brace initializing vs assignment has some debate even though I know brace initialization prevents narrowing but overwhelming developers I talked to still prefer using '=' for readability, same with classic for loops instead of using something from <algorithm>. I guess it boils down to: which features should you absolutely use in almost any case vs use it when the occasion comes?
tl;dr If C++ was a culture, which things are absolutely taboo vs justifiable in certain contexts?
r/cpp • u/thisis_a_cipher • Apr 02 '26
For context, before I learnt cpp, I primarily used python and java.
When I was first starting out in learning cpp, I felt completely lost -- because I felt none of the resources usually mentioned online filled the gap of getting a dev familiar with a high-level language up to speed on the core concepts of modern cpp. Overwhelmingly, resources were meant for complete beginner programmers, and these resources barely mapped onto existing mature code bases that I was supposed to work on.
Even courses like "cpp for java developers" focused overwhelmingly on things like arrays, vectors, strings. like ??? pedagogically, it makes no sense to focus on these things - I can just read cppreference, they are standard data structures.
I finally stumbled onto this criminally underrated playlist of 5 short videos that explain the core concepts you need to know
I still consider myself a novice in cpp after working with it for about a year now, but these 5 videos were honestly enough for me to start understanding and contributing to existing cpp codebases. Obviously, there was a lot of learning that I did after from various sources, but I didn't even KNOW that these were the core concepts that I should've been focused on to start going deeper before I stumbled across that playlist.
For instance, learncpp.com often gets mentioned on this subreddit but
Just thought I should share.
r/cpp • u/foonathan • Apr 02 '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/1ri7ept/c_show_and_tell_march_2026/
r/cpp • u/holyblackcat • Apr 02 '26
r/cpp • u/OkEmu7082 • Apr 02 '26
the Command-Query Separation (CQS) principle (Meyer's doctrine) says that a function should be either side effect free or side effect only(no return value). in cpp scientific programming, this makes sense performance-wise since for large objects, it is efficient to allocate once and use function side effect to modify, and one should avoid returning large object that involved the expensive allocation and deep copying.
(modern) fortran's syntax support even makes this principle somewhat explicit, it provides the function(which is usually used without side effect) and subroutine( which is analogues to the c/cpp function that returns void), and in fortran OOP one usually sticks to type bound subroutines instead of type bound functions so that if it is already altering the state of the obj as a side effect there should be no more return values
do you know or come across any exception in cpp scientific programming or in other applications, where the CQS principle should be violated and it is the best way to do it? why?
Edit: how does the usage of functor/lambda in cpp evolve this doctrine
r/cpp • u/tartaruga232 • Apr 02 '26
A brief recap of the current status of module partitions - as I understand it.
"module A:;") on top of an already arcane concept.Questions:
1 Yes, I know the MSVC compiler has this obscure /InternalPartition option for those who want standard conformant behavior.
r/cpp • u/booker388 • Apr 02 '26
Repo here: https://github.com/lewj85/jessesort
Added branchless binary search and now JesseSort is faster than std::sort on every input type except random, and only slightly behind random! Easy enough to code a fallback mechanism too to just use introsort in those cases. Here's the gcc (libcstd++) timing table:
Number of Input Values
Input Type 1000 10000 100000 1000000
------------------------------------------------------------------------------
Random 1.607 1.164 1.150 1.191
Sorted 1.070 0.684 0.576 0.554
Reverse 1.660 0.949 0.895 0.804
Sorted+Noise(3%) 0.931 0.751 0.721 0.796
Random%100 1.444 1.170 0.905 1.050
Jitter 1.056 0.688 0.658 1.511
Alternating 0.869 0.536 0.237 0.528
Sawtooth 1.948 0.613 0.278 0.477
BlockSorted 0.693 0.361 0.278 0.518
OrganPipe 0.374 0.190 0.116 0.245
Rotated 0.536 0.430 0.321 0.686
Signal 1.493 0.839 0.614 0.531Values <1 mean JesseSort is faster. Take a look at that 100k column!
Similar performance with clang (libc++), though slightly worse on random input (clang table is in the repo readme). Again, with a fallback, it's easy enough to match introsort performance on random input while gaining huge speedups almost everywhere else.
Looking for contributors to help me with this. Dual patience has so much potential and some cool avenues to explore, such as simulating games, early freezing, or AVX2/AVX512 insertion. Always welcome to hearing new ideas as well.
r/cpp • u/Xadartt • Apr 01 '26
r/cpp • u/cristi1990an • Apr 01 '26
For those who dabbled in Rust, you might know that string types in Rust, be it literals, slices or owned are by default UTF8 encoded and all methods enforce this invariant. Funny thing is that this design also works well in C++, allowing us to validate strings once, keep their unicode validity enforced through dedicated types and work on these unicode strings without worries of runtime errors.
This is what I've been working on for the past few weeks and I wanted to share it with you, prior to making the full official release.
Hopefully the few examples of the features this library has that I've added here are self explanatory, and I'm also adding a link to the project: https://github.com/cristi1990an/unicode_ranges
#include "unicode_ranges.hpp"
#include <print>
#include <array>
#include <ranges>
using namespace unicode_ranges;
using namespace unicode_ranges::literals;
int main()
{
// Compile time string validation
static constexpr utf8_string_view greetings = "Salutări din România 🇷🇴 👋"_utf8_sv;
// Rust style unicode character/grapheme lazy views over the string
std::println("{}: {}",
greetings.char_count(), // 25
greetings.chars() | std::views::drop(21)); // [🇷, 🇴, , 👋]
std::println("{}: {::s}",
greetings.grapheme_count(), // 24
greetings.graphemes() | std::views::drop(21)); // [🇷🇴, , 👋]
// owned utf8 string
utf8_string owned_string = greetings;
// find and replace grapheme cluster with utf8 string slice
owned_string = owned_string.replace_all("🇷🇴"_grapheme_utf8, "[ro flag]"_utf8_sv);
// replace any of matching characters with replacement (rvalue overload might not reallocate)
owned_string = std::move(owned_string).replace_all(std::array{ "ă"_u8c, "â"_u8c }, "a"_u8c);
// STD style index based modifying methods also available
owned_string.erase(owned_string.find("👋"_u8c), "👋"_u8c.code_unit_count());
std::println("{}, {}, {}",
owned_string, // Salutari din Romania [ro flag]
owned_string.starts_with("Salutari"_utf8_sv), // true
owned_string.is_ascii()); // true
// pipe the character view into your favorite view adaptors, don't worry about overlaps
owned_string = owned_string.chars()
| std::views::filter(
[](utf8_char ch)
{
return ch.is_ascii_lowercase();
})
| std::ranges::to<utf8_string>();
std::println("{}", owned_string); // alutaridinomaniaroflag
}r/cpp • u/joaquintides • Apr 01 '26
r/cpp • u/Massive-Bottle-5394 • Mar 31 '26
I'm experimenting with reflection in C++26 and other things. And I'm confused by the behavior of std::constant_wrapper. https://godbolt.org/z/vo6rbMb41
Can somebody explain why example not working and how to fix?
I need to implement some reflection functions using this technique (deducing a template parameter via a constructor argument), but this error is making me wonder
EDIT
I did a little research, and it seems that this behavior comes from the implementation in GCC, which for some reason doesn't follow the wording of the proposal that literally describes the entire implementation
EDIT 2
I was wrong. There is a newer version of the proposal that explains the observed behavior. Still, it’s a sad thing that my case isn’t supported.
r/cpp • u/ContDiArco • Mar 31 '26
This is an endeavor...
r/cpp • u/tartaruga232 • Mar 31 '26
I've been bold and created two friendly new subreddits:
Everything about the Microsoft C++ compiler
News, insights, discussions & questions about the modules feature of the C++ programming language.
I hope it's ok to mention these here. Let's see how it goes.
r/cpp • u/caroIine • Mar 30 '26
r/cpp • u/mindsaspire • Mar 30 '26
I've been building a C++20 service on Seastar and catalogued every class of bug that burned me into a set of rules I check on every commit. Each one cost at least a day to diagnose.
A few examples:
.then() are use-after-free (the coroutine frame outlives the lambda that created it)std::shared_ptr destructs on the wrong shard in Seastar's shared-nothing model& in do_with lambdas gives you a copy that dies while the future is still runningSome are Seastar-specific, but most apply to any coroutine-based async C++. The post covers the anti-pattern, why it breaks, and the fix for each.
https://ranvier.systems/2026/03/29/24-hard-rules-for-writing-correct-async-cpp.html
Curious if others have hit similar issues or have rules I'm missing.