#33 Add functions to traits

Open jmh530

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -19,7 +19,7 @@
Loading
19 19
/**
20 20
   A reference-counted smart pointer similar to C++'s std::shared_ptr.
21 21
 */
22 -
struct RefCounted(Type,
22 +
struct RefCounted(RefCountedType,
23 23
                  Allocator = typeof(theAllocator),
24 24
                  Flag!"supportGC" supportGC = gcExists ? Flag!"supportGC".yes : Flag!"supportGC".no)
25 25
    if(isAllocator!Allocator)
@@ -30,6 +30,8 @@
Loading
30 30
    enum isSingleton = hasMember!(Allocator, "instance");
31 31
    enum isTheAllocator = is(Allocator == typeof(theAllocator));
32 32
    enum isGlobal = isSingleton || isTheAllocator;
33 +
    
34 +
    alias Type = RefCountedType;
33 35
34 36
    static if(isGlobal)
35 37
        /**

@@ -21,7 +21,7 @@
Loading
21 21
   A unique pointer similar to C++'s std::unique_ptr.
22 22
 */
23 23
struct Unique(
24 -
    Type,
24 +
    UniqueType,
25 25
    Allocator = typeof(theAllocator()),
26 26
    Flag!"supportGC" supportGC = gcExists ? Flag!"supportGC".yes : Flag!"supportGC".no
27 27
)
@@ -35,6 +35,8 @@
Loading
35 35
    enum isTheAllocator = is(Allocator == typeof(theAllocator));
36 36
    enum isGlobal = isSingleton || isTheAllocator;
37 37
38 +
    alias Type = UniqueType;
39 +
38 40
    static if(is(Type == class))
39 41
        alias Pointer = Type;
40 42
    else

@@ -43,3 +43,103 @@
Loading
43 43
    import std.experimental.allocator: theAllocator;
44 44
    enum isTheAllocator = is(Allocator == typeof(theAllocator));
45 45
}
46 +
47 +
/**
48 +
   Determines if a type is Unique.
49 +
 */
50 +
template isUnique(T) {
51 +
    import automem.unique: Unique;
52 +
    import std.traits: TemplateOf;
53 +
    enum isUnique = __traits(isSame, TemplateOf!T, Unique);
54 +
}
55 +
56 +
///
57 +
@("isUnique")
58 +
@safe unittest {
59 +
    import automem.unique: Unique;
60 +
61 +
    static struct Point {
62 +
        int x;
63 +
        int y;
64 +
    }
65 +
66 +
    auto u = Unique!Point(2, 3);
67 +
    static assert(isUnique!(typeof(u)));
68 +
69 +
    auto p = Point(2, 3);
70 +
    static assert(!isUnique!(typeof(p)));
71 +
}
72 +
73 +
/**
74 +
   The base type of a `Unique` pointer.
75 +
 */
76 +
template UniqueType(T)
77 +
{
78 +
    import automem.unique: Unique;
79 +
    static assert(isUnique!T);
80 +
    alias UniqueType = T.Type;
81 +
}
82 +
83 +
///
84 +
@("Get the base type of a Unique type")
85 +
@safe unittest {
86 +
    import automem.unique: Unique;
87 +
88 +
    static struct Point {
89 +
        int x;
90 +
        int y;
91 +
    }
92 +
93 +
    auto u = Unique!Point(2, 3);
94 +
    static assert(is(Point == UniqueType!(typeof(u))));
95 +
}
96 +
97 +
/**
98 +
   Determines if a type is RefCounted.
99 +
 */
100 +
template isRefCounted(T) {
101 +
    import automem.ref_counted: RefCounted;
102 +
    import std.traits: TemplateOf;
103 +
    enum isRefCounted = __traits(isSame, TemplateOf!T, RefCounted);
104 +
}
105 +
106 +
///
107 +
@("isRefCounted")
108 +
@safe unittest {
109 +
    import automem.ref_counted: RefCounted;
110 +
    
111 +
    static struct Point {
112 +
        int x;
113 +
        int y;
114 +
    }
115 +
116 +
    auto s = RefCounted!Point(2, 3);
117 +
    static assert(isRefCounted!(typeof(s)));
118 +
119 +
    auto p = Point(2, 3);
120 +
    static assert(!isRefCounted!(typeof(p)));
121 +
}
122 +
123 +
/**
124 +
   The base type of a `RefCounted` pointer.
125 +
 */
126 +
template RefCountedType(T)
127 +
{
128 +
    import automem.ref_counted: RefCounted;
129 +
    static assert(isRefCounted!T);
130 +
    alias RefCountedType = T.Type;
131 +
}
132 +
133 +
///
134 +
@("Get the base type of a RefCounted type")
135 +
@safe unittest {
136 +
    import automem.ref_counted: RefCounted;
137 +
138 +
    static struct Point {
139 +
        int x;
140 +
        int y;
141 +
    }
142 +
143 +
    auto s = RefCounted!Point(2, 3);
144 +
    static assert(is(Point == RefCountedType!(typeof(s))));
145 +
}

Learn more Showing 1 files with coverage changes found.

New file source/automem/traits.d
New
Loading file...
Files Coverage
source/automem 0.06% 97.55%
tests/ut 99.45%
Project Totals (12 files) 98.87%
Loading