ericniebler / meta

A tiny metaprogramming library
Boost Software License 1.0
302 stars 47 forks source link

why does meta::for_each use a CTOR? #58

Closed gabyx closed 5 years ago

gabyx commented 6 years ago

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 5 years ago

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