C++ Logo

std-proposals

Advanced search

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

From: organicoman <organicoman_at_[hidden]>
Date: Sat, 03 Aug 2024 00:53:04 +0400
Sent from my Galaxy
I wish you good day.I wish you a better day, thank you for your time, i appreciate you, sincerely not lying.As for the orhers, if we agree that the algorithm proposed is correct, then let me remind you what I said in earlier post."..The fun about this proposal, is the idea of inventing a compiler planner, that can prove at compile time what to generate.When to unroll a loop?When to stamp a switch function?How to consolidate different generated functions?...and so on..."So if the discussion is On then I'm willing to tackle that point.>>> >> > Sent from my Galaxy> >> >> > -------- Original message --------> > From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>> > Date: 8/2/24 9:40 PM (GMT+04:00)> > To: organicoman <organicoman_at_[hidden]>> > Cc: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>, std-proposals_at_[hidden]> > Subject: Re: [std-proposals] Function overload set type information loss> >> > pt., 2 sie 2024 o 18:35 organicoman <organicoman_at_[hidden]> napisał(a):> > >> > >> > >> > > Lest be charitable and assume you mean this code:> > >> > >> > > ```> > > template<typename T>> > > void foo() { cout <<typeid(T).name()<<endl;}> > >> > > auto useType(effdecltype(foo) f)> > > {> > > using T = __get_ortho_at__<0>(f);> > > f();> > > return T(0);> > > }> > >> > > template<typename T>> > > void consumeType(T t)> > > { cout << typeid(t).name(); }> > >> > > int main()> > > {> > >     vector<effdecltype(foo)> vec;> > >     vec.push_back(&foo<int>);> > >     vec.push_back(&foo<double>);> > > vec.push_back(&foo<float>);> > > for(int i=0; i<5; ++i)> > > vec.push_back(&foo<char>);> > > for(const auto& F: vec)> > > consumeType(useType(F));> > > }> > > ```> > >> > >> > > It can be easy fixed by helper:> > >> > >> > > ```> > > template<typename T>> > > void consumeTypeHelper()> > > {> > > foo<T>();> > > return consumeType(T{});> > > }> > >> > > int main()> > > {> > >     vector<void(*)()> vec;> > >     vec.push_back(&consumeTypeHelper<int>);> > >     vec.push_back(&consumeTypeHelper<double>);> > > vec.push_back(&consumeTypeHelper<float>);> > > for(int i=0; i<5; ++i)> > > vec.push_back(&consumeTypeHelper<char>);> > > for(const auto& F: vec)> > > F();> > > }> > > ```> > >> > > Done. Problem fixed in C++11> > >> >> >> >> >> >> > > Very good... nice try.> > > Unfortunately you miss the point.> > >> > > I showed a loop over a set of functions returning many types.> > > Imagine you have a container of slots, which returns different types ( i already said that many times)> > > Given the current state of C++ you can store them only as. Let say.> > > vector<std::any(*)(int, double)>> > > How can you tell what type the called function returned before it was hiden inside std::any?> > > Is it clear?> > >> > >> >> > Then show this code, I fixed your "example", now show code that can't> > be fixed in the same way.> > If you can't write it, then its means this code can't exist and is not> > a real life problem.

Received on 2024-08-02 20:53:14