Re: overiding mutable methods in immutable classes

2014-11-22 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 02:37:21 UTC, Eric wrote: I know I can make a class immutable, but the problem is I want to constrain a template parameter to only immutable types, and I want to use class types. template Foo(T : immutable Object) Accepts immutable(Object) and other immutable

Re: undefined reference to class template

2014-11-22 Thread Satoshi via Digitalmars-d-learn
On Monday, 17 November 2014 at 21:12:54 UTC, Steven Schveighoffer wrote: On 11/14/14 6:29 PM, Satoshi wrote: Hi, Im using GDC 4.9.0 compiler. I have template classes like public class LinkedList(T) {...} and when I try compile it together, everything works fine. But when I compile every source

Re: overiding mutable methods in immutable classes

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 09:57:55 UTC, anonymous wrote: On Saturday, 22 November 2014 at 02:37:21 UTC, Eric wrote: I know I can make a class immutable, but the problem is I want to constrain a template parameter to only immutable types, and I want to use class types. template Foo(T :

How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
I tried to pass pointer to static array but it didn't work.

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried it right now and it works. if you really want to get some help, you'd better give us something to start with. i.e. your

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:20:55 UTC, drug wrote: I tried to pass pointer to static array but it didn't work. try this: import std.stdio; void change(ref int[3] arr) { arr[1] = 6; } void main() { int[3] a = [1, 2, 3]; writeln(a = , a); change(a); writeln(a = ,

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:20:55 UTC, drug wrote: I tried to pass pointer to static array but it didn't work. Also, if you really want to be lame and actually use a pointer try this: import std.stdio; void change(int *arr) { arr[1] = 6; } void main() { int[3] a = [1, 2, 3];

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Maybe this is not so lame because change() can take any length of static array. void change (int[] arr) { arr[1] = 42; } void main () { int[$] a = [1, 2, 3]; change(a);

Re: How to pass static array to function not by value?

2014-11-22 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 22, 2014 at 05:57:30PM +0200, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Maybe this is not so lame because change() can take any length of static array. void change (int[]

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:57:40 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Maybe this is not so lame because change() can take any length of static array. void change (int[]

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried it right now and it works. if you really want to get some

Re: How to pass static array to function not by value?

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 16:07:25 UTC, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried

Re: How to pass static array to function not by value?

2014-11-22 Thread Ali Çehreli via Digitalmars-d-learn
On 11/22/2014 07:07 AM, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it didn't work. i tried it right now and it

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 08:07:31 -0800 H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sat, Nov 22, 2014 at 05:57:30PM +0200, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric via Digitalmars-d-learn digitalmars-d-learn@puremagic.com

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 20:26, Ali Çehreli wrote: On 11/22/2014 07:07 AM, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static array but it

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 20:26, Eric wrote: On Saturday, 22 November 2014 at 16:07:25 UTC, drug wrote: On 22.11.2014 19:34, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 18:20:44 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: I tried to pass pointer to static

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 20:30, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 08:07:31 -0800 H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sat, Nov 22, 2014 at 05:57:30PM +0200, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 15:45:51 + Eric

Re: overiding mutable methods in immutable classes

2014-11-22 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 15:00:00 UTC, Eric wrote: Yes, but if I don't declare the class T as immutable, I don't think this constraint will work. You're mistaken. It works just fine. class X /* not immutable */ { private int x; this(int x) pure { this.x = x; } } template

Re: How to pass static array to function not by value?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 20:05:13 +0400 drug via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Does it worth to make some compiler option that for example prohibits passing static array instead of dynamic one without slicing? Who has a lot of breakable correct D code doesn't use

Re: How to pass static array to function not by value?

2014-11-22 Thread drug via Digitalmars-d-learn
On 22.11.2014 21:22, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 20:05:13 +0400 drug via Digitalmars-d-learndigitalmars-d-learn@puremagic.com wrote: Does it worth to make some compiler option that for example prohibits passing static array instead of dynamic one without slicing?

Re: overiding mutable methods in immutable classes

2014-11-22 Thread Eric via Digitalmars-d-learn
On Saturday, 22 November 2014 at 17:06:29 UTC, anonymous wrote: On Saturday, 22 November 2014 at 15:00:00 UTC, Eric wrote: Yes, but if I don't declare the class T as immutable, I don't think this constraint will work. You're mistaken. It works just fine. class X /* not immutable */ {

Re: overiding mutable methods in immutable classes

2014-11-22 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 17:40:42 UTC, Eric wrote: Yes, but this is what I really want: class X(T : immutable Object) { private T x; this(T x) pure { this.x = x; } } class Y { private int x; this(int x) pure { this.x = x; } } void main() { immutable(Y) y = new

naked popcnt function

2014-11-22 Thread Ad via Digitalmars-d-learn
Hello, I would like to write a popcnt function. This works fine ulong popcnt(ulong x) { asm { mov RAX, x ; popcnt RAX, RAX ; } } However, if I add the naked keyword ( which should improve performance? ) it doesn't work anymore and I can't figure out what change I am supposed to make ( aside

Re: Dub / Derelict confusion

2014-11-22 Thread Paul via Digitalmars-d-learn
On Friday, 21 November 2014 at 01:23:55 UTC, Mike Parker wrote: On 11/21/2014 10:22 AM, Mike Parker wrote: You are adding anything You /aren't/ The problem is 'no available video device' when trying to init SDL. I've recently wiped/re-installed this machine so something must be missing.

Re: overiding mutable methods in immutable classes

2014-11-22 Thread Eric via Digitalmars-d-learn
But I'm not sure if maybe I changed to much about it. My point is, that I think it's generally a good idea to be flexible when possible, and not make (im)mutability demands unless actually necessary. You may know the following, but I feel like there may be some confusion about it: Note that

Simple code sample of Nesting Structures. I'm I doing something illegal here?

2014-11-22 Thread WhatMeWorry via Digitalmars-d-learn
// Two simple value type structures. one embedded in the other. I've stepped through the debugger and I see the embedded structure being set to 2, and dog. import std.stdio; struct NestedBottom { int i; char[3] fixedArray; // this(){} no-argument ctor can only be defined by

Re: naked popcnt function

2014-11-22 Thread safety0ff via Digitalmars-d-learn
On Saturday, 22 November 2014 at 18:30:06 UTC, Ad wrote: Hello, I would like to write a popcnt function. This works fine ulong popcnt(ulong x) { asm { mov RAX, x ; popcnt RAX, RAX ; } } However, if I add the naked keyword ( which should improve performance? ) it doesn't work anymore and I

Re: Simple code sample of Nesting Structures. I'm I doing something illegal here?

2014-11-22 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 22 November 2014 at 20:57:07 UTC, WhatMeWorry wrote: auto bottom = NestedBottom(2, ['d','o','g']); That 'auto' is the problem. You want 'this.bottom = ...' instead.

Re: Simple code sample of Nesting Structures. I'm I doing something illegal here?

2014-11-22 Thread ketmar via Digitalmars-d-learn
On Sat, 22 Nov 2014 20:57:05 + WhatMeWorry via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: auto bottom = NestedBottom(2, ['d','o','g']); ah, that good old thingy! there were some debates about locals that shadows fields and how that can introduce some hard-to-catch

Re: Simple code sample of Nesting Structures. I'm I doing something illegal here?

2014-11-22 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 22, 2014 at 11:54:01PM +0200, ketmar via Digitalmars-d-learn wrote: On Sat, 22 Nov 2014 20:57:05 + WhatMeWorry via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: auto bottom = NestedBottom(2, ['d','o','g']); ah, that good old thingy! there were some

Re: overiding mutable methods in immutable classes

2014-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 22, 2014 14:59:58 Eric via Digitalmars-d-learn wrote: On Saturday, 22 November 2014 at 09:57:55 UTC, anonymous wrote: On Saturday, 22 November 2014 at 02:37:21 UTC, Eric wrote: I know I can make a class immutable, but the problem is I want to constrain a template

Re: Dub / Derelict confusion

2014-11-22 Thread Mike Parker via Digitalmars-d-learn
On 11/23/2014 3:52 AM, Paul wrote: Whenever I try to learn a new language I always seem to end up fighting the OS or the IDE rather than spending time where I should. Therefore, I'm going to put this idea on hold and stick to console programs for a while (tried to install ncurses as well

Re: naked popcnt function

2014-11-22 Thread Marco Leise via Digitalmars-d-learn
Am Sat, 22 Nov 2014 18:30:05 + schrieb Ad a...@fakmail.fg: Hello, I would like to write a popcnt function. This works fine ulong popcnt(ulong x) { asm { mov RAX, x ; popcnt RAX, RAX ; } } However, if I add the naked keyword ( which should improve performance? ) it doesn't work