Closed timotheecour closed 7 years ago
Why this should be simplified?
Figure plot(S)(S slice, GGPlotD gg, string title = "") if(isSlice!S)
is arguably more readable than
Figure plot(SliceKind kind, size_t[] packs, Iterator) (Slice!(kind, packs, Iterator) slice, GGPlotD gg, string title = "")
The older style should be used. After your change the following code would not work for example:
import mir.ndslice;
const s = slice!double(2, 3);
auto foo(SliceKind kind, size_t[] packs, Iterator) (Slice!(kind, packs, Iterator) slice)
{
slice.popFront;
}
foo(s);
I agree that (S) is simpler. But a DIP that strip const
should be implemented first .
isSlice
has a confusing name, isX should always be bool-return.
how about:
// before:
template isSlice(T) {
static if (is(T : Slice!(kind, packs, Iterator), SliceKind kind, size_t[] packs, Iterator))
enum size_t[] isSlice = packs[];
else
enum size_t[] isSlice = null;
}
// after: rename isSlice to getSlicePacks (and update code using it) and define:
template isSlice(T) {
enum isSlice = is(T : Slice!(kind, packs, Iterator), SliceKind kind, size_t[] packs, Iterator));
}
would that be acceptable? at least as PR?
isSlice
behaves as boolean if it is used as boolean. It just stores additional information that is very useful for generic code
here's an example:
could be simplified (and be more readable) with:
there are lots of such cases (search for SliceKind)