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

Why would you advise someone "x should be implemented as an enum and not a sum type"? [closed]

I'm reading the design documentation for IPLD, and in a discussion about Kinds, it advises Kind must be an enum, and not a sum type. Attempting to implement kind as a sum type conflates it with Node. ...
user1713450's user avatar
  • 1,443
33 votes
2 answers
2k views

What's the point of deleted virtual functions?

Apparently you can =delete virtual functions: struct A { virtual void foo() = delete; }; struct B : A { void foo() override = delete; }; Interestingly, both functions have to be =deleted, or ...
HolyBlackCat's user avatar
  • 98.7k
5 votes
1 answer
191 views

Is there really not cross product in std::linalg and if yes why?

I know for sure how to calculate a cross product myself, but usually I tree to use the standard library where possible. I am aware that std::linalg is still in development so this might already be the ...
Torsten Knodt's user avatar
0 votes
2 answers
171 views

Why ISO C++ forbid taking the address of a bound member function to form a pointer to member function?

Here is the error in GCC (which i have already fixed): ISO C++ forbid taking the address of a bound member function to form a pointer to member function This is the error line of my code: threads[i] ...
stirner's user avatar
  • 11
0 votes
2 answers
173 views

Why is the virtual keyword applied to methods instead of classes

When the virtual keyword is applied to a method the whole class becomes abstract. Shouldn't the virtual or abstract keyword be applied to the class? It is a more intuitive design because it reflects ...
rishflab 's user avatar
13 votes
1 answer
429 views

Why doesn't the C++ standard implicitly define a lambda capturing nothing as `static` by default?

C++23 allows to define a lambda as static. i.e. If a lambda captures nothing, then it can be defined as static: // with superfluous argument `this`, less efficient. auto fn1 = [](int a, int b) { ...
xmllmx's user avatar
  • 42.6k
4 votes
1 answer
162 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
  • 30.1k
0 votes
1 answer
80 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
78 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
119 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
  • 98.7k
4 votes
1 answer
146 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
212 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.3k
3 votes
0 answers
46 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, ...
a_floating_point's user avatar
1 vote
3 answers
190 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
6 votes
1 answer
583 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,187

15 30 50 per page
1
2 3 4 5
98