6,220 questions
Score of 7
0 answers
149 views
Using std::cout with exception configuration triggers cerr throwing exception, too
Recently I learnt that nearly every C++-hello-world-program is buggy because it returns 0 (= EXIT_SUCCESS) even if the output could not be written. This can e. g. happen when you redirect the output ...
Score of 3
1 answer
202 views
What is wrong with using `forward` without the `std::` qualifier?
Clang has the warning unqualified-std-cast-call. It warns when move and forward are used without the std:: qualifier, for example when the code has a using statement.
The patch says that there is a ...
Score of -4
1 answer
281 views
Using C++26 <simd> library [closed]
My C++ compiler (g++ 16) have changed the <simd> library implementation under the hood forcing me to learn the new version of the library.
I have got 2 problems:
I don't know how to set the ABI ...
Score of 2
2 answers
273 views
Can't create an `std::array` of non-movable non-copyable objects with specific constructor
I am trying to make an array of 27 non-movable non-copyable objects and then use plain references to them.
https://godbolt.org/z/zYhrTxK6c
playground with the non-copyable non-movable object
Here's ...
Best practices
2
votes
27
replies
525
views
Seemingly bad design choices in C++? Why are things the way they are?
I'm learning about C++ multithreading, and the more I learn about it the more I start to question the design choices of the standard library.
Here are some examples:
std::thread's inability to simply ...
Advice
0
votes
3
replies
133
views
ankerl's dense map is slower than std::unordered_map?
Lately I've been running into some performance Issues with std's unordered_map, I use it mainly for hash wise lookup, e.g:
std::unordered_map<uint64_t, mpark::variant<int32_t, float>>
...
Score of 0
0 answers
272 views
std::array at function not throwing out of range
While debugging something I stumbled into this behavior on godbolt. When compiling and running the following (godbolt link https://godbolt.org/z/9c5966sbK):
#include <array>
int main()
{
...
Score of -2
1 answer
217 views
Implementation of std::string class members [duplicate]
class string {
struct long_mode {
size_t size;
size_t capacity;
char* buffer;
};
struct short_mode {
uint8_t size;
char buffer[23];
};
...
Score of 10
2 answers
406 views
Function object returning the nth item of a tuple
With std::ranges::max, it is possible to use a projection as follows
std::vector<std::tuple<char,int,double>> v = {
{'a',2,1.0}, {'c',1,3.0}, {'b',4,2.0}, {'d',3,4.0}
};
auto m = std::...
Advice
4
votes
22
replies
420
views
C/C++ standard string conversion functions don't support binary string literals?
Edit: Turns out the issue was an outdated glibc version, both on my computer and in all of the linked Godbolt examples. This issue does not occur with glibc versions >= 2.38 and the various string ...
Advice
1
vote
11
replies
102
views
troubles in including cpp headers
hope you are doing well guys i just have learnt how to build my own local library or what we call a header (MVS) and i built it within a project and everything was good, but when i have started new ...
Score of 0
0 answers
142 views
Linkage error using STD on Windows GCC 15.2.0
I follow How to use module `std` with gcc to generate "gcm.cache/std.gcm" on Windows using GCC 15.2.0 and ran g++ -std=c++23 -fmodules -fsearch-include-path -c bits/std.cc at "C:\bak\...
Score of 4
3 answers
358 views
Does std::atomic remain atomic when a struct is allocated with malloc?
I have a struct that contains a std::atomic member:
#include <atomic>
#include <cstdint>
struct Foo {
std::atomic<int64_t> value;
int64_t age;
};
If I allocate memory for ...
Score of 2
1 answer
369 views
Is std::system thread safe? If not, in which way?
Is std::system thread safe? If not, in which way? Clangd gives me warning about it, says this function is not thread safe. If not, I want to execute different task in a thread safe way, is there a ...
Score of 4
2 answers
417 views
CMake looks for `std.cppm` in wrong directory when using `import std`
Recently I've decided to "modularize" my library. No success. Here is the repo where you can find CMakeLists.txt & CMakePresets.json: kissra (GitHub)
The issue is that CMake cannot find ...