6,212 questions
Advice
3
votes
7
replies
249
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
207
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 ...
-1
votes
1
answer
226
views
What are the disadvantages of std::try_lock()?
I am currently studying the work of the mutex and I have a question, if we have the std::try_lock() method, then why not always use it instead of std::lock(), what are its disadvantages?
For example, ...
Advice
1
vote
7
replies
179
views
How does Microsofts std::lib implementation perform debug iterator checks?
In the question Why does Microsoft's implementation of std::string require 40 bytes on the stack? the observation is made, that a std::string requires 8 additional bytes in Debug mode.
After ...
0
votes
0
answers
80
views
Debug configuration build with OR'ing std::wregex constansts throws an unexpected std::regex_error exception
I'm compiling this with VS 2022 C++ compiler, as "ISO C++20 Standard (/std:c++20)" for a Debug configuration.
How come this throws the following std::regex_error:
regex_error(error_backref):...
6
votes
4
answers
283
views
Constexpr function that builds an integral value from a list of bits
Sometimes, it may be useful to build an integral value from a list of bits (in increasing order). Such a function could be named to_integral.
Example:
static_assert (to_integral(1,1,0,1,0,1) == ...
0
votes
0
answers
115
views
Does std::is_invocable_r with void as return type lead to UB?
Today I stumbled upon weird behavior of std::is_invocable_r.
While doing research for why it is happening, I stumbled upon this question on Stack Overflow:
is_invocable_r ignoring the return parameter
...
15
votes
1
answer
1k
views
Is it Undefined Behavior to backport namespace std features to older C++ versions?
According to What are the reasons that extending the std namespace is considered undefined behavior?, adding anything to namespace std is Undefined Behavior, with some exceptions carved out, such as ...
0
votes
1
answer
379
views
Apple Clang 21 unable to compile with c++ 23 stacktrace header
I am trying to use the C++ 23 stacktrace header in my project but I can't get it to compile. I've reproduced this with a minimal case to demonstrate the error I am getting. Any input would be greatly ...
5
votes
0
answers
202
views
Why is std::atomic<T> larger than T itself for user-defined structs on MSVC but not on GCC/Clang?
I was checking the size of std::atomic compared to T on different platforms (Windows/MSVC, Linux/GCC, Android/Clang).
For intrinsic types (like int, int64_t, etc.), the size of std::atomic matches the ...
0
votes
1
answer
137
views
Why template instantiation requires specialation in the case where it is already done for all cases?
In c++ when i try to write a code that returns reverse of a type list what i wrote( a user defined template class):
template <typename ...V,typename ...D>
constexpr decltype(auto) merge(...
5
votes
1
answer
143
views
Use std::regex_search called from module
I came across a strange problem. I made a C++20 module with the following content (file module.cppm):
module;
#include <regex>
#include <string>
export module foo;
export namespace bar {
...
1
vote
0
answers
166
views
Weird interaction between libstdc++ standard library headers and module
I'm using clang 21.1.0 from linuxbrew's LLVM package with libstdc++ from Fedora 42's repos (gcc 15.2.1). The following code compiles:
#include <memory>
#include <string>
auto main() -> ...
4
votes
2
answers
431
views
Including c++ standard headers from C not allowed, what should I use instead?
I'm trying to modernize an old code base that's written in a combination of C and C++.
My first task is to get it compiling with cl.exe v19.44.35214.
I'm getting a lot of this error in yvals_core.h:
#...
4
votes
2
answers
220
views
Can the back() iterator of a vector be safely assumed to be the end() iterator after a pop_back()?
My problem is the following :
std::vector<struct pollfd> vec = { ... }; // Actually a member variable on a Server object
for (auto iter = vec.begin(); iter != vec.end(); ) {
if (...