Skip to content

Commit

Permalink
add ptr method for slice
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 26, 2016
1 parent f8eaa9d commit 8629b11
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions std/experimental/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,29 @@ struct Slice(size_t _N, _Range)
_ptr._range = range;
}

/++
Returns:
pointer to the first element of a slice if slice is defined as `Slice!(N, T*)` or
plain structure with two fields `shift` and `range` otherwise. In second case the expression `range[shift]`
refers to the first element. For slices with named elements the type of a return value has the same behavior like a pointer.
Note:
`ptr` is defined only for not packed slices.
Attention:
`ptr` refers to the first element in the memory representation if and only if all strides are positive.
+/
static if (is(PureRange == Range))
auto ptr() @property
{
static if (hasPtrBehavior!PureRange)
{
return _ptr;
}
else
{
static struct Ptr { size_t shift; Range range; }
return Ptr(_ptr._shift, _ptr._range);
}
}

/++
Returns: static array of lengths
Expand Down

0 comments on commit 8629b11

Please sign in to comment.