Re: Cannot implicitly convert derived type

2014-02-22 Thread Eric Suen
interface iButton { } class WindowsButton : iButton { } interface iGui(T) { @property T button(ref T button); } class WindowsGui : iGui!(WindowsButton) { @property WindowsButton button(ref WindowsButton button) { return button; } } "Frustrated" > On Saturday, 22 February 2014 at 05:20:25 U

Re: Cannot implicitly convert derived type

2014-02-22 Thread Ali Çehreli
On 02/22/2014 12:17 PM, Frustrated wrote: > Again, the whole point of why it is illegal because you can pass > a RogueButton... BUT I DON'T INTEND TO PASS THEM! Thinking that way, many rules of a statically type-checked language like D would be unnecessary. ;) > WindowsGui only uses WindowsBu

IFTI with value / template value parameter shadowing

2014-02-22 Thread Mathias LANG
Hi everyone, I recently end up with the following code: import std.stdio; T IFTI_Type(T)(T value) { return value; } int IFTI_Value(int n)(int n) { return n; } int Shadowing_FTW(int n)() { writeln(n); int n = 42; // Will print 6 return n; } voidmai

Re: Cannot implicitly convert derived type

2014-02-22 Thread Steven Schveighoffer
On Sat, 22 Feb 2014 15:17:37 -0500, Frustrated wrote: It is legal exactly because I will always guarantee that the proper button will be used. Static typing says it's not legal. D does not do dynamic type checking upon calling virtual functions. It is not logically legal as mentioned sev

Re: hiding a class property behind a method

2014-02-22 Thread francesco cattoglio
On Saturday, 22 February 2014 at 22:42:24 UTC, simendsjo wrote: The problem isn't about optional parenthesis or properties. It's the fact that you can redefine a symbol to be something entierly different, and that this difference will only be seen if you are looking at the symbol through the "

Re: hiding a class property behind a method

2014-02-22 Thread simendsjo
On 02/22/2014 11:33 PM, Francesco Cattoglio wrote: On Saturday, 22 February 2014 at 17:21:50 UTC, luka8088 wrote: It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: [snip] Nice find. I gues

Re: hiding a class property behind a method

2014-02-22 Thread Francesco Cattoglio
On Saturday, 22 February 2014 at 17:21:50 UTC, luka8088 wrote: It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: [snip] Nice find. I guess we could add this to the list of "ugly code cau

Re: hiding a class property behind a method

2014-02-22 Thread simendsjo
On 02/22/2014 09:43 PM, Ali Çehreli wrote: It looks like name hiding, which I am familiar from C++. Name hiding does not differentiate between functions and variables. Ali The problem is that hiding a name *is* a problem. When you are hiding a name, then a class would no longer behave as yo

Re: Build Hash from Array in one statement ?

2014-02-22 Thread Ali Çehreli
On 02/22/2014 11:26 AM, Gordon wrote: > Is there a way to quickly build a hash from the values of an array? If I am allowed to misunderstand :) it as a *single* hash from all of the values, then you can use D's internal hash algorithm for arrays: import std.stdio; void main() { auto arr

Re: hiding a class property behind a method

2014-02-22 Thread Ali Çehreli
On 02/22/2014 10:00 AM, Maxim Fomin wrote: > On Saturday, 22 February 2014 at 17:41:58 UTC, Ali Çehreli wrote: >> >> The code uses the two objects through the A interface and x() is a >> virtual function on that interface. >> >> When the C interface is used then we get C.x, which happens to be >>

Re: hiding a class property behind a method

2014-02-22 Thread Ali Çehreli
On 02/22/2014 12:06 PM, Nynn007 wrote: >> The code uses the two objects through the A interface and x() is a >> virtual function on that interface. > [...] >> Ali I agree. :) > > The book "Programming in D" (r651) says in chapter "57.7 Using the > subclass in place of the superclass", in the ex

Re: Cannot implicitly convert derived type

2014-02-22 Thread Frustrated
On Saturday, 22 February 2014 at 05:20:25 UTC, Eric Suen wrote: Generic? I don't see how this would help. I'd have to specify every concrete type in the creation of the object which might be significant. I can't use a generic virtual method so that doesn't help either. It would be nice to hav

Re: Cannot implicitly convert derived type

2014-02-22 Thread Frustrated
On Saturday, 22 February 2014 at 01:03:22 UTC, Steven Schveighoffer wrote: On Fri, 21 Feb 2014 17:54:06 -0500, Frustrated wrote: interface iGui { @property iButton button(ref iButton button); } class WindowsGui : iGui { WindowsButton _button; @property WindowsButton

Re: hiding a class property behind a method

2014-02-22 Thread Nynn007
The code uses the two objects through the A interface and x() is a virtual function on that interface. [...] Ali The book "Programming in D" (r651) says in chapter "57.7 Using the subclass in place of the superclass", in the example about Clock and AlarmClock : void use(Clock clock) {

Re: Build Hash from Array in one statement ?

2014-02-22 Thread Tobias Pankrath
--- Or, put differently, is there a way to convert values in an array to keys of hash in one statement ? Thanks! -gordon std.array.assocArray. -- T[] keys; auto aa = zip(keys, repeat(true)).assocArray;

Re: Bug with references (no casting used)

2014-02-22 Thread Artur Skawina
On 02/22/14 18:22, andrea9940 wrote: > I was trying to get my vector struct to use extensively references for > passing parameters and I found a subtle bug which make me lose a few hour. > > A sample code that shows the bug is here http://pastebin.com/rvcNdjAE (fails > with dmd 2.064 on linux) >

Build Hash from Array in one statement ?

2014-02-22 Thread Gordon
Hello, Is there a way to quickly build a hash from the values of an array? A one-statement equivalent of: T[] array_values ; int[T] hash_values; hash_values = map!() (array_values) ; Instead of: for (v; array_values) { hash_values[v] = 1; } in Perl, that would be: %ha

Re: Bug with references (no casting used)

2014-02-22 Thread anonymous
On Saturday, 22 February 2014 at 17:22:51 UTC, andrea9940 wrote: Hi everyone, I was trying to get my vector struct to use extensively references for passing parameters and I found a subtle bug which make me lose a few hour. A sample code that shows the bug is here http://pastebin.com/rvcNdjA

Re: Bug with references (no casting used)

2014-02-22 Thread Maxim Fomin
On Saturday, 22 February 2014 at 17:22:51 UTC, andrea9940 wrote: Hi everyone, I was trying to get my vector struct to use extensively references for passing parameters and I found a subtle bug which make me lose a few hour. A sample code that shows the bug is here http://pastebin.com/rvcNdjA

Re: hiding a class property behind a method

2014-02-22 Thread Maxim Fomin
On Saturday, 22 February 2014 at 17:41:58 UTC, Ali Çehreli wrote: The code uses the two objects through the A interface and x() is a virtual function on that interface. When the C interface is used then we get C.x, which happens to be hiding the x() function of the base class. It looks nor

Re: hiding a class property behind a method

2014-02-22 Thread Ali Çehreli
On 02/22/2014 09:21 AM, luka8088 wrote:> It seems to me that the following code should be illegal, but I am > uncertain of it so I am posting here for a confirmation before I post it > on bug tracker: > > > http://dpaste.dzfl.pl/dae728734cc6 > > > import std.stdio; > > class A { >string x ()

Re: hiding a class property behind a method

2014-02-22 Thread simendsjo
On 02/22/2014 06:21 PM, luka8088 wrote: import std.stdio; class A { string x () { return "A"; }; } class B : A { override string x () { return "B"; }; } class C : A { string x = "C"; // should this be illegal? } void main () { A o1 = new B(); writeln(o1.x); // B A o2 = new

Bug with references (no casting used)

2014-02-22 Thread andrea9940
Hi everyone, I was trying to get my vector struct to use extensively references for passing parameters and I found a subtle bug which make me lose a few hour. A sample code that shows the bug is here http://pastebin.com/rvcNdjAE (fails with dmd 2.064 on linux) I think that the code is wrong

hiding a class property behind a method

2014-02-22 Thread luka8088
It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: http://dpaste.dzfl.pl/dae728734cc6 import std.stdio; class A { string x () { return "A"; }; } class B : A { override string x () { re

Re: Range Construction Pattern

2014-02-22 Thread Nordlöw
I have a pile of extensions to std.algorithm, std.traits, std.numeric, I'll pull some day when I get the time... I mean push...

Scalability in std.parallelism

2014-02-22 Thread Nordlöw
In the following test code given below of std.parallelism I get some interesting results: when compiled as dmd -release -noboundscheck -O -inline -w -wi -wi ~/Work/justd/t_parallelism.d -oft_parallelism My scalability measures says the following 3.14159 took 221[ms] 3.14159 took 727[ms] Sp

Re: Range Construction Pattern

2014-02-22 Thread Nordlöw
btw, I'd call this template 'apply', because repeat already exists in Phobos with a different use. Good idea! I'll rename it. I have a pile of extensions to std.algorithm, std.traits, std.numeric, I'll pull some day when I get the time... /Per

Re: Range Construction Pattern

2014-02-22 Thread Philippe Sigaud
per.nordlow: > > My try so far: > > import std.traits: isCallable, ReturnType, arity, ParameterTypeTuple; > > enum arityMin0(alias fun) = __traits(compiles, fun()); // new syntax in 2.064 > > auto repeat(alias fun)(size_t n) if (isCallable!fun && > arityMin0!fun

Re: Range Construction Pattern

2014-02-22 Thread Nordlöw
My try so far: import std.traits: isCallable, ReturnType, arity, ParameterTypeTuple; enum arityMin0(alias fun) = __traits(compiles, fun()); // new syntax in 2.064 auto repeat(alias fun)(size_t n) if (isCallable!fun && arityMin0!fun &&

Re: Range Construction Pattern

2014-02-22 Thread Philippe Sigaud
> You can check if arbitrary code compiles with the "if-typeof-delegate-trick": > -- > static if(is(typeof({ } > { > // code compiles > } > -- Or with __traits(compiles, ), which better documents the intent.

Re: Range Construction Pattern

2014-02-22 Thread Tobias Pankrath
I believe we need a new std.trait, say arityMin, for this. Any ideas on how to implement that? Perhaps using __traits(compiles...? See also my update at: https://stackoverflow.com/questions/21954381/range-construction-pattern/21954416?noredirect=1#21954416 In the meantime you can use an is

Re: Range Construction Pattern

2014-02-22 Thread Nordlöw
On Saturday, 22 February 2014 at 14:03:11 UTC, Philippe Sigaud wrote: Now what remains is to retstrict create to only take a fun with *no* input arguments and a non-void return. How do I do that? With a template contraint. Not tested: import std.traits: isCallable, ParameterTypeTuple, Retur

Re: Range Construction Pattern

2014-02-22 Thread Philippe Sigaud
> Now what remains is to retstrict create to only take a fun with *no* input arguments and a non-void return. > > How do I do that? With a template contraint. Not tested: import std.traits: isCallable, ParameterTypeTuple, ReturnType; auto create(alias fun)(size_t n) if (isCallable!fun && Paramet

Re: Range Construction Pattern

2014-02-22 Thread Tobias Pankrath
Great! See also: https://stackoverflow.com/questions/21954381/range-construction-pattern/21954416?noredirect=1#21954416 I don't think that 'create' is a good name for a function, that basically lazily evaluates another function foo n times. Maybe std.range.repeat should have an overload that

Re: Range Construction Pattern

2014-02-22 Thread Nordlöw
times = iota(3).map!(x => Clock.currTime).array; -- Ok here's my try so far: auto create(alias fun)(size_t n) { import std.range: iota, map; return n.iota.map!(n => fun); } Now what remains is to retstrict create to only take a fun with *no* input arguments and a non-void return. Ho

Re: Range Construction Pattern

2014-02-22 Thread Nordlöw
On Saturday, 22 February 2014 at 12:40:42 UTC, Tobias Pankrath wrote: On Saturday, 22 February 2014 at 12:29:11 UTC, Nordlöw wrote: Assumed I have the following code SysTime[] times; const n = 3; foreach (i; 0..n) times ~= Clock.currTime; is there a simpler, perhaps functional, higher

Re: Is there kind of "associative tuple" - like syntax in D?

2014-02-22 Thread Artur Skawina
On 02/21/14 18:57, Uranuz wrote: > In my template functions, classes it's necessary to write variadic template > parameter list, where elements are options to this class/function changing > it's behaviour. But they are optional and may be not set at all. These > options may be folowed by variad

Re: Range Construction Pattern

2014-02-22 Thread Tobias Pankrath
On Saturday, 22 February 2014 at 12:29:11 UTC, Nordlöw wrote: Assumed I have the following code SysTime[] times; const n = 3; foreach (i; 0..n) times ~= Clock.currTime; is there a simpler, perhaps functional, higher order pattern with which to achieve the same goal? What's Clock.

Range Construction Pattern

2014-02-22 Thread Nordlöw
Assumed I have the following code SysTime[] times; const n = 3; foreach (i; 0..n) times ~= Clock.currTime; is there a simpler, perhaps functional, higher order pattern with which to achieve the same goal?

Re: Why does object creation give segmentation fault in DLL?

2014-02-22 Thread Tolga Cakiroglu
On Saturday, 22 February 2014 at 11:08:41 UTC, evilrat wrote: On Saturday, 22 February 2014 at 09:09:42 UTC, Tolga Cakiroglu wrote: I have written a DLL file in Linux (x86_64). It is as below: File: lib.dll = class A{} extern(C) void foo(){ Object obj = new Object()

Re: Optimize my code =)

2014-02-22 Thread Robin
Hiho, as I used the ldmd wrapper for ldc2 I was able to use the same arguments given via the cmdfile. These were: -release -noboundscheck -O and -inline. Robin

Re: Why does object creation give segmentation fault in DLL?

2014-02-22 Thread evilrat
On Saturday, 22 February 2014 at 09:09:42 UTC, Tolga Cakiroglu wrote: I have written a DLL file in Linux (x86_64). It is as below: File: lib.dll = class A{} extern(C) void foo(){ Object obj = new Object(); // test 1 A objA = new A(); // test 2 ch

Why does object creation give segmentation fault in DLL?

2014-02-22 Thread Tolga Cakiroglu
I have written a DLL file in Linux (x86_64). It is as below: File: lib.dll = class A{} extern(C) void foo(){ Object obj = new Object(); // test 1 A objA = new A(); // test 2 char[] c = new char[ 1024 ]; // test 3 } Compilation code is below:

Re: Treat memory as a file with a name.

2014-02-22 Thread Steve Teale
If it's the same librsvg as below, then it looks like it has an API function which can also load a SVG from memory: https://developer.gnome.org/rsvg/2.40/RsvgHandle.html#rsvg-handle-new-from-data To answer your original question, I think the best way to do this is to create a pipe on the files