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