blob: 02e4d7719aac9f4086210b2fcc4fc1f2e60652cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/**
* Implementation of dynamic array property support routines.
*
* Copyright: Copyright Digital Mars 2000 - 2015.
* License: Distributed under the
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
* (See accompanying file LICENSE)
* Authors: Walter Bright
* Source: $(DRUNTIMESRC rt/_adi.d)
*/
module rt.adi;
// debug = adi; // uncomment to turn on debugging printf's
debug (adi) import core.stdc.stdio : printf;
/***************************************
* Support for array equality test.
* Returns:
* 1 equal
* 0 not equal
*/
extern (C) int _adEq2(void[] a1, void[] a2, TypeInfo ti)
{
debug(adi) printf("_adEq2(a1.length = %zd, a2.length = %zd)\n", a1.length, a2.length);
if (a1.length != a2.length)
return 0; // not equal
if (!ti.equals(&a1, &a2))
return 0;
return 1;
}
@safe unittest
{
debug(adi) printf("array.Eq unittest\n");
struct S(T) { T val; }
alias String = S!string;
alias Float = S!float;
String[1] a = [String("hello"c)];
assert(a != [String("hel")]);
assert(a != [String("helloo")]);
assert(a != [String("betty")]);
assert(a == [String("hello")]);
assert(a != [String("hxxxx")]);
Float[1] fa = [Float(float.nan)];
assert(fa != fa);
}
unittest
{
debug(adi) printf("struct.Eq unittest\n");
static struct TestStruct
{
int value;
bool opEquals(const TestStruct rhs) const
{
return value == rhs.value;
}
}
TestStruct[] b = [TestStruct(5)];
TestStruct[] c = [TestStruct(6)];
assert(_adEq2(*cast(void[]*)&b, *cast(void[]*)&c, typeid(TestStruct[])) == false);
assert(_adEq2(*cast(void[]*)&b, *cast(void[]*)&b, typeid(TestStruct[])) == true);
}
|