metaprogramming - C++11 variadic template parameter expansion -


i following:

template<typename func> class functionwrapper { public:     typedef decltype(func()) returntype;     typedef ... argstype;      functionwrapper(func func)     {         func_ = func;     }      returntype operator() (argstype args)     {         return func_(args);     } private:     func func_; }; 

the problem don't know how deduce argstype func type. i'd make work when function returns/accepts nothing well.

the usecase be:

functionwrapper<myfunction> wrapper; auto result = wrapper(1, 2, 3); 

you can determine argument , return type(s) in operator() , use perfect forwarding:

template <typename func> class functionwrapper {     func func_;  public:      functionwrapper(func func) : func_(func) {}      template <typename... args>     auto operator() (args&&... args)       -> decltype(func_(std::forward<args>(args)...)) {         return    func_(std::forward<args>(args)...);     } }; 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -