Is there a nicer way to get the first element or typeof(element).init from a range?
realhet
real_het at hotmail.com
Sun May 30 12:16:19 UTC 2021
Hello,
This is my current solution but there must be a better way to do
it in D
T get(T)(T[] arr, size_t idx, T def = T.init){
return idx<arr.length ? arr[idx]
: def;
}
.......
Preset[string] presets;
presets.keys.sort.take(1).get(0); <-----
Is there a prettier way to do this?
Thanks in advance.
More information about the Digitalmars-d-learn
mailing list