Re: Testing membership in associative array

2024-03-04 Thread Profunctor via Digitalmars-d-learn
My sincerest apologies, my initial solution is flawed due to a foolish oversight. The below version works. ```d bool contains(M, K...)(M map, K keys) if (K.length > 0) { static if (K.length == 1) return (keys[0] in map) !is null; else return (keys[0] in map) !is null && contains(map[

Re: Testing membership in associative array

2024-03-04 Thread Profunctor via Digitalmars-d-learn
On Monday, 4 March 2024 at 23:49:46 UTC, Lettever wrote: [ ... ] ```d // A template constraint is added to ensure we may always index into `keys`, // in addition to being a sanity check. bool contains(M, K...)(M map, K keys) if (K.length > 0) { static if (K.length == 1) return (keys[0]

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Profunctor via Digitalmars-d-learn
On Monday, 5 February 2024 at 21:12:58 UTC, Gary Chike wrote: [ ... ] In addition to the methods hitherto provided: ```d auto getUser() => tuple("John Doe", 32); // Name a Tuple's fields post hoc by copying the original's fields into a new Tuple. template named(names...) { auto named(T)