Skip to main content
Filter by
Sorted by
Tagged with
Advice
2 votes
2 replies
58 views

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 ...
Somedude's user avatar
Advice
0 votes
6 replies
196 views

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 ...
Alnitak's user avatar
  • 341k
-1 votes
1 answer
225 views

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, ...
freakl's user avatar
  • 7
Advice
1 vote
7 replies
179 views

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 ...
Brandlingo's user avatar
  • 3,242
0 votes
0 answers
79 views

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):...
c00000fd's user avatar
  • 22.8k
6 votes
4 answers
283 views

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) == ...
abcdefg's user avatar
  • 4,637
0 votes
0 answers
114 views

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 ...
CygnusX1's user avatar
  • 22.1k
15 votes
1 answer
1k views

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 ...
Dominik Kaszewski's user avatar
0 votes
1 answer
374 views

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 ...
Keegan's user avatar
  • 19
5 votes
0 answers
202 views

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 ...
Abhishek's user avatar
  • 251
0 votes
1 answer
137 views

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(...
Hazret Hasanov's user avatar
5 votes
1 answer
143 views

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 { ...
d7d1cd's user avatar
  • 387
1 vote
0 answers
166 views

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() -> ...
rdong8's user avatar
  • 97
4 votes
2 answers
431 views

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: #...
Andy's user avatar
  • 3,658
4 votes
2 answers
220 views

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 (...
Azyrod's user avatar
  • 151
2 votes
1 answer
140 views

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, ...
Otto Lewis's user avatar
0 votes
0 answers
90 views

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 ...
MDF's user avatar
  • 9
2 votes
1 answer
220 views

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 <...
Stigl's user avatar
  • 61
4 votes
1 answer
295 views

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. ...
Hendrik's user avatar
  • 756
2 votes
1 answer
144 views

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<...
desynchedneo's user avatar
1 vote
2 answers
218 views

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) : ...
Mark Charsley's user avatar
10 votes
1 answer
174 views

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::...
Samonir's user avatar
  • 401
0 votes
1 answer
192 views

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 ...
sammyiscuul's user avatar
4 votes
0 answers
189 views

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 ...
alecov's user avatar
  • 5,262
3 votes
0 answers
67 views

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 ...
mkskeller's user avatar
3 votes
0 answers
73 views

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 ...
bers's user avatar
  • 6,309
2 votes
1 answer
706 views

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(...
cose's user avatar
  • 43
-2 votes
1 answer
310 views

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, ...
Neil Stephens's user avatar
3 votes
2 answers
99 views

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 ...
Gemini Em's user avatar
3 votes
3 answers
272 views

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 (...
Atul Rawat's user avatar
5 votes
1 answer
164 views

I'm trying to parallelize a part of a larger program using the C++ standard library and its execution policies. The original program uses std::accumulate to calculate sums over columns of 2d vectors (...
md-enthusiast's user avatar
26 votes
3 answers
2k views

In the following code: struct copy_only { copy_only() = default; copy_only(const copy_only&) = default; copy_only& operator=(const copy_only&) = default; ...
Fantastic Mr Fox's user avatar
0 votes
1 answer
126 views

I was trying to solve a coding problem and, to summarize, I was using this piece of code: char result[50005][26], buffer[50005]; while (fin >> buffer) { for (int i = 0; i < strlen(...
naphy's user avatar
  • 3
1 vote
1 answer
153 views

A while back I ported some of the C++ stdlib containers to environment where stdlib was not available. While iterators for contiguous and node-based containers were easy, I was stumped how to ...
Dominik Kaszewski's user avatar
2 votes
1 answer
235 views

Consider the following program: #include <array> int main() { throw std::logic_error("hi"); } With some C++ compilers (or rather, standard libraries) - this compiles. For example,...
einpoklum's user avatar
  • 137k
0 votes
0 answers
74 views

I am facing difficulties with my C++/SFML project that is focused on replicating the game of Blokus. I've been trying to get all the pieces to be seen in initial loading and am also unable to have the ...
Natasha Shorrock's user avatar
2 votes
0 answers
160 views

given the following MWE #include <iostream> #include <vector> #include <ranges> #include <algorithm> #include <numeric> namespace{ auto doSomething(const bool b) { ...
RocketSearcher's user avatar
3 votes
2 answers
187 views

I am porting a console application that was written in C targeting Linux. I want to make the code as portable as possible, so that it can also be used on Windows and other OSs. So far, I was able to ...
Dominik Kaszewski's user avatar
2 votes
1 answer
127 views

I have an object of type std::variant<std::monostate, T...>, but I need to call a function that only accepts std::variant<T...>. Is there a way I could convert a std::variant<std::...
gimbup's user avatar
  • 358
3 votes
2 answers
267 views

Why is push for std::queue<T, Container> defined as void push( const value_type& value ); void push( value_type&& value ); instead of a single member function with forwarding ...
zza's user avatar
  • 147
7 votes
1 answer
215 views

I would like to know if there is built-in checkers in std which checks if a type is printable via operator<< or if it is formattable via std::format. I tried to search it and could not find ...
sakcakoca's user avatar
  • 129
2 votes
1 answer
93 views

What I want to do I am working on a small discord bot to handle friendly bets on ESport matches with my friends. Lately I have been trying to add the date and hours of the matches to: Display only ...
Maeglix's user avatar
  • 55
0 votes
2 answers
224 views

Is it possible to make guaranteed alternating execution of two threads without using two atomics (or other stuff like semaphores, etc.)? I want to make sure the both threads execute, preferably if one ...
Damir Tenishev's user avatar
3 votes
0 answers
134 views

I have many threads which share access to the same pool of objects, and some threads could remove objects, so I use std::vector<std::shared_ptr<T>> to hold pointers to the objects so that ...
Damir Tenishev's user avatar
6 votes
0 answers
206 views

Rewriting the following function using std::find_if yields roughly 2x speed up, but only when given Intel CPU. bool process_update_range_based(int treeId, int newHeight, bool tall, ...
Vladislav Kogan's user avatar
10 votes
5 answers
683 views

I want to apply the same template algorithm to std::vectors which contain objects of some type T and (different) std::vectors which contain std::shared_ptrs to objects of some type T. Can I ...
Damir Tenishev's user avatar
2 votes
1 answer
137 views

I read that std::sort only accepts random access iterators. So, I expected to find code in the sort function that ensures only random access iterators are accepted, but I couldn't find any. Why is it ...
Code_JP's user avatar
  • 51
2 votes
0 answers
132 views

I want to pass a std::ranges::view to a function which is an implementation of an interface, without creating a new vector and allocating more memory. virtual void doSomethingWithInts(std::ranges::...
A-_-S's user avatar
  • 878
4 votes
1 answer
110 views

C++ 20 introduces std::ranges::iota_view. It may be used as part of a for loop, for example. for (auto i: std::ranges::iota_view(0, 10)) It appears to take two template parameters. For example, the ...
user2138149's user avatar
  • 18.7k
1 vote
1 answer
105 views

I'm working on a deterministic real time project which has an execution cycle per iteration of couple of hundred micro-seconds. I'm facing issue where by the push operation on a std::priority_queue ...
Dark Sorrow's user avatar
  • 2,041

1
2 3 4 5
125