1 /** 2 * TypeInfo support code. 3 * 4 * Copyright: Copyright Digital Mars 2004 - 2009. 5 * License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 * Authors: Walter Bright 7 */ 8 9 /* Copyright Digital Mars 2004 - 2009. 10 * Distributed under the Boost Software License, Version 1.0. 11 * (See accompanying file LICENSE or copy at 12 * http://www.boost.org/LICENSE_1_0.txt) 13 */ 14 module rt.typeinfo.ti_ptr; 15 16 // internal typeinfo for any pointer type 17 // please keep in sync with TypeInfo_Pointer 18 19 class TypeInfo_P : TypeInfo 20 { 21 @trusted: 22 const: 23 pure: 24 nothrow: 25 getHash(scope const void * p)26 override size_t getHash(scope const void* p) 27 { 28 size_t addr = cast(size_t) *cast(const void**)p; 29 return addr ^ (addr >> 4); 30 } 31 equals(in void * p1,in void * p2)32 override bool equals(in void* p1, in void* p2) 33 { 34 return *cast(void**)p1 == *cast(void**)p2; 35 } 36 compare(in void * p1,in void * p2)37 override int compare(in void* p1, in void* p2) 38 { 39 if (*cast(void**)p1 < *cast(void**)p2) 40 return -1; 41 else if (*cast(void**)p1 > *cast(void**)p2) 42 return 1; 43 else 44 return 0; 45 } 46 tsize()47 override @property size_t tsize() nothrow pure 48 { 49 return (void*).sizeof; 50 } 51 initializer()52 override const(void)[] initializer() const @trusted 53 { 54 return (cast(void *)null)[0 .. (void*).sizeof]; 55 } 56 swap(void * p1,void * p2)57 override void swap(void *p1, void *p2) 58 { 59 void* tmp = *cast(void**)p1; 60 *cast(void**)p1 = *cast(void**)p2; 61 *cast(void**)p2 = tmp; 62 } 63 flags()64 override @property uint flags() nothrow pure const { return 1; } 65 } 66