Produce std::tuple of same type in compile time given its length by a template argument

前端 未结 5 1883
礼貌的吻别
礼貌的吻别 2021-02-13 10:18

In c++, how can I implement a function with an int template argument indicating the tuple length and produce a std::tuple with that length?

E.g.

func<         


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-02-13 10:40

    Here are two boost.hana solutions (C++14):

    //first
    hana::replicate(int{}, hana::size_c<2>);
    
    //second
    hana::cycle(std::make_tuple(int{}), hana::size_c<2>);
    

    Both produce integer-tuples of size 2, but instead of std::tuples they yield hana::tuples.

提交回复
热议问题