Skip to content

Commit 39e9080

Browse files
committed
Merge pull request #44 from burner/notnothrow
Fix Issue #43
2 parents c99dd0b + 98a9df3 commit 39e9080

File tree

8 files changed

+146
-5
lines changed

8 files changed

+146
-5
lines changed

src/containers/cyclicbuffer.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,13 @@ unittest
792792
b.reserve(b.capacity + 1);
793793
assert(equal(b[], [7, 6, 0, 1, 2, 3, 4, 5]));
794794
}
795+
796+
unittest
797+
{
798+
static class Foo
799+
{
800+
string name;
801+
}
802+
803+
CyclicBuffer!Foo b;
804+
}

src/containers/hashmap.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,16 @@ unittest
481481
hm3[100] = 1;
482482
assert (hm3.get(100, 20) == 1);
483483
}
484+
485+
unittest
486+
{
487+
static class Foo
488+
{
489+
string name;
490+
}
491+
492+
auto hm = HashMap!(string, Foo)(16);
493+
auto f = new Foo;
494+
hm.insert("foo", f);
495+
assert("foo" in hm);
496+
}

src/containers/hashset.d

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ struct HashSet(T, Allocator = Mallocator, alias hashFunction = generateHash!T,
119119
/**
120120
* Returns: true if value is contained in the set.
121121
*/
122-
bool contains(T value) inout nothrow
122+
bool contains(T value) inout
123123
{
124124
return (value in this) !is null;
125125
}
126126

127127
/**
128128
* Supports $(B a in b) syntax
129129
*/
130-
inout(T)* opBinaryRight(string op)(T value) inout nothrow if (op == "in")
130+
inout(T)* opBinaryRight(string op)(T value) inout if (op == "in")
131131
{
132132
if (buckets.length == 0 || _length == 0)
133133
return null;
@@ -634,3 +634,28 @@ unittest
634634
auto h = new AStruct(10, 10);
635635
assert(h in fred);
636636
}
637+
638+
unittest
639+
{
640+
static class Foo
641+
{
642+
string name;
643+
}
644+
645+
hash_t stringToHash(string str) @safe pure nothrow @nogc
646+
{
647+
hash_t hash = 5381;
648+
return hash;
649+
}
650+
651+
hash_t FooToHash(Foo e) pure @safe nothrow @nogc
652+
{
653+
return stringToHash(e.name);
654+
}
655+
656+
HashSet!(Foo, Mallocator, FooToHash) hs;
657+
auto f = new Foo;
658+
hs.insert(f);
659+
assert(f in hs);
660+
auto r = hs.range();
661+
}

src/containers/openhashset.d

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct OpenHashSet(T, Allocator = Mallocator,
123123
* Returns:
124124
* $(B true) if the hash set contains the given item, false otherwise.
125125
*/
126-
bool contains(T item) const nothrow @safe
126+
bool contains(T item) const
127127
{
128128
if (empty)
129129
return false;
@@ -135,7 +135,7 @@ struct OpenHashSet(T, Allocator = Mallocator,
135135
}
136136

137137
/// ditto
138-
bool opBinaryRight(string op)(T item) inout nothrow if (op == "in")
138+
bool opBinaryRight(string op)(T item) inout if (op == "in")
139139
{
140140
return contains(item);
141141
}
@@ -282,7 +282,7 @@ private:
282282
* Returns:
283283
* size_t.max if the item was not found
284284
*/
285-
static size_t toIndex(const Node[] n, T item, size_t hash) nothrow @safe
285+
static size_t toIndex(const Node[] n, T item, size_t hash)
286286
{
287287
immutable size_t bucketMask = (n.length - 1);
288288
immutable size_t index = hash & bucketMask;
@@ -354,3 +354,34 @@ unittest
354354
assert (ohs.remove(0));
355355
assert (ohs.remove(1));
356356
}
357+
358+
unittest
359+
{
360+
static class Foo
361+
{
362+
string name;
363+
364+
override bool opEquals(Object other) const @safe pure nothrow @nogc
365+
{
366+
Foo f = cast(Foo)other;
367+
return f !is null && f.name == this.name;
368+
}
369+
}
370+
371+
hash_t stringToHash(string str) @safe pure nothrow @nogc
372+
{
373+
hash_t hash = 5381;
374+
return hash;
375+
}
376+
377+
hash_t FooToHash(Foo e) pure @safe nothrow @nogc
378+
{
379+
return stringToHash(e.name);
380+
}
381+
382+
OpenHashSet!(Foo, Mallocator, FooToHash) hs;
383+
auto f = new Foo;
384+
hs.insert(f);
385+
assert(f in hs);
386+
auto r = hs.range();
387+
}

src/containers/slist.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,15 @@ unittest
284284
l ~= "fghij";
285285
assert (l.length == 2);
286286
}
287+
288+
unittest
289+
{
290+
static class Foo
291+
{
292+
string name;
293+
}
294+
295+
SList!Foo hs;
296+
auto f = new Foo;
297+
hs.put(f);
298+
}

src/containers/treemap.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,15 @@ unittest
184184
assert(equal(tm.keys, a));
185185
assert(equal(tm.values, repeat(0).take(a.length)));
186186
}
187+
188+
unittest
189+
{
190+
static class Foo
191+
{
192+
string name;
193+
}
194+
195+
TreeMap!(string, Foo) tm;
196+
auto f = new Foo;
197+
tm["foo"] = f;
198+
}

src/containers/ttree.d

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,3 +1164,23 @@ unittest
11641164
assert(allocator.bytesUsed == 0);
11651165
}
11661166
}
1167+
1168+
unittest
1169+
{
1170+
static class Foo
1171+
{
1172+
string name;
1173+
1174+
this(string s)
1175+
{
1176+
this.name = s;
1177+
}
1178+
}
1179+
1180+
TTree!(Foo, Mallocator, false, "a.name < b.name") tt;
1181+
auto f = new Foo("foo");
1182+
tt.insert(f);
1183+
f = new Foo("bar");
1184+
tt.insert(f);
1185+
auto r = tt.range();
1186+
}

src/containers/unrolledlist.d

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,21 @@ unittest
599599
static assert (is (typeof(objs.front) == const));
600600
static assert (is (typeof(objs[].front) == const));
601601
}
602+
603+
unittest
604+
{
605+
static class A
606+
{
607+
int a;
608+
int b;
609+
610+
this(int a, int b)
611+
{
612+
this.a = a;
613+
this.b = b;
614+
}
615+
}
616+
617+
UnrolledList!(A) objs;
618+
objs.insert(new A(10, 11));
619+
}

0 commit comments

Comments
 (0)