How can one make a variadic-based chained-indexing function?

后端 未结 2 1899
夕颜
夕颜 2021-02-10 00:54

If I have an object a that either a built-in array or a class-type with a suitable operator [], and its returned type can be indexed itself, how should

2条回答
  •  梦谈多话
    2021-02-10 01:22

    To get the right return value for the slice function, you can create a helper template that computes the correct result type. For example:

    template 
    struct SliceResult {
        typedef typename SliceResult::Type Type;
    };
    
    template 
    struct SliceResult {
        typedef typename std::underlying_type::type Type;
    };
    

    The slice function would then return a SliceResult<...>::Type.

提交回复
热议问题