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
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.