2 * This is a public domain version of qsort.d. All it does is call C's
5 * Copyright: Copyright Digital Mars 2000 - 2010.
6 * License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
7 * Authors: Walter Bright, Martin Nowak
10 /* Copyright Digital Mars 2000 - 2010.
11 * Distributed under the Boost Software License, Version 1.0.
12 * (See accompanying file LICENSE_1_0.txt or copy at
13 * http://www.boost.org/LICENSE_1_0.txt)
19 private import core.stdc.stdlib;
27 else version (WatchOS)
30 version (CRuntime_Glibc)
32 alias extern (C) int function(scope const void *, scope const void *, scope void *) Cmp;
33 extern (C) void qsort_r(scope void *base, size_t nmemb, size_t size, Cmp cmp, scope void *arg);
35 extern (C) void[] _adSort(return scope void[] a, TypeInfo ti)
37 extern (C) int cmp(scope const void* p1, scope const void* p2, scope void* ti)
39 return (cast(TypeInfo)ti).compare(p1, p2);
41 qsort_r(a.ptr, a.length, ti.tsize, &cmp, cast(void*)ti);
45 else version (FreeBSD)
47 alias extern (C) int function(scope void *, scope const void *, scope const void *) Cmp;
48 extern (C) void qsort_r(scope void *base, size_t nmemb, size_t size, scope void *thunk, Cmp cmp);
50 extern (C) void[] _adSort(return scope void[] a, TypeInfo ti)
52 extern (C) int cmp(scope void* ti, scope const void* p1, scope const void* p2)
54 return (cast(TypeInfo)ti).compare(p1, p2);
56 qsort_r(a.ptr, a.length, ti.tsize, cast(void*)ti, &cmp);
62 alias extern (C) int function(scope void *, scope const void *, scope const void *) Cmp;
63 extern (C) void qsort_r(scope void *base, size_t nmemb, size_t size, scope void *thunk, Cmp cmp);
65 extern (C) void[] _adSort(return scope void[] a, TypeInfo ti)
67 extern (C) int cmp(scope void* ti, scope const void* p1, scope const void* p2)
69 return (cast(TypeInfo)ti).compare(p1, p2);
71 qsort_r(a.ptr, a.length, ti.tsize, cast(void*)ti, &cmp);
77 private TypeInfo tiglobal;
79 extern (C) void[] _adSort(return scope void[] a, TypeInfo ti)
81 extern (C) int cmp(scope const void* p1, scope const void* p2)
83 return tiglobal.compare(p1, p2);
86 qsort(a.ptr, a.length, ti.tsize, &cmp);
95 debug(qsort) printf("array.sort.unittest()\n");
97 int[] a = new int[10];
110 _adSort(*cast(void[]*)&a, typeid(a[0]));
112 for (int i = 0; i < a.length - 1; i++)
114 //printf("i = %d", i);
115 //printf(" %d %d\n", a[i], a[i + 1]);
116 assert(a[i] <= a[i + 1]);