Skip to main content

Questions tagged [c++]

For questions about C++'s design, or languages which are closely related to C++

7 votes
1 answer
841 views

Why might C++ have been designed to make types like std::strong_ordering a class instead of an enumeration?

In C++, std::strong_ordering has four valid values, yet instead of being an enumeration, it is a class. This seems weird to me, for it prevents std::strong_ordering from being used in a switch ...
ggZQX6YPvD's user avatar
-4 votes
3 answers
188 views

Did std::forward_list really need *_after member functions?

Did C++'s std::forward_list really need insert_after, emplace_after, ...
Dannyu NDos's user avatar
  • 1,485
8 votes
0 answers
151 views

Non-trivial implementations of consume memory ordering

In the C++ memory model through C++23, one of the memory ordering types for loads is memory_order_consume. The intent of this was to expose the feature that most ...
Nate Eldredge's user avatar
0 votes
1 answer
219 views

Why does C++ let some standard class templates lack definitions when not specialized, rather than to explicitly let them be unusable by default?

In the standard C++ library, some class templates lack definition, but are defined when their template is specialized. The most notable such class template is ...
Dannyu NDos's user avatar
  • 1,485
-2 votes
2 answers
224 views

Parallel like CUDA, safe like Rust [closed]

CUDA excels at parallel programming, but is primarily marketed for programming languages that have certain disadvantages compared to Rust, for example in terms of safety (C, C++) or speed (Python). ...
root's user avatar
  • 97
7 votes
3 answers
1k views

What aspects of a language design make copyability of an object possible or conditional to something?

I was reviewing the so-called prototype pattern, and I feel like in C++ it all boils down to "how do I define a virtual copy constructor" (and if you ...
Enlico's user avatar
  • 175
-1 votes
2 answers
546 views

If in computer science, compare-and-swap is known as "compare-and-swap," why are the C/C++ functions named atomic_compare_exchange_*?

In computer science, compare-and-swap is known as, well, "compare-and-swap" and often abbreviated as "CAS." Why are the functions in the standard C library and C++ library named <...
Paul J. Lucas's user avatar
7 votes
2 answers
343 views

Why can't a parser for C++ be realized with a DPDA?

In the book of Wilhelm, Seidl and Hack, " Compiler Design, Syntactic and Semantic Analysis" they write on p. 10 (bold face emphasis is mine) Most designers of programming languages have ...
Thomas Preu's user avatar
3 votes
1 answer
255 views

Is there any particular reason to only implement 2 and 3 input hypot?

I've checked the information on cppreference.com and found that there are only 2 and 3 input hypot function. I am wondering why not implement the variadic version ...
JimmyHu's user avatar
  • 165
0 votes
1 answer
429 views

How might I implement a `typeid` operator (returning the type of its argument as something, presumably as a string) in my compiler?

So, here is how strings work in my AEC-to-WebAssembly compiler. After the program is parsed, all strings except inline assembly ones are gathered in a C++ ...
FlatAssembler's user avatar
12 votes
0 answers
486 views

In C/C++, why does the logarithm of zero have a well-defined imaginary part?

By the C standard and the C++ standard: $\log(0+0i) = -\infty+0 i$. $\log(0-0i) = -\infty-0 i$. $\log(-0+0i) = -\infty+\pi i$. $\log(-0-0i) = -\infty-\pi i$. However, if the floating-point complex ...
Dannyu NDos's user avatar
  • 1,485
11 votes
0 answers
484 views

Why was && chosen as rvalue reference in C++?

I am NOT asking what && means. Does anyone know the history of why the symbol && was chosen? I can give some ...
sudo pkill depression's user avatar
16 votes
7 answers
6k views

How is clang able to evaluate loops without getting stuck in an infinite loop?

I recently saw this tweet. And for posterity, this is the C++ code: ...
JBraha's user avatar
  • 263
9 votes
1 answer
2k views

Why did std::set not have a contains function until C++20?

Another design decision that baffled me. Checking if an element is in a set is the entire purpose of a set! Until C++20 I had to write stuff like ...
qwr's user avatar
  • 591
16 votes
3 answers
5k views

Why did C++ standard library name the containers map and unordered_map instead of map and ordered_map?

This is something that has slightly annoyed me for a while. A map as a mathematical object (function) is by default "unordered", and the same is for maps as a data structure AKA associative ...
qwr's user avatar
  • 591

15 30 50 per page