variadic template class to make a deferred call to a variadic template function

前端 未结 2 629
无人共我
无人共我 2021-01-24 06:07

I can create a template class that stores some values in a property and let me later call a method that call a function with this arg. Like this :

template <         


        
2条回答
  •  离开以前
    2021-01-24 06:41

    http://ideone.com/OPl7Rz

    #include 
    #include 
    
    using namespace std;
    
    template
    void f(T... a)
    {
        std::initializer_list {(std::cout<
    class Defer
    {
        private:
            std::function func;
    
        public:
            Defer(T... a) : func(std::bind(f, a...)) {}
            void call() {func();}
    };
    
    
    
    int main()
    {
        Defer d(1, 1.1, 2, "Hey");
        d.call();
        return 0;
    }
    

提交回复
热议问题