Template help
Anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jul 12 14:20:00 PDT 2014
One way I've used it in code
struct MapBy(T,string key) if (hasDeepMember!(T,key)) {
alias key_t = DeepMemberType!(T,key);
private const(T)[key_t] _map;
bool has(key_t id) const nothrow {
if ((id in _map) != null) return true;
else return false;
}
void put(in ref T val) pure nothrow {
auto id = val.Extract!key;
_map[id] = val;
}
ref const(T) get(key_t id) const nothrow {
assert(has(id));
return _map[id];
}
}
More information about the Digitalmars-d-learn
mailing list