6,201 questions
0
votes
1
answer
76
views
C++ Enum storage size conversion prevention
Is is possible to prevent explicit enum storage size conversions? I tried overloading = but this does not seem to work on primitive types.
enum GlobalSettingTableType : std::uint16_t
{
first = 0,
...
0
votes
0
answers
81
views
C++ wofstream/wifstream: problems with numeric values in binary format
I'm trying to use std::wofstream/wifstream to serialize/deserialized mixed numerical (e.g., int, double) and std::wstring content, with the numerical values serialized in binary mode. But the ...
2
votes
1
answer
179
views
std::unique() algorithm returns clearly non-unique results [duplicate]
I have been experimenting with C++'s std::unique() algorithm, but the results it returns really confuse me.
I have done a simple function to test it, like so:
#include <algorithm>
#include <...
4
votes
1
answer
260
views
Pros and cons of make_unique vs direct constructor call in C++17 [closed]
The function std::make_shared<T>() is most often preferred to std::shared_ptr<T> {new T}, because it will only make one allocation, as opposed to two allocations in the second example. ...
2
votes
1
answer
132
views
Using std::move with Constructor(Type t) or Constructor(Type&& t). What's the difference?
I'm studying std::move semantics and I would like this to be clarified to me:
Say I have:
// Message.h
class Message
{
private:
std::array<uint8_t, BUFFER_SIZE> buffer;
std::queue<...
1
vote
2
answers
183
views
C++ map whose key is a string within the value
Say I have a C++ class containing an id:
class MyData {
std::string _id;
std::vector<int> _stuff;
public:
const std::string& id() { return _id; }
MyData(std::string id) : ...
9
votes
1
answer
132
views
How to correctly determine the seed type for the various random number engines in the c++ standard library
Recently there was a discussion on the reddit c++ subedit pertaining to the difficulties of using the random library. One of the issues was how to correctly seed a random number engines.
std::...
0
votes
1
answer
135
views
std::cout not working. Code runs, but just prints absolutely nothing [closed]
Here is the extremely simple code in C++:
#include <iostream>
int main() {
std::cout << "hello world" << std::endl;
return 0;
}
When I purposefully create an ...
4
votes
0
answers
154
views
Questions regarding the new C++ fixed-width floating-point types in C++23
With the introduction of the new fixed-width floating point types in C++23 (the std::floatN_t types in <stdfloat>), some guarantees regarding the representation of floating-point types are not ...
3
votes
0
answers
57
views
Named pipes/FIFO stalling on macOS with C++
The code below works as expected on Linux when run as follows:
mkfifo /tmp/{a,b}
./a.out 0 & ./a.out 1 &
results in
hello
bye
hello
bye
...
On macOS, however, it just stalls. It seems that ...
3
votes
0
answers
40
views
Can I choose where Visual Studio builds "ISO C++23 Standard Library Modules"?
I have Visual Studio 2022 v17.14.1 compile ISO C++23 Standard Library Modules according to the setting below in several projects:
Unfortunately, each project seems to compile their own copy of the ...
1
vote
1
answer
319
views
cmake ignores CMAKE_EXPERIMENTAL_CXX_IMPORT_STD flag regardless of when it is called
I have a very simple script:
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")
set(CMAKE_CXX_MODULE_STD 1)
project(...
-2
votes
1
answer
172
views
can't find libc++ packages on el9
I have a c++ application that I automatically build and release for various platforms. I use docker images to build for Linux distros.
Recently I ran into a libstdc++ bug in std::regex (very old, ...
3
votes
2
answers
94
views
Cannot detect protected base class method with SFINAE
I attempted the following approach using c++ SFINAE and std::declval to find if there exists the proper method in a base class, that can be called from the derived class. The derived class gets the ...
3
votes
3
answers
178
views
Why does std::filesystem::absolute resolve . and .. on Windows but not on POSIX platforms?
I'm using C++17's std::filesystem::absolute to convert relative paths to absolute ones. I noticed that on Windows (MSVC), this function seems to resolve . and .. components in the path, but on Linux (...