Skip to main content
Filter by
Sorted by
Tagged with
2 votes
0 answers
42 views

Let's say that we have a simple main.cpp file which contains only a single call of a function bar which is defined in the module a: import a; int main() { bar(1); } Then let's take a look at the ...
siga's user avatar
  • 451
5 votes
6 answers
233 views

Let's say I have the following code: #include <array> #include <string> #include <variant> using namespace std::literals; using known_types_t = std::variant<int, double, char>...
Miguel Horta's user avatar
-3 votes
1 answer
112 views

Overloading 3-way comparison operator. I am a bit confused when it comes to the 3-way comparison operator. I don't understand why the two return types, that I listed below, are used with the 3-way ...
JAYD3V's user avatar
  • 12.6k
4 votes
2 answers
148 views

I am implementing type-erased iterators for code that uses std::views and have found a problem while trying to compare values that wrap sentinels. Basically, it seems that for some composition of ...
Krzysiek Karbowiak's user avatar
9 votes
1 answer
288 views

Here is a possibly incorrect program for communicating between a function and a signal handler that might interrupt it. Assume that HandleSignal has been arranged to run as a signal handler. The ...
jacobsa's user avatar
  • 7,817
6 votes
1 answer
336 views

Before I get to my main question, I'm assuming that std::mutex::unlock() stops touching this as soon as it puts the mutex in a state where another thread might lock it - even though the call to unlock(...
user3188445's user avatar
  • 4,980
0 votes
0 answers
132 views

I have the below code with the below output: #include <iostream> #include <string> using namespace std; class P { public: P() { cout << "P() ctor" << ...
yapkm01's user avatar
  • 3,811
0 votes
5 answers
280 views

Assume I have a bunch of different enum classes. Further I have a general handler that can work with int values. The handler is in an UI layer, that cannot be templated. It uses the int-converted ...
king_nak's user avatar
  • 11.7k
21 votes
4 answers
2k views

I have three std::vectors, std::vector<std::string> vec1{ "one", "two", "three" }; std::vector<std::string> vec2{ "1", "2", "3" }...
RocketSearcher's user avatar
21 votes
1 answer
653 views

C++ allows us to make union class type without any data members. (cppreference even contain an example with it.) Can one request the compiler to provide default implementation of equality comparison ...
Fedor's user avatar
  • 24.7k
3 votes
6 answers
200 views

I have some tricky code that I need to initialize many objects that refer to each other. I want to allocate and construct them all at once, so I put them all in a struct. It looks like this: // User ...
Guillaume Racicot's user avatar
-3 votes
1 answer
205 views

I'm trying to iterate through a text file's lines using ranges: auto iter_lines(std::ifstream& file) { auto lines = std::ranges::istream_view<char>(file) | std::views::lazy_split(...
aviad1's user avatar
  • 376
2 votes
1 answer
236 views

The following integer power function returns 0 when the result should be greater than 2^32 if the base argument is unsigned int, but works fine when the base argument type is changed to an unsigned ...
user31597808's user avatar
6 votes
0 answers
447 views

Consider this example: #include <atomic> #include <thread> #include <cassert> int main(){ std::atomic<int> v = 0; std::atomic<bool> flag = false; std::thread ...
xmh0511's user avatar
  • 7,618
5 votes
1 answer
175 views

This works, but is it legal/safe? (i.e.: Is it okay to pass projection as predicate argument to std::ranges::any_of/all_of/none_of?) #include <ranges> #include <iostream> #include <...
Garux's user avatar
  • 83
-1 votes
1 answer
137 views

We read files that can contain all kinds of data types, which we normalize before further processing. This also works with MSVC, GCC, and Clang on my PC. However, GCC does strange things on our CI. ...
SunBlack's user avatar
  • 177
1 vote
0 answers
57 views

What is the category of std::views::transform based on a std::vector? What is the category of the view's iterator in the following code? #include <iterator> #include <memory> #include <...
Krzysiek Karbowiak's user avatar
21 votes
2 answers
2k views

Consider: #include <print> #include <set> struct Num { auto operator <=> (const Num& other) const{ std::println ("{} <=> {}", val, other.val); ...
NoSenseEtAl's user avatar
  • 30.9k
4 votes
1 answer
496 views

Consider the following struct: struct Particle { float scale; float opacity; float rotation; }; I want the following to compile: static_assert(indexOf<&Particle::scale>() == 0); ...
Vittorio Romeo's user avatar
10 votes
0 answers
176 views

MSVC doesn't accept this code, even the latest version on Godbolt: #include <type_traits> template <class R> struct A { A(); }; template <class R> requires std::is_reference_v&...
Brian Bi's user avatar
  • 123k
5 votes
1 answer
167 views

The libstdc++ implementation of std::ranges::ref_view, following the C++ standard, includes the following code: template<range _Range> requires is_object_v<_Range> class ref_view : ...
Fei Du's user avatar
  • 80
2 votes
1 answer
176 views

I found some (for me) unexplainable behaviour in VS2022 and C++20 with static_assert(std::forward_iterator<my_iterator<...>>), looks to me broken or I'm not using it in a correct fasion. ...
PapaAtHome's user avatar
0 votes
2 answers
166 views

I am implementing a non-intrusive idle objectpool in C++ using a union inside a struct, Does this code violate the strict aliasing rule? The goal is to reuse memory for objects of type T while also ...
likecpp's user avatar
  • 21
9 votes
2 answers
586 views

My game engine in C++ using modules from C++20. class A contains unique_ptr of class B, class B contains regular pointer to class A and unique_ptr to class C, and this structure continues for 4 levels ...
Work Steve's user avatar
0 votes
0 answers
134 views

I read some QA about these two operations. But I still don't understand. acquire-release-versus-sequentially-consistent-memory-order Can I understand the difference between memory_order_acq_rel and ...
breaker00's user avatar
  • 195

1
2 3 4 5
123