C++ Logo

std-proposals

Advanced search

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

From: organicoman <organicoman_at_[hidden]>
Date: Thu, 01 Aug 2024 02:55:50 +0400
Sent from my Galaxy
> This is called a mapping from int to int that means, if two functions stamped from the same template have the same mapping, then the same input gives the same output.> But with current C++ it is not the case.> Example:> template<int I>> int foo (int j)> {> return I * j;> }>> int main()> {> auto f1 = &foo<5>;> auto f2 = &foo<-3>;>> if(std::is_same_v<decltype(f1), decltype(f2)>)> cout << " f1(1) must equal f2(1) is" << boolalpha<< (f1(1)==f2(1));> }>> Try this snippet, and reason about it. That's all what i can say.But `foo<5>` and `foo<-3>` do not "have the same mapping" of `int` to`int`. As such, there is no reason to expect `f1(1)` and `f2(1)` to beequal.Two instantiations of the same template with different parametersgenerate different things. That's *how templates work*.`foo<5>` and`foo<-3>` are expected to be different functions with differentbehavior. Two different functions that have the same type are still*two different functions*.----Hello Jason,I guess you get exactly what i mean, you just want to argue.You say f1 has the same type as f2 , right?But at the same time they give me two different values.It is like you tell me int(1) != int(1) // same type different values.But I guess i understand what you told me once, a while back ago."Put 20 C++ expert in a room to fix a problem you will get 20 opinions and no solution"

Received on 2024-07-31 22:56:01