C++ Logo

std-proposals

Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 30 Jul 2024 17:05:30 +0200
Hi organicoman,   you are welcome. I wanted to help to focus on the center of your proposal. But as far as I understand the other people answering on this list so far, understood quite well, so take their feedback seriously.   In maths keeping some more information of operations sometimes works, sometimes not.     Example 1: Complex numbers You can extend the sqrt to the sqrt of negative numbers. You get the complex numbers, which are an important discovery.   Example 2: Principal values and roots But still, the root has not unique result, one defines a principal value instead and throws away other possibilities: https://en.wikipedia.org/wiki/Principal_value   Example 3: Infinity and division by zero The same with infinity and division by zero: If you can keep, how you got to infinity or division by zero, you can solve more equations. But there was no extension of the sets of numbers. Instead you can define a limes, which also is not always unique (e.g. could be different coming from the left or right side).     In C++ programmers often want to hide, where a type comes from and want to create a specific type. In your proposal:   int a = 4;   if (cond1)     a = globalVar1<double>; if (cond2)     a = globalVar2<float>;   Now you also cannot tell, where a is coming from, what its original type was.   The language can be much more complicated, with loops and function calls.   Why not insert the origin type you want into a custom type.   Create a new templated class, which implicitly converts to int. As long as it is not converted, you can retrieve the origin type. But you also can use it, wherever you would need an int.   Best, Sebastian    

Received on 2024-07-30 15:05:32