ericniebler/meta

why does meta::for_each use a CTOR?

gabyx opened this issue · 1 comments

gabyx commented

I am wondering why the implementation of for_each uses the CTOR in f(Args{}).
The following constructs the HugeObj just to run the lambda:

struct HugeObj
    {
        HugeObj(){ std::cout << "Huge Obj CTOR";}
    };
meta::for_each(meta::list<HugeObj>{}, [](auto&&r){});

Wouldnt it better to have a pointer

meta::for_each(meta::list<HugeObj>{}, [](auto*p){});

or a Functor f with a templated invoke<T> function
where the implementation would look like this:

return (void)std::initializer_list<int>{((void)f.invoke<Args>()), 0)...}, f;
gabyx commented

Stupid question:
Wrapping the thing in another transformed list
meta::transform<meta::list<HugeObj>, meta::quote<meta::list>> resolves this problem...