If I have an object a, then either an inline array or a class type with a suitable one operator [], and its return type can be indexed myself, how can I write a general function that can index all of them with a variable call instead of a separate block of brackets? In other words, I can make expressions such as:
a[i0][i1]...[iK]
and I want to be able to write it as one function:
slice( a, i0, i1, ..., iK )
since C ++ rules require it to operator []work with single arguments, making it less compatible with variable material. (This question is based on the Usenet thread, where I tried asking for something like this, ultimately resolving only possible nested built-in arrays.)
First hit:
template < typename T, typename U >
constexpr
auto slice( T &&t, U &&u ) noexcept(???) -> ???
{ return ce_forward<T>(t)[ ce_forward<U>(u) ]; }
template < typename T, typename U, typename V, typename ...W >
constexpr
auto slice( T &&t, U &&u, V &&v, W... &&w ) noexcept(???) -> ???
{
return slice( ce_forward<T>(t)[ce_forward<U>(u)], ce_forward<V>(v),
ce_forward<W>(w)... );
}
ce_forward constexpr - std::forward. ( , constexpr, .) , . , , :
operator [] , ( ), - . . , ( ?) .operator [] - (-). ( this).- . ( UDT, .) undefined, , .
- l-, r
slice. - (final?) ,
std::is_nothrow_move_constructible<ReturnType>::value OR'd . ( - noexcept.) - , r-, . ( , , , l-v-r-value, l-value.)
- , ( ), . ,
this (const/volatile/both/none / &/&&/none).