Lazy range of hashes?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Aug 25 17:30:05 PDT 2012
On 8/26/12, bearophile <bearophileHUGS at lycos.com> wrote:
> This seems to work:
It seems it's as simple as defining a struct:
struct LazyHash(T...)
{
T hashes;
bool opIn_r(X)(X x)
{
foreach (hash; hashes)
{
if (x in hash)
return true;
}
return false;
}
}
auto lazyHash(T...)(T t)
{
return LazyHash!T(t);
}
void main()
{
auto x = ["foo" : 1];
auto y = ["bar" : 2];
assert("bar" in lazyHash(x, y));
assert("barx" !in lazyHash(x, y));
}
I didn't even have to define a ctor since field assignment works.
More information about the Digitalmars-d-learn
mailing list