C++ Logo

std-proposals

Advanced search

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

From: organicoman <organicoman_at_[hidden]>
Date: Fri, 02 Aug 2024 04:06:30 +0400
Sent from my Galaxy
-------- Original message --------From: Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> Date: 8/2/24 3:24 AM (GMT+04:00) To: std-proposals_at_[hidden] Cc: Jason McKesson <jmckesson_at_[hidden]> Subject: Re: [std-proposals] Function overload set type information loss On Thu, Aug 1, 2024 at 6:56 PM organicoman via Std-Proposals<std-proposals_at_[hidden]> wrote:>> Tiago,> I got your analogy perfectly, you are reiterating what you said about how much to allocate...etc.>> Allow me to explain:> 1- main motivation:> template<int T>> int F(int x) { return T * x + 1; }> int main()> {> vector<int(*)(int)> vec;> vec.push_back(&F<1>);> vec.push_back(&F<2>);> vec.push_back(&F<3>);>> for(const auto& f : vec)> {> cout << "function parameterized on t = " << /*some call to get the non-type template value*/ << endl;>> cout << "ret val =" << f(10) << endl;> }> }>> Despite the information about the template value is known, yet i connot access it from out side the function, why???"Known" by who? See, the fundamental problem is that the informationis not known. That's because it's not part of the function.Consider this:```int i = k + j;```Can I use `i` to access `k` or `j`? No.why???Because the value of `i` has already been computed by this expression.`k` and `j` were accessed, the results of access had `+` applied, andthe result of that was coerced into an `int` for storage into `i`.From that point forward, `k` and `j` are *completely uninvolved* with`i`. You cannot reach back and access `k` or `j` through `i`.A function pointer is a *value*. And that value works like *everyother kind of value* in C++. It gets computed and it gets stored, butyou cannot use the stored value to reach back and interrogate *how*that value got there.The expression `&F<1>` computes the value of a function pointer. Thatvalue does not in any way contain any information about `F` or `1`.The value itself does not know how it got there; all it knows is thatit has a certain value. As such, you cannot reach through that valueto figure out how it got there, to query properties about how thatvalue came to be.The thing you're trying to do is introspect the compile timeproperties of the expression that led to the production of a runtimevalue.> Maybe i want to create an abacus of that function against the value of T!!> That's the whole purpose of my proposal.That's not motivation though; it's an artificial example of how thefeature can be used. The question is what problem it solves. Show aproblem, preferably one that real C++ programmers face, which thisproposal will solve.Thank you Jason for your discussion, honestly.But I already wasted 3 days of my vacation on this.I'm drained and not motivated at all now.So let's just agree to disagree.The proposal is there for any one, free of charges.Thank you guys.

Received on 2024-08-02 00:06:43