@@ -4616,7 +4616,8 @@ enum SpanMode
4616
4616
[" animals" , " plants" ]));
4617
4617
}
4618
4618
4619
- private struct DirIteratorImpl
4619
+ private struct DirIteratorImpl (alias pred = (const scope ref DirEntry entry) => true)
4620
+ // TODO: if (is(typeof(pred(DirEntry.init)) : bool))
4620
4621
{
4621
4622
@safe :
4622
4623
SpanMode _mode;
@@ -4720,6 +4721,8 @@ private struct DirIteratorImpl
4720
4721
4721
4722
bool mayStepIn ()
4722
4723
{
4724
+ if (pred(_cur))
4725
+ return false ;
4723
4726
return _followSymlink ? _cur.isDir : _cur.isDir && ! _cur.isSymlink;
4724
4727
}
4725
4728
}
@@ -4863,11 +4866,12 @@ private struct DirIteratorImpl
4863
4866
}
4864
4867
}
4865
4868
4866
- struct DirIterator
4869
+ struct DirIterator (alias pred = (const scope ref DirEntry entry) => true)
4870
+ // TODO: if (is(typeof(pred(DirEntry.init)) : bool))
4867
4871
{
4868
4872
@safe :
4869
4873
private :
4870
- RefCounted! (DirIteratorImpl, RefCountedAutoInitialize.no) impl;
4874
+ RefCounted! (DirIteratorImpl! (pred) , RefCountedAutoInitialize.no) impl;
4871
4875
this (string pathname, SpanMode mode, bool followSymlink) @trusted
4872
4876
{
4873
4877
impl = typeof (impl)(pathname, mode, followSymlink);
@@ -4957,7 +4961,12 @@ foreach (d; dFiles)
4957
4961
+/
4958
4962
auto dirEntries (string path, SpanMode mode, bool followSymlink = true )
4959
4963
{
4960
- return DirIterator (path, mode, followSymlink);
4964
+ return DirIterator! ()(path, mode, followSymlink);
4965
+ }
4966
+ auto dirEntries (alias pred)(string path, SpanMode mode, bool followSymlink = true )
4967
+ // TODO: if (is(typeof(pred(DirEntry.init)) : bool))
4968
+ {
4969
+ return DirIterator! (pred)(path, mode, followSymlink);
4961
4970
}
4962
4971
4963
4972
// / Duplicate functionality of D1's `std.file.listdir()`:
@@ -5064,7 +5073,7 @@ auto dirEntries(string path, string pattern, SpanMode mode,
5064
5073
import std.path : globMatch, baseName;
5065
5074
5066
5075
bool f (DirEntry de) { return globMatch(baseName(de.name), pattern); }
5067
- return filter! f(DirIterator(path, mode, followSymlink));
5076
+ return filter! f(DirIterator! () (path, mode, followSymlink));
5068
5077
}
5069
5078
5070
5079
@safe unittest
0 commit comments