C++ Logo

std-proposals

Advanced search

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

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 2 Aug 2024 18:06:00 +0200
pt., 2 sie 2024 o 17:43 organicoman <organicoman_at_[hidden]> napisał(a):
>
>
>
> pt., 2 sie 2024 o 17:05 organicoman <organicoman_at_[hidden]> napisał(a):
> >
> >
> >> Did you read this paper at least once? Or is this too much to ask you?
> >
> > To be totally honest with you... it is too much asked.
> > Because i need to get used to concepts, coroutines, executors, TS papers......etc
> > When i say understand, that means master.
> > None of which i use in my daily job.
> > And I'm not an avid "new feature" consumer, if what i have is sufficient.
> >
> > Probably you are right, maybe i need to update gradually.
> >
>
> And you ask to change language even if a problem you had
> could be fixed 10 times by different features in C++26?
>




> As far as i recall, nobody posted here a solution using any of the new features of C++
>
> I gave you a problem about signal and slots, show me how you solve it using reflection.
> And please don't say "why do you want to use the return value of slots".
> Right down a solution and explain it to me, I am a good listener.
>

Because you do not show any real life problem here,
Nobody will do work to prepare solution for convoluted examples.

Besides, I already gave you a couple solutions for your "problem",
use `^foo<int>` operator and `std::vector<std::meta::info>`.

> >> Simply the whole loop body is hidden in the `Handle` helper.
> >> Show me real life problems that can't be handled like this.
> >
> > Please read the bottom of that post not it's top.
> >
>
> What post exactly? You make multiple and each one have
> diffrent code. Most cases was similar to one I posters here.
> Show exactly the code you mean and show
> why it can be handled by my `&Handle<&foo<int>>` helper.
>



> The post from where you copied this snippet.
> 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;
> }
> }
> -----
> Go all the way to the bottom, and read slowly and carefully.
> Then give me specific questions.

Please read slowly and carefully what I ask you to do.
I ask you to provide precise example, I have no idea what "loop"
you are referring to as there no other examples of "problems"
only your "solutions".

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

Received on 2024-08-02 16:06:14