Re: Checking if something is a template specialization?
On Fri, 18 Feb 2011 02:02:51 +, Sean Eskapp wrote: If I have class Bar(T) { } void foo(Y)() { ... } Is there a way to check inside foo() that Y is in some way an instantiation of Bar? Is there a way to find WHICH instantiation it is? void foo(Y)() { static if (is(Y Z == Bar!Z)) { // Here, Z is now an alias to whichever type Bar is // instantiated with. } else { // Z is invalid here. } }
Re: BigInt problem
tsukikage wrote: Please see source in attachment. The output is M2 M3 M5 M7 M13 M17 M19 M31 M61 M89 M107 M127 M521 M607 M1279 M2203 M2281 M3217 M4253 M4423 *** M9689*** M9941 M11213 M19937 *** M21701*** M23209 It missed 2 Mersenne Primes 9689 21701. Is it my program bug or bigint broken? It seems subtle. Thank you! That's quite a terrible bug in Bigint. It's slipped through testing because of a fault in the win32 Phobos makefile (someone disabled asserts!). If Phobos is compiled in debug mode, your code causes an assert failure inside the bigint code. It's a straightforward problem with the fast recursive division implementation, failing to properly normalize intermediate quotients. Unfortunately the fix won't make the next release, which happens in a few hours.
Re: Checking if something is a template specialization?
== Quote from Lars T. Kyllingstad (public@kyllingen.NOSPAMnet)'s article On Fri, 18 Feb 2011 02:02:51 +, Sean Eskapp wrote: If I have class Bar(T) { } void foo(Y)() { ... } Is there a way to check inside foo() that Y is in some way an instantiation of Bar? Is there a way to find WHICH instantiation it is? void foo(Y)() { static if (is(Y Z == Bar!Z)) { // Here, Z is now an alias to whichever type Bar is // instantiated with. } else { // Z is invalid here. } } Perfect, thanks!
Proxy sorting
This is a RosettaCode simple task: http://rosettacode.org/wiki/Sort_disjoint_sublist#D Given a list of values and a set of integer indices into that value list, sort the values at the given indices, but preserving the values at indices outside the set of those to be sorted. Example input: values: [7, 6, 5, 4, 3, 2, 1, 0] indices: {6, 1, 7} Output: [7, 0, 5, 4, 3, 2, 1, 6]. I'd like to solve the problem using std.algorithm.sort, creating an array of proxy things, that while they get sorted, sort the original items too. Is it possible? This is a first try, but it doesn't work. I think struct postblits aren't useful here (currently disjointSort can't use a map() because of a map() bug I've added to bugzilla few days ago, so I use just a foreach+append). import std.stdio, std.algorithm, std.array; struct Proxy(T) { T* item; int opCmp(ref const Proxy other) { if (*item *(other.item)) return -1; else return *item *(other.item); } void opAssign(Proxy other) { if (item != null) *item = *(other.item); item = other.item; } } Proxy!T proxy(T)(ref T item) { return Proxy!T(item); } void disjointSort(T, U)(T[] arr, U[] s) { auto idxSet = array(uniq(s.sort())); auto proxies = new Proxy!T[idxSet.length]; foreach (i, idx; idxSet) proxies[i] = proxy(arr[idx]); proxies.sort(); } void main() { auto data = [7, 6, 5, 4, 3, 2, 1, 0]; auto indexes = [6, 1, 1, 7]; disjointSort(data, indexes); writeln(data); } Here I think opAssign() is not used by the swap() used by sort(). Bye, bearophile
Re: Proxy sorting
On Fri, 18 Feb 2011 08:08:22 -0500, bearophile bearophileh...@lycos.com wrote: This is a RosettaCode simple task: http://rosettacode.org/wiki/Sort_disjoint_sublist#D Given a list of values and a set of integer indices into that value list, sort the values at the given indices, but preserving the values at indices outside the set of those to be sorted. Example input: values: [7, 6, 5, 4, 3, 2, 1, 0] indices: {6, 1, 7} Output: [7, 0, 5, 4, 3, 2, 1, 6]. I'd like to solve the problem using std.algorithm.sort, creating an array of proxy things, that while they get sorted, sort the original items too. Is it possible? This is a first try, but it doesn't work. I think struct postblits aren't useful here (currently disjointSort can't use a map() because of a map() bug I've added to bugzilla few days ago, so I use just a foreach+append). import std.stdio, std.algorithm, std.array; struct Proxy(T) { T* item; int opCmp(ref const Proxy other) { if (*item *(other.item)) return -1; else return *item *(other.item); } void opAssign(Proxy other) { if (item != null) *item = *(other.item); item = other.item; } } Proxy!T proxy(T)(ref T item) { return Proxy!T(item); } void disjointSort(T, U)(T[] arr, U[] s) { auto idxSet = array(uniq(s.sort())); auto proxies = new Proxy!T[idxSet.length]; foreach (i, idx; idxSet) proxies[i] = proxy(arr[idx]); proxies.sort(); } void main() { auto data = [7, 6, 5, 4, 3, 2, 1, 0]; auto indexes = [6, 1, 1, 7]; disjointSort(data, indexes); writeln(data); } Here I think opAssign() is not used by the swap() used by sort(). I think opAssign is incorrect. Think about a standard swap: swap(ref Proxy p1, ref Proxy p2) { auto ptmp = p1; p1 = p2; p2 = ptmp; } Let's expand it out to the assignments that happen: ptmp.item = p1.item; *p1.item = *p2.item; // at this point, both ptmp.item and p1.item point to the *same element*, so you are also effectively assigning *ptmp.item p1.item = p2.item; *p2.item = *ptmp.item; p2.item = ptmp.item; If you passed in items that point to 1 and 2 respectively, I'd expect the pointers to be swapped, but both values set to 2. My suggestion would be to create a bidirectional proxy range that uses a supplemental array to determine where the next/previous element is (i.e. the index array). Should be pretty simple. Then just pass this to sort. -Steve
datetime fails with undefined reference
I can't seem to use std.datetime at all. I get undefined reference on whether I use a StopWatch, or if I just try to compile the unittest. All I have to do is declare a StopWatch: import std.stdio; import std.datetime; void main() { StopWatch sw; } This fails to compile: [kai@worky ~]$ dmd datetime_test.d /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib/libphobos2.a(datetime_35c_30e.o): In function `_D3std8datetime7systimeFNeZS3std8datetime5Ticks': std/datetime.d:(.text._D3std8datetime7systimeFNeZS3std8datetime5Ticks+0x1c): undefined reference to `clock_gettime' /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib/libphobos2.a(datetime_359_1fe.o): In function `_D3std8datetime5Ticks12_staticCtor5OFNeZv': std/datetime.d:(.text._D3std8datetime5Ticks12_staticCtor5OFNeZv+0x1b): undefined reference to `clock_getres' collect2: ld returned 1 exit status --- errorlevel 1 Am I missing some libraries somewhere? If I 'import core.sys.posix.time, core.sys.posix.sys.time;', parts of dattime work, and others don't. A main with just: writef(%s %s\n, (is(typeof({auto fp = clock_gettime; }; Prints true true, but using them like this gives undefined again: timespec ts; writef(%d\n, clock_getres(CLOCK_REALTIME, ts)); datetime_test.o: In function `_Dmain': datetime_test.d:(.text._Dmain+0x34): undefined reference to `clock_getres' collect2: ld returned 1 exit status --- errorlevel 1 I'm running Fedora 14 x86_64, dmd-2.051-0.i386, glibc-2.13-1.i686. Any ideas?
Finding out if T is a specialization of another template
I was given this code, to check if Y is a specialization of Bar. How does it work? class Bar(T) { } void foo(Y)() { static if (is(Y Z == Bar!Z)) { // Here, Z is now an alias to whichever type Bar is // instantiated with. } else { // Z is invalid here. } }
Re: Opt-out polymorphism?
On 13/02/2011 21:34, Sean Eskapp wrote: Is there a way to specify that a function is nonvirtual, but can still be overriden in base classes? e.g. Then you're not overriding at all. You're just declaring a function in the derived class that happens to have the same name. As such, it seems to me to have little use besides writing confusing code. Stewart.
Re: datetime fails with undefined reference
On Fri, 18 Feb 2011 16:38:19 +, Kai Meyer wrote: I can't seem to use std.datetime at all. I get undefined reference on whether I use a StopWatch, or if I just try to compile the unittest. All I have to do is declare a StopWatch: import std.stdio; import std.datetime; void main() { StopWatch sw; } This fails to compile: [kai@worky ~]$ dmd datetime_test.d /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib/libphobos2.a (datetime_35c_30e.o): In function `_D3std8datetime7systimeFNeZS3std8datetime5Ticks': std/datetime.d:(.text._D3std8datetime7systimeFNeZS3std8datetime5Ticks +0x1c): undefined reference to `clock_gettime' /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib/libphobos2.a (datetime_359_1fe.o): In function `_D3std8datetime5Ticks12_staticCtor5OFNeZv': std/datetime.d:(.text._D3std8datetime5Ticks12_staticCtor5OFNeZv+0x1b): undefined reference to `clock_getres' collect2: ld returned 1 exit status --- errorlevel 1 Am I missing some libraries somewhere? If I 'import core.sys.posix.time, core.sys.posix.sys.time;', parts of dattime work, and others don't. A main with just: writef(%s %s\n, (is(typeof({auto fp = clock_gettime; }; Prints true true, but using them like this gives undefined again: timespec ts; writef(%d\n, clock_getres(CLOCK_REALTIME, ts)); datetime_test.o: In function `_Dmain': datetime_test.d:(.text._Dmain+0x34): undefined reference to `clock_getres' collect2: ld returned 1 exit status --- errorlevel 1 I'm running Fedora 14 x86_64, dmd-2.051-0.i386, glibc-2.13-1.i686. Any ideas? You have to link in librt. Pass the -L-lrt option to DMD and it should work. -Lars
Re: Finding out if T is a specialization of another template
On Fri, 18 Feb 2011 17:16:02 +, Sean Eskapp wrote: I was given this code, to check if Y is a specialization of Bar. How does it work? class Bar(T) { } void foo(Y)() { static if (is(Y Z == Bar!Z)) { // Here, Z is now an alias to whichever type Bar is // instantiated with. } else { // Z is invalid here. } } I'm not sure what you mean by how does it work. If it's the is() expression you're wondering about, it's documented here: http://www.digitalmars.com/d/2.0/expression.html#IsExpression -Lars
Re: datetime fails with undefined reference
Great news! Worked like a champ. Is there documentation somewhere that I missed? I would love to be able to answer these questions on my own. I've been stumped on this one for a week :(
Re: datetime fails with undefined reference
On Friday, February 18, 2011 10:12:09 Kai Meyer wrote: Great news! Worked like a champ. Is there documentation somewhere that I missed? I would love to be able to answer these questions on my own. I've been stumped on this one for a week :( That should be in the dmd.conf in dmd.2.052.zip. If you're using an old dmd.conf, that would be the problem. Actually, I wouldn't have expected and old dmd.conf to work at all, since the directory structure for the lib folder(s) was changed due to the addition of 64-bit. So, I don't know what the deal with your setup is. Regardless, make sure that your current dmd.conf is either the most up-to-date on or at least based on it. Otherwise, you're going to be running into issues. - Jonathan M Davis
Re: Opt-out polymorphism?
Stewart Gordon: Then you're not overriding at all. You're just declaring a function in the derived class that happens to have the same name. I think Sean refers to the second usage of new in C#: http://msdn.microsoft.com/en-us/library/51y09td4%28v=vs.71%29.aspx Bye, bearophile
Re: datetime fails with undefined reference
On Fri, 18 Feb 2011 10:23:41 -0800, Jonathan M Davis wrote: On Friday, February 18, 2011 10:12:09 Kai Meyer wrote: Great news! Worked like a champ. Is there documentation somewhere that I missed? I would love to be able to answer these questions on my own. I've been stumped on this one for a week :( That should be in the dmd.conf in dmd.2.052.zip. If you're using an old dmd.conf, that would be the problem. Actually, I wouldn't have expected and old dmd.conf to work at all, since the directory structure for the lib folder(s) was changed due to the addition of 64-bit. So, I don't know what the deal with your setup is. Regardless, make sure that your current dmd.conf is either the most up-to-date on or at least based on it. Otherwise, you're going to be running into issues. Well, he could be using a setup similar to me. I don't use dmd.conf at all. Instead I set the DFLAGS environment variable in the startup script of my shell. I think the new dependency should be noted in the changelog. -Lars
Re: datetime fails with undefined reference
On Friday, February 18, 2011 11:43:22 Lars T. Kyllingstad wrote: On Fri, 18 Feb 2011 10:23:41 -0800, Jonathan M Davis wrote: On Friday, February 18, 2011 10:12:09 Kai Meyer wrote: Great news! Worked like a champ. Is there documentation somewhere that I missed? I would love to be able to answer these questions on my own. I've been stumped on this one for a week :( That should be in the dmd.conf in dmd.2.052.zip. If you're using an old dmd.conf, that would be the problem. Actually, I wouldn't have expected and old dmd.conf to work at all, since the directory structure for the lib folder(s) was changed due to the addition of 64-bit. So, I don't know what the deal with your setup is. Regardless, make sure that your current dmd.conf is either the most up-to-date on or at least based on it. Otherwise, you're going to be running into issues. Well, he could be using a setup similar to me. I don't use dmd.conf at all. Instead I set the DFLAGS environment variable in the startup script of my shell. I think the new dependency should be noted in the changelog. Probably, but I think that Andrei or Walter would have to be the one to do that. But dmd.conf has changed a fair bit with this release, and anyone who doesn't use dmd.conf (I have no idea why you wouldn't - it seems like you're just making life harder on yourself) is going to run into trouble. However, in general, I don't think that dmd.conf changes have made it into the changelog, so that's nothing new. Walter probably assumes that you're going to use the provided dmd.conf and doesn't think about it. - Jonathan M Davis
Re: __stack_chk_guard on Mac OSX
On 2011-02-17 22:19, HansR wrote: I followed the directions on http://www.digitalmars.com/d/2.0/dmd-osx.html for the hello.d example and I kept getting an error about __stack_chk_guard. Seems odd. What version of the D compiler are you using and what version of Mac OS X? -- /Jacob Carlborg
Re: datetime fails with undefined reference
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article On Friday, February 18, 2011 10:12:09 Kai Meyer wrote: Great news! Worked like a champ. Is there documentation somewhere that I missed? I would love to be able to answer these questions on my own. I've been stumped on this one for a week :( That should be in the dmd.conf in dmd.2.052.zip. If you're using an old dmd.conf, that would be the problem. Actually, I wouldn't have expected and old dmd.conf to work at all, since the directory structure for the lib folder(s) was changed due to the addition of 64-bit. So, I don't know what the deal with your setup is. Regardless, make sure that your current dmd.conf is either the most up-to-date on or at least based on it. Otherwise, you're going to be running into issues. - Jonathan M Davis Ok, my dmd.conf that came with the download does not have it in there. The package doesn't claim ownership to /etc/dmd.conf. I removed the rpm package, deleted the old dmd.conf, and installed the rpm again, but the dmd.conf that was generated is exactly the same: [kai@worky ~]$ cat /etc/dmd.conf [Environment] DFLAGS= -I/usr/include/d/dmd/phobos -I/usr/include/d/dmd/druntime/import -L-L/usr/lib Should I just simply add -L-lrt to the dmd.conf for now? Or just put it in my make file? Why does the rpm not claim ownership of the config file?: [kai@worky ~]$ rpm -qf /etc/dmd.conf file /etc/dmd.conf is not owned by any package [kai@worky ~]$ rpm -ql dmd | grep dmd.conf /usr/share/man/man5/dmd.conf.5.gz Thanks for the fast replies!
Re: Finding out if T is a specialization of another template
== Quote from Lars T. Kyllingstad (public@kyllingen.NOSPAMnet)'s article On Fri, 18 Feb 2011 17:16:02 +, Sean Eskapp wrote: I was given this code, to check if Y is a specialization of Bar. How does it work? class Bar(T) { } void foo(Y)() { static if (is(Y Z == Bar!Z)) { // Here, Z is now an alias to whichever type Bar is // instantiated with. } else { // Z is invalid here. } } I'm not sure what you mean by how does it work. If it's the is() expression you're wondering about, it's documented here: http://www.digitalmars.com/d/2.0/expression.html#IsExpression -Lars Ah, yes. I'd checked the is documentation, but whenever I tried using that is expression outside of an if statement, it complained about my usage, so I assumed it had something to do with if statements.
Verify tuple is a tuple of class objects?
Is there a way to run a template at compile time, without using a member? What I'm trying to do is verify that every element of a tuple is a class type, and so far, I've been doing this: template VerifyTuple(Type, Types...) { static assert(is(Type : Object), Type.stringof ~ is not a class type.); static if(Types.length == 0) alias void dummy; else alias VerifyTuple!(Types).dummy dummy; } and to use it, I have to do this: class Foo(T...) { alias VerifyTuple!(T).dummy dummy; } Is there any way to just run the template, without bothering to use the dummy aliases?
Re: Verify tuple is a tuple of class objects?
On Fri, 18 Feb 2011 16:15:16 -0500, Sean Eskapp eatingstap...@gmail.com wrote: Is there a way to run a template at compile time, without using a member? What I'm trying to do is verify that every element of a tuple is a class type, and so far, I've been doing this: template VerifyTuple(Type, Types...) { static assert(is(Type : Object), Type.stringof ~ is not a class type.); static if(Types.length == 0) alias void dummy; else alias VerifyTuple!(Types).dummy dummy; } and to use it, I have to do this: class Foo(T...) { alias VerifyTuple!(T).dummy dummy; } Is there any way to just run the template, without bothering to use the dummy aliases? eponymous should help (also cleaned up some of your code): template VerifyTuple(Types...) { static if(Types.length == 0) enum bool VerifyTuple = true; else enum bool VerifyTuple == is(Type : Object) VerifyTuple!(Types[1..$]); } class Foo(T...) { static assert(VerifyTuple!(T...), one of types in ~ T.stringof ~ is not a class); } It doesn't identify the specific type that isn't a class, but that could be done with a separate template. -Steve
Re: Verify tuple is a tuple of class objects?
Sean Eskapp: What I'm trying to do is verify that every element of a tuple is a class type, If you mean a TypeTuple, this is a solution: import std.typetuple: allSatisfy, TypeTuple; template IsClass(T) { enum IsClass = is(T == class); } class Foo {} class Bar {} struct Spam {} alias TypeTuple!(Foo, Bar, Spam) T1; alias TypeTuple!(Foo, Bar, Foo) T2; static assert(!allSatisfy!(IsClass, T1)); static assert(allSatisfy!(IsClass, T2)); void main() {} I don't know if there is a way to write IsClass() in a shorter way, like a lambda template. Bye, bearophile
Re: datetime fails with undefined reference
On Friday, February 18, 2011 12:29:40 Kai Meyer wrote: == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article On Friday, February 18, 2011 10:12:09 Kai Meyer wrote: Great news! Worked like a champ. Is there documentation somewhere that I missed? I would love to be able to answer these questions on my own. I've been stumped on this one for a week :( That should be in the dmd.conf in dmd.2.052.zip. If you're using an old dmd.conf, that would be the problem. Actually, I wouldn't have expected and old dmd.conf to work at all, since the directory structure for the lib folder(s) was changed due to the addition of 64-bit. So, I don't know what the deal with your setup is. Regardless, make sure that your current dmd.conf is either the most up-to-date on or at least based on it. Otherwise, you're going to be running into issues. - Jonathan M Davis Ok, my dmd.conf that came with the download does not have it in there. The package doesn't claim ownership to /etc/dmd.conf. I removed the rpm package, deleted the old dmd.conf, and installed the rpm again, but the dmd.conf that was generated is exactly the same: [kai@worky ~]$ cat /etc/dmd.conf [Environment] DFLAGS= -I/usr/include/d/dmd/phobos -I/usr/include/d/dmd/druntime/import -L-L/usr/lib Should I just simply add -L-lrt to the dmd.conf for now? Or just put it in my make file? Why does the rpm not claim ownership of the config file?: [kai@worky ~]$ rpm -qf /etc/dmd.conf file /etc/dmd.conf is not owned by any package [kai@worky ~]$ rpm -ql dmd | grep dmd.conf /usr/share/man/man5/dmd.conf.5.gz Thanks for the fast replies! If you just use the zip file, you're fine. I don't know what the state of the rpm is. I just always use the zip file. It's nice and self contained. All you have to do is make sure that /path/to/dmd2/linux/bin is on your PATH. The current dmd.conf should look like this: === [Environment] DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L- L%@P%/../lib32 -L-L%@P%/../lib64 -L--no-warn-search-mismatch -L--export-dynamic -L-lrt === If the pieces get moved elsewhere (such as installing libphobos2.a in a /usr/lib or something similar), then the paths would have to be updated though. Also, according to the online docs: dmd will look for the initialization file dmd.conf in the following sequence of directories: 1. current working directory 2. directory specified by the HOME environment variable 3. directory dmd resides in 4. /etc/ == So, maybe you need to just put the correct dmd.conf in one of the first three spots. Or you could just edit /etc/dmd.conf. I don't know what exactly the rpm does, so I don't know what it does with dmd.conf. But you have several options. Really, -L-lrt _should_ be in dmd.conf since core.time and std.datetime require it, but ultimately what matters is that it be in your DFLAGS so that dmd uses it when compiling. - Jonathan M Davis
Re: Verify tuple is a tuple of class objects?
Can anyone explain to me why this throws: class Foo() { } void main() { static if (is(Foo == class)) { } else { static assert(0); } }
Re: Finding out if T is a specialization of another template
On Fri, 18 Feb 2011 20:37:38 +, Sean Eskapp wrote: == Quote from Lars T. Kyllingstad (public@kyllingen.NOSPAMnet)'s article On Fri, 18 Feb 2011 17:16:02 +, Sean Eskapp wrote: I was given this code, to check if Y is a specialization of Bar. How does it work? class Bar(T) { } void foo(Y)() { static if (is(Y Z == Bar!Z)) { // Here, Z is now an alias to whichever type Bar is // instantiated with. } else { // Z is invalid here. } } I'm not sure what you mean by how does it work. If it's the is() expression you're wondering about, it's documented here: http://www.digitalmars.com/d/2.0/expression.html#IsExpression -Lars Ah, yes. I'd checked the is documentation, but whenever I tried using that is expression outside of an if statement, it complained about my usage, so I assumed it had something to do with if statements. Yeah, is() has a few extra features when it's combined with 'static if'. :) -Lars
Re: Verify tuple is a tuple of class objects?
bearophile bearophileh...@lycos.com wrote: I don't know if there is a way to write IsClass() in a shorter way, like a lambda template. No such thing, sadly. I have suggested it before, and would love to see such a feature. -- Simen
Re: Proxy sorting
Steven Schveighoffer: I think opAssign is incorrect. Silly me :-) My suggestion would be to create a bidirectional proxy range that uses a supplemental array to determine where the next/previous element is (i.e. the index array). Should be pretty simple. Then just pass this to sort. Thank you for your answers. Second try, it doesn't work yet, I'm looking for the problem: import std.stdio, std.array, std.algorithm, std.range; struct IndirectArray(Tdata, Tindexes) { Tdata[] data; Tindexes[] indexes; bool empty() { return indexes.empty(); } void popFront() { indexes.popFront(); } Tdata front() { return data[indexes.front()]; } IndirectArray save() { return this; } void popBack() { indexes.popBack(); } Tdata back() { return data[indexes.back()]; } @property size_t length() { return indexes.length; } Tdata opIndex(size_t i) { return data[indexes[i]]; } void opIndexAssign(Tdata value, size_t i) { data[indexes[i]] = value; } } static assert(isRandomAccessRange!(IndirectArray!(double, int))); // OK void disjointSort(Tdata, Tindexes)(Tdata[] arr, Tindexes[] idxSet) { auto proxy = IndirectArray!(Tdata, Tindexes)(arr, idxSet); sort(proxy); } void main() { auto data = [7, 6, 5, 4, 3, 2, 1, 0]; writeln(orig: , [7, 6, 5, 4, 3, 2, 1, 0]); auto indexes = [1, 6, 7]; disjointSort(data, indexes); writeln(result: , data); auto expected = [7, 0, 5, 4, 3, 2, 1, 6]; writeln(expected: , expected); assert(data == expected); } The static assert shows it's a random access range. But it breaks on the lines of partition(): r.front = t2; r.back = t1; So beside being a random access range, it needs some other property... General comment: to sort an array you need length, opIndex and opIndexAssign methods only. The need of all other methods looks a bit silly. Bye, bearophile
Re: datetime fails with undefined reference
As noted in my earlier email on the other list, I too got this problem. Fromn what I can tell 1.066 and 2.051 have dmd.conf files but there is no such thing in the 1.067 and 2.052 distributions. So the out of the box configuration does seem to be broken. That should be in the dmd.conf in dmd.2.052.zip. If you're using an old dmd.conf, that would be the problem. Actually, I wouldn't have expected and old dmd.conf to work at all, since the directory structure for the lib folder(s) was changed due to the addition of 64-bit. So, I don't know what the deal with your setup is. Regardless, make sure that your current dmd.conf is either the most up-to-date on or at least based on it. Otherwise, you're going to be running into issues. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@russel.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: datetime fails with undefined reference
On Sat, 2011-02-19 at 00:27 +, Russel Winder wrote: As noted in my earlier email on the other list, I too got this problem. Fromn what I can tell 1.066 and 2.051 have dmd.conf files but there is no such thing in the 1.067 and 2.052 distributions. So the out of the box configuration does seem to be broken. That should be in the dmd.conf in dmd.2.052.zip. If you're using an old dmd.conf, that would be the problem. Actually, I wouldn't have expected and old dmd.conf to work at all, since the directory structure for the lib folder(s) was changed due to the addition of 64-bit. So, I don't know what the deal with your setup is. Regardless, make sure that your current dmd.conf is either the most up-to-date on or at least based on it. Otherwise, you're going to be running into issues. Sorry this is not correct, the locate database just hasn't been updated since I installeed. However the linux/bin/dmd.conf file is indentical in the 2.051 and 2.052 distributions. This means DMD is broken out of the box. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@russel.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Proxy sorting
Thank you for your answers. Second try, it doesn't work yet, I'm looking for the problem: Third try, this seems to work: import std.stdio, std.array, std.algorithm, std.range; struct IndirectArray(Tdata, Tindexes) { Tdata[] data; Tindexes[] indexes; bool empty() { return indexes.empty(); } void popFront() { indexes.popFront(); } ref Tdata front() { return data[indexes.front()]; } IndirectArray save() { return this; } void popBack() { indexes.popBack(); } ref Tdata back() { return data[indexes.back()]; } @property size_t length() { return indexes.length; } Tdata opIndex(size_t i) { return data[indexes[i]]; } void opIndexAssign(Tdata value, size_t i) { data[indexes[i]] = value; } IndirectArray opSlice(size_t x, size_t y) { return IndirectArray(data, indexes[x .. y]); } } static assert(isRandomAccessRange!(IndirectArray!(double, int))); // OK void disjointSort(Tdata, Tindexes)(Tdata[] arr, Tindexes[] idxSet) { auto proxy = IndirectArray!(Tdata, Tindexes)(arr, idxSet); sort(proxy); } void main() { auto data = [7, 6, 5, 4, 3, 2, 1, 0]; writeln(orig: , [7, 6, 5, 4, 3, 2, 1, 0]); auto indexes = [1, 6, 7]; disjointSort(data, indexes); writeln(result: , data); auto expected = [7, 0, 5, 4, 3, 2, 1, 6]; writeln(expected: , expected); assert(data == expected); } I don't know yet how much efficient it is, things like opSlice() copy size_t.sizeof*4 bytes. front() and back() must return by ref, and opSlice() too is needed. I think this requirements need to be added to the template constraints of sort(). Bye, bearophile
Re: datetime fails with undefined reference
On Friday, February 18, 2011 16:27:23 Russel Winder wrote: As noted in my earlier email on the other list, I too got this problem. Fromn what I can tell 1.066 and 2.051 have dmd.conf files but there is no such thing in the 1.067 and 2.052 distributions. So the out of the box configuration does seem to be broken. And as I said in my response to your other message, the proper dmd.conf file _is_ in the distributed zip file. So, unless you're dealing with the deb or rpm, and they're broken, and I don't know why you wouldn't be seeing a new dmd.conf with the 2.052 release. But I don't know what the state of the rpm or deb is. I just always use the zip file, which is very simple. - Jonathan M Davis
Re: Read non-UTF8 file
On 13/02/2011 21:49, Nrgyzer wrote: snip It compiles and works as long as the returned char-array/string of f.readLine() doesn't contain non-UTF8 character(s). If it contains such chars, writeln() doesn't write anything to the console. Is there any chance to read such files? Please post sample input that shows the problem, and the output generated by replacing the writeln call with writefln(%s, cast(ubyte[]) convertToUTF8(f.readLine())); so that we can see what it is actually reading in. Stewart.
Re: using a binary tree container
On 11/02/2011 12:30, Dominic Jones wrote: snip Would that not be constructing an associated array? Whilst an associated array would do the job, there is no value for the key:value pair, just a list of keys. In the C++ STL there are the set and map containers. I want something like set. Dominic http://pr.stewartsplace.org.uk/d/sutil/ includes a set class template. Stewart.
Re: Verify tuple is a tuple of class objects?
On 18/02/2011 21:22, Steven Schveighoffer wrote: snip template VerifyTuple(Types...) { static if(Types.length == 0) enum bool VerifyTuple = true; else enum bool VerifyTuple == is(Type : Object) VerifyTuple!(Types[1..$]); snip You have two typos there. Corrected version: enum bool VerifyTuple = is(Types[0] : Object) VerifyTuple!(Types[1..$]); But perhaps even nicer: -- template VerifyTuple() { enum bool VerifyTuple = true; } template VerifyTuple(T, Ypes...) { enum bool VerifyTuple = is(T : Object) VerifyTuple!(Ypes); } -- (Some of you will be able to guess what other language I've programmed in in my time from this.) Stewart.
Error when exiting program
I'm using some one else's bindings to a C library. The problem seems to be limited to D2 programs. Error as follows: An exception was thrown while finalizing an instance of class jec2.bmp.Bmp I also get other errors at program exit. Thanks for any help. :-)
Re: Error when exiting program
Joel Christensen Wrote: I'm using some one else's bindings to a C library. The problem seems to be limited to D2 programs. Error as follows: An exception was thrown while finalizing an instance of class jec2.bmp.Bmp I also get other errors at program exit. Thanks for any help. :-) I think you are going to have to give us more detail. What library, what error?