Skip to content

Commit

Permalink
refactor error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Feb 22, 2016
1 parent f6e274a commit 5e1146e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
5 changes: 5 additions & 0 deletions std/experimental/ndslice/internal.d
Expand Up @@ -5,6 +5,11 @@ import std.meta; //: AliasSeq, anySatisfy, Filter, Reverse;

package:

enum string indexStrideAssertMsg(size_t i, size_t N) =
"index at position "
~ i.stringof ~ " (from the range [0 .." ~ N.stringof ~ ")) "
~ " must be less than corresponding length.";

enum string tailErrorMessage(
string fun = __FUNCTION__,
string pfun = __PRETTY_FUNCTION__) =
Expand Down
20 changes: 4 additions & 16 deletions std/experimental/ndslice/slice.d
Expand Up @@ -886,10 +886,7 @@ struct Slice(size_t _N, _Range)
size_t stride;
foreach (i; Iota!(0, N)) //static
{
assert(_indexes[0][i] < _lengths[i],
"indexStride: index at position "
~ i.stringof ~ " (from the range [0 .." ~ N.stringof ~ ")) "
~ " must be less than corresponding length");
assert(_indexes[0][i] < _lengths[i], indexStrideAssertMsg!(i, N) ~ tailErrorMessage!());
stride += _strides[i] * _indexes[0][i];
}
return stride;
Expand All @@ -899,10 +896,7 @@ struct Slice(size_t _N, _Range)
size_t stride;
foreach (i, index; _indexes) //static
{
assert(index < _lengths[i],
"indexStride: index at position "
~ i.stringof ~ " (from the range [0 .." ~ N.stringof ~ ")) "
~ " must be less than corresponding length");
assert(index < _lengths[i], indexStrideAssertMsg!(i, N) ~ tailErrorMessage!());
stride += _strides[i] * index;
}
return stride;
Expand All @@ -917,10 +911,7 @@ struct Slice(size_t _N, _Range)
size_t stride;
foreach_reverse (i; Iota!(0, N)) //static
{
assert(_indexes[0][i] < _lengths[N - 1 - i],
"mathIndexStride: index at position "
~ i.stringof ~ " (from the range [0 .." ~ N.stringof ~ ")) "
~ " must be less than corresponding length");
assert(_indexes[0][i] < _lengths[N - 1 - i], indexStrideAssertMsg!(i, N) ~ tailErrorMessage!());
stride += _strides[N - 1 - i] * _indexes[0][i];
}
return stride;
Expand All @@ -930,10 +921,7 @@ struct Slice(size_t _N, _Range)
size_t stride;
foreach_reverse (i, index; _indexes) //static
{
assert(index < _lengths[N - 1 - i],
"mathIndexStride: index at position "
~ i.stringof ~ " (from the range [0 .." ~ N.stringof ~ ")) "
~ " must be less than corresponding length");
assert(index < _lengths[N - 1 - i], indexStrideAssertMsg!(i, N) ~ tailErrorMessage!());
stride += _strides[N - 1 - i] * index;
}
return stride;
Expand Down

0 comments on commit 5e1146e

Please sign in to comment.