C++之可变模板参数打印及Pari的逐块式构造(Piecewise Construction)

class Foo
{
public:
    Foo(tuple<int, double>)
    {
        cout << "Foo(tuple<int, double>)"<< endl;
    }
    template <typename T>
    void print(T t)
    {
        cout << t << endl;
    }

    template <typename T, typename ...Args>
    void print(T t, Args... args)
    {
        cout << t << endl;
        print(args...);
    }

    template <typename... Args>
    Foo(Args... args)
    {
        cout << __FUNCTION__ << "Foo(Args... args)"<< endl;
        //int arr[] = {(print(args), 0)...};
        print(args...);
    }
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
    auto tp = make_tuple(1,2.22);
    pair<int, Foo> p1(42, tp);
    pair<int, Foo> p2(piecewise_construct, make_tuple(41), tp);
    return a.exec();

}
 

 

 

 

posted on 2022-10-11 10:25  奔跑吧,蜗牛!  阅读(88)  评论(0编辑  收藏  举报

导航