C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function overload set type information loss

From: Nathaniel Rupprecht <nathaniel.rupprecht_at_[hidden]>
Date: Wed, 31 Jul 2024 20:39:56 -0400
My proposal is trying to keep all information available about types, concerning only 3 categories of objects.
> -Arrays
> -Functions templates
> -Variable templates
> To achieve that we need a tool, in form of an operator, to record that lost information otherwise.
> This operator behaves exactly like its current counterparts so it will not break any existing code.
> But when used in some well defined manner it will trigger the compiler to do some type manipulation.

Again, and I you don’t seem to be addressing this or noticing this, what you are proposing is not correct in the slightest. Things like
```cpp
template<typename T>
inline constexpr int X = 1;

int main() {
  auto x1 = X<int>;
  auto x2 = X<double>;
}
```
do not have different type. This is a feature, not a bug. Literally, actually speaking `x1` and `x2` are the integer with value 1. They are both literally 1. And 1 has type int. Values do not carry a “history of how they were created.” You might as well say that
```cpp
auto y1 = 1 + 2;
auto y2 = 3 + 0;
```
Should have different types because they were added together in different ways, as if y1 should have type int<1 + 2> and y2 should have type int<3 + 0>!
This is all nonsense. You can of course write your own program that does things like this, or at least tries to, but this is not a feature that will ever be standardized.

> And pretending that something works is a logical way to find errors.
> 1- assume A is correct
> 2- Use it
> 3- if it give contradiction result, then your assumption is wrong
> 4- correct it
> 5- then repeat from 1.
>
> That's how usually we build softwares.

We are not talking about building software, if you want to make your own program that tries to reproduce this effect by like storing a pair in every vector and where the first element is data and the second is some object that you use to represent how this element was created or where it came from, no one is stopping you.

We are talking about the standard, and changes to it are usually based on identifying an actual need and how to change the standard to address that need, while also taking into account all the diverse use cases that real C++ users have.

Also, again, your “A” is not correct, so we are all kind of stuck at step 1. The problem seems to be in your flow chart since you, as you say, keep going back to step 1 when you hit 5 (though you keep skipping 4), where you again assume that A is correct! I think you need another step, like step 0, where you propose a new “A.”



Received on 2024-08-01 00:40:09