Creating a sub-tuple starting from a std::tuple

前端 未结 4 1426
深忆病人
深忆病人 2021-01-18 18:29

Let us suppose that a std::tuple is given. I would like to create a new std::tuple whose types are the ones indexed in [

4条回答
  •  离开以前
    2021-01-18 19:00

    Subrange from tuple with boundary checking, without declaring "helper classes":

    template ())>
    struct sub_range;
    
    template 
    struct sub_range, std::index_sequence>
    {
        static_assert(elems <= sizeof...(args) - starting, "sub range is out of bounds!");
        using tuple = std::tuple> ...>;
    };
    

    Usage:

    struct a0;
    ...
    struct a8;
    
    using range_outer = std::tuple;
    sub_range<2, 3, range_outer>::tuple; //std::tuple
    

提交回复
热议问题