1 /**
2     Dereferences an object depending on its type
3 */
4 module ddash.utils.deref;
5 
6 import ddash.common;
7 
8 /**
9     Dereferences a thing
10 
11     Could be a range, a pointer, or a nullable.
12 
13     Since:
14         - 0.0.1
15 */
16 auto ref deref(T)(auto ref T t) if (from!"std.traits".isPointer!T) {
17     return *t;
18 }
19 
20 /// Ditto
21 auto ref deref(T)(auto ref T t) if (from!"std.range".isInputRange!T) {
22     return t.front;
23 }
24 
25 import std.typecons: Nullable;
26 /// Ditto
27 auto ref deref(T)(auto ref Nullable!T t) {
28     return t.get;
29 }
30 
31 ///
32 unittest {
33     import std.typecons: nullable;
34     auto a = nullable(1);
35     auto b = new int(1);
36     auto c = [1];
37 
38     assert(a.deref == 1);
39     assert(b.deref == 1);
40     assert(c.deref == 1);
41 }