6,220 questions
Advice
0
votes
3
replies
92
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>>
...
-2
votes
0
answers
147
views
What does storing in buffer (for std::cout) actually mean? [duplicate]
std::cout stores values in a buffer and then prints them to the console.
I have this example:
#include <iostream>
int main() {
for(int i=0;i<10000;i++)
std::cout << "A&...
0
votes
0
answers
265
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()
{
...
-2
votes
1
answer
195
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];
};
...
10
votes
2
answers
388
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
386
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
98
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 ...
0
votes
0
answers
137
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\...
4
votes
3
answers
340
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 ...
2
votes
1
answer
345
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 ...
4
votes
2
answers
325
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 ...
6
votes
4
answers
266
views
Size mismatch of more than 2 arrays
Let's say I have n arrays (right now I have 4 but that might go up) and they're supposed to be of the same size, but since I'm fetching them from outside the code I want to be sure
std::vector<int&...
Advice
0
votes
10
replies
259
views
Valid but unspecified state. What is specified then?
The standard says that after a move, an object is in a "valid but unspecified state". I found nothing in the standard on the properties of being in a "specified state" and being in ...
Advice
3
votes
8
replies
341
views
Why do people use macros to declare namespaces in c++?
Off the top of my head, I only remember LLVM's standard library do this, but I remember seeing other libraries also do this. I'm not entirely sure what is the advantage here. I feel like namespace std ...
Advice
0
votes
6
replies
246
views
C++ compile type endianness for use in macros
I need to layout a structure in two different ways depending on the endianness of the target platform. Currently I'm using an additional pre-compile phase to run a program to test the endianness, and ...