Skip to main content
4 votes
1 answer
154 views

Why doesn't std::array's operator[] retain the value category of the array?

I'd have expected that if an std::array is an rvalue, then calling operator[] returns an rvalue as well. But it doesn't seem to be the case (cppreference), there are no value-category overloads. For ...
geza's user avatar
  • 29.5k
0 votes
1 answer
70 views

A hash function that maintains mathematical equality (especially for sets)

I'm working on a little math-based programming language (written in Rust) that uses sets instead of types. In it, a variable or value belongs to a set of values (eg. x : {1, 2, 3} or msg : Str). The ...
Apuji's user avatar
  • 5
1 vote
1 answer
41 views

How to implement ordered fan-in (proper message passing for my language)?

I'm the creator of https://github.com/nevalang/neva It's a dataflow programming where you have nodes that do message passing through ports. I use go channels to implement that. However, I faced an ...
emil14's user avatar
  • 81
2 votes
2 answers
98 views

Why does `std::integral_constant` have a `::type` that refers to itself?

I'm reading the documentation on std::integral_constant, and apparently it includes using type that refers to itself. template <typename T, T Value> struct integral_constant { using type = ...
HolyBlackCat's user avatar
  • 94.4k
4 votes
1 answer
130 views

Why does the standard require only input iterators for std::distance, rather than forward iterators?

I was perplexed to see that the template parameter requirement for std::distance is a LegacyInputIterator rather than a LegacyForwardIterator. Since input-only iterators don't have the multi-pass ...
Spencer's user avatar
  • 2,214
3 votes
1 answer
167 views

Why there is no std::numbers::sqrtpi_v?

I have a std::normal_distribution<RealType> normal_distribution and want to use its normalization constant in a constexpr. Unfortunately, I cannot use normal_distribution.stddev() * std::sqrt(2 *...
0xbadf00d's user avatar
  • 18.1k
3 votes
0 answers
44 views

Why is the overload for both the == and <=> operator required to overload all comparison operators? [duplicate]

I was going through this guide on operator overloading in C++. If I try to implement all the comparison operators using the <=> operator: friend auto operator<=>(const Some_class& lhs, ...
user3612's user avatar
  • 367
1 vote
3 answers
176 views

Why don't STL containers have methods for general funcitons?

I understand that there are general functions on iterators that accomplish everything you would want to do, such as std::find, std::count etc. but why don't the standard containers such as std::vector ...
Daniel Barac's user avatar
3 votes
1 answer
288 views

Why `std::string_view` is not modifiable?

I start experiment with std::string_view. It has a very ugly feature. You cannot say: std::string_view<const char> and std::string_view<char> like the awesome std::span. So, you cannot ...
Chameleon's user avatar
  • 2,124
1 vote
1 answer
187 views

Why did C++03 allow data members with the same name as the class?

Between the C++98 standard and the C++03 standard, an interesting change was made: struct S { int S; }; This code is valid in C++03 and newer, but was ill-formed in C++98. Specifically, [class....
Jan Schultke's user avatar
  • 37.8k
2 votes
1 answer
80 views

Why is initialization of inline/non-inline variables indeterminately sequenced?

int x = f(); inline int y = x; It is unspecified whether y is zero or the value of x. Note that x has ordered initialization and y has partially-ordered initialization (see [basic.start.dynamic] p1). ...
Jan Schultke's user avatar
  • 37.8k
2 votes
1 answer
126 views

Why can't C++ overload resolution deduced nested template types?

This purported duplicate explains the mechanism of why this isn't allowed and shows a corner case where it can't work, but fails to address the question of why C++ refuses to allow it in the cases ...
BCS's user avatar
  • 78.1k
0 votes
2 answers
109 views

Why is it illegal to call offsetof() on pointer member?

From there I know that it is illegal in C to call offsetof on a pointer, but why is it undefined behaviour? Standard implementation #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)...
user avatar
0 votes
2 answers
54 views

Why is List<Subtype> able to be assigned to List<Supertype> here?

I understand that Java is generally invariant since it does not want to deal with issues of co/contra-variance. So in general, List<Parent> a = new ArrayList<Child>(); will require a type-...
user129393192's user avatar
5 votes
2 answers
219 views

Why are views required to be (move-)assignable?

The std::ranges::view concept in C++23 requires a view to be movable, which includes move-assignability. I understand why we want a view to be move-constructible, but why is the assignment necessary? ...
Nikola Benes's user avatar
  • 2,713

15 30 50 per page
1
2 3 4 5
98