Re: Why does a switch break cause a segmentation fault

2019-07-22 Thread Eric via Digitalmars-d-learn
Shouldn't (stream == null) be (stream is null)? -Eric From: "adamgoldberg via Digitalmars-d-learn" To: digitalmars-d-learn@puremagic.com Sent: Monday, July 22, 2019 3:05:17 PM Subject: Why does a switch break cause a segmentation fault Hey, I just happened to be writing a program in D

Re: write a function template specialisation that tests if an argument is known at compile time

2018-08-14 Thread Eric via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 03:01:11 UTC, Cecil Ward wrote: On Tuesday, 14 August 2018 at 02:53:01 UTC, Cecil Ward wrote: On Sunday, 12 August 2018 at 12:27:59 UTC, Alex wrote: On Saturday, 11 August 2018 at 05:17:51 UTC, Cecil Ward wrote: T myfunc(T)( T x, uint mask ) if ( mask == 3 )

Re: unimplemented abstract function compiles.

2018-08-12 Thread Eric via Digitalmars-d-learn
I thought it would work the same way as an interface (which must be implemented by the direct sub class, otherwise compile error). But apparently it's possible to implement an abstract function anywhere in the class hierarchy. That makes it, in this case, impossible to check during compile

unimplemented abstract function compiles.

2018-08-11 Thread Eric via Digitalmars-d-learn
Code below compiles while I would not expect it to compile. Is there a reason that this compiles? Specs are a bit lite on abstract classes. Only thing I found that would need to allow this is: "19.4 functions without bodies" https://dlang.org/spec/function.html#function-declarations But

Action at a distance, separating operations from subjects

2018-07-30 Thread Eric via Digitalmars-d-learn
Not a question. I came up with a nice and simple way to apply operations on an arbitrary number of members of unknown type of a set of objects of unknown type. This without having to reimplement these operations for each class that needs to support the operation(s). All this without

Re: crash when using in struct constructor

2018-07-18 Thread Eric via Digitalmars-d-learn
On Wednesday, 18 July 2018 at 12:10:18 UTC, baz wrote: Specs are clear : it's a global so it's evaluated at compile time (https://dlang.org/spec/declaration.html#global_static_init) Example code should not compile. Indeed. Inside a function it does actually work. And ofcourse for class

Re: crash when using in struct constructor

2018-07-16 Thread Eric via Digitalmars-d-learn
On Monday, 16 July 2018 at 22:16:10 UTC, Adam D. Ruppe wrote: On Monday, 16 July 2018 at 22:08:34 UTC, Eric wrote: This makes the compiler crash. Is it illegal code? Yes, a struct can be moved at any time by the compiler which means pointers to it can be invalidated at random. Unless you

Re: crash when using in struct constructor

2018-07-16 Thread Eric via Digitalmars-d-learn
Pasted slightly wrong code, last line should be: List ls = 2; Question still stands.

crash when using in struct constructor

2018-07-16 Thread Eric via Digitalmars-d-learn
This makes the compiler crash. Is it illegal code? struct List { private List* head; private List* tail; this(int x) { head = null; tail = // <-- crasher } } List2 ls = 2;

Re: indexing stuff during compile time

2017-12-24 Thread Eric via Digitalmars-d-learn
I am just a bit confused why I had to use tuple() while the doc Because of the enum, that code was full of errors :/ Got it now: auto groupIndex(Ts...)() { import std.meta; import std.algorithm.comparison : cmp, strcmp = cmp; enum Comp(N1, N2) = strcmp(N1.stringof,

Re: indexing stuff during compile time

2017-12-24 Thread Eric via Digitalmars-d-learn
Ok, solved. It appears you can sort tuples. I am just a bit confused why I had to use tuple() while the doc for staticSort states it works on AliasSeq. auto groupIndex(Ts...)() { import std.meta; enum Comp(alias N1, alias N2) = { __traits(identifier, typeof(N1)) <

Re: indexing stuff during compile time

2017-12-24 Thread Eric via Digitalmars-d-learn
Forgot to mention that I also want groupIndex!(A,B) == groupIndex!(B,A) Which I wanted to do by sorting the names. If that requirement wasn't there it would be as simple as: auto groupIndex(Ts...)() { return GroupId!Ts.id; } size_t s_nextIdx=1; struct GroupId(Ts ...) { static size_t

indexing stuff during compile time

2017-12-23 Thread Eric via Digitalmars-d-learn
I am trying to build a string->int dictionary at compile time. The ints are unique and must not be greater than the number of unique strings. So, they are sequential for each string that is not yet indexed. Example: size_t idx1 = nameToIndex!"blah"; // 0 size_t idx2 = nameToIndex!"blah2"; //

problem overloading functions with complex enum type

2017-07-08 Thread Eric via Digitalmars-d-learn
import std.stdio; enum A : int { a, b }; enum B : int { a, b }; enum AS : string[2] { a = ["1","2"], b = ["3","4"] }; enum BS : string[2] { a = ["5","6"], b = ["7","8"] }; void func(A a) { writeln("A"); } void func(B b) { writeln("B"); } void funcs(AS a) { writeln("AS"); } void funcs(BS

Re: Need advice on using DUB registry

2017-04-02 Thread Eric via Digitalmars-d-learn
On Sunday, 2 April 2017 at 04:14:56 UTC, rikki cattermole wrote: On 02/04/2017 2:37 AM, Eric wrote: I'm planning on some day putting a package in the DUB registry. My package is dependent on my "util" package which is a collection of stuff I use across all my projects. Does this mean I

Need advice on using DUB registry

2017-04-01 Thread Eric via Digitalmars-d-learn
I'm planning on some day putting a package in the DUB registry. My package is dependent on my "util" package which is a collection of stuff I use across all my projects. Does this mean I also have to put my util package in the DUB registry? Could I just make "util" a git sub module of the

Re: Problem building DMD

2017-03-11 Thread Eric via Digitalmars-d-learn
On Saturday, 11 March 2017 at 17:54:55 UTC, ag0aep6g wrote: On 03/11/2017 06:41 PM, Eric wrote: I'm trying to build the master branch of DMD on redhat 7. I get the following errors: ddmd/root/newdelete.c:26:8: error: expected identifier or ‘(’ before string constant extern "C" ^

Re: Problem building DMD

2017-03-11 Thread Eric via Digitalmars-d-learn
On Saturday, 11 March 2017 at 17:54:55 UTC, ag0aep6g wrote: Looks like a C compiler is used instead of a C++ compiler. Despite the extension, dmd's *.c files are C++ code. Yes, that's what I thought - redhat has gcc, but not g++. There must be a needed compile option...

Problem building DMD

2017-03-11 Thread Eric via Digitalmars-d-learn
I'm trying to build the master branch of DMD on redhat 7. I get the following errors: ddmd/root/newdelete.c:26:8: error: expected identifier or ‘(’ before string constant extern "C" ^ ddmd/root/newdelete.c:31:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘new’

Re: Is this template constraint a bug?

2016-05-12 Thread Eric via Digitalmars-d-learn
Yes, it's a bug. Please file an issue. Meanwhile try this workaround: class A(T) { static assert(is(T : A!T), "..."); } Bug report filed, and thanks for the workaround. -Eric

Is this template constraint a bug?

2016-05-12 Thread Eric via Digitalmars-d-learn
is(T : A!T) tells if T can automatically be converted to A!T. The last line below is doing just that, yet the template constraint does not work. class A(T) if (is(T : A!T)) { } // if (is(T : A!T)) gives this error: // Error: template instance x.A!(B) does not match //template

Re: Is this a bug?

2016-04-15 Thread Eric via Digitalmars-d-learn
On Friday, 15 April 2016 at 18:28:58 UTC, Eric wrote: line 6 can be fixed like this: "const I!(J) i = a;" Now if I can just figure out how to fix line 15... This works: 1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 const (I!(J)) i = a; 7 } 8

Re: Is this a bug?

2016-04-15 Thread Eric via Digitalmars-d-learn
On Friday, 15 April 2016 at 18:22:02 UTC, Eric wrote: On Friday, 15 April 2016 at 17:43:59 UTC, ag0aep6g wrote: On 15.04.2016 19:13, Eric wrote: 1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 I!(J) i = a; 7 } 8 9 interface I(V) { }

Re: Is this a bug?

2016-04-15 Thread Eric via Digitalmars-d-learn
On Friday, 15 April 2016 at 17:43:59 UTC, ag0aep6g wrote: On 15.04.2016 19:13, Eric wrote: 1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 I!(J) i = a; 7 } 8 9 interface I(V) { } 10 11 class F(V) if (is(V : I!(V))) { } 12 13

Is this a bug?

2016-04-15 Thread Eric via Digitalmars-d-learn
1 alias J = const C; 2 3 void main(string[] args) 4 { 5 J a = new C(); 6 I!(J) i = a; 7 } 8 9 interface I(V) { } 10 11 class F(V) if (is(V : I!(V))) { } 12 13 class C : I!(J) 14 { 15 F!(J) m; 16 } The above code gives the following compile error: Error:

Re: Internal compiler erorr

2016-04-15 Thread Eric via Digitalmars-d-learn
On Monday, 11 April 2016 at 00:55:44 UTC, Mike Parker wrote: On Sunday, 10 April 2016 at 17:19:14 UTC, Eric wrote: I am getting this error when I compile: Error: Internal Compiler Error: unsupported type const(string) No line number is given. Does anyone know what causes this? compiler

Internal compiler erorr

2016-04-10 Thread Eric via Digitalmars-d-learn
I am getting this error when I compile: Error: Internal Compiler Error: unsupported type const(string) No line number is given. Does anyone know what causes this? compiler version = v2.071.0 -Eric

Re: Need help with DLANGUI

2015-03-24 Thread Eric via Digitalmars-d-learn
BTW, why do you need FreeImage to create image? Isn't it just possible inside dlangui? This is basically my question. Is there a drawing engine that can draw lines, circles, and shapes as well as single pixels? -Eric

opEquals unsafe? Please tell me this isnt true...

2014-11-24 Thread Eric via Digitalmars-d-learn
@safe class Y { } @safe class X { } @safe class Z { int x; this() { if (typeid(X) == typeid(Y)) x = 1; // Compile Error else x = 2; } } void main() { new Z; } // test.d(19): Error: safe function 'test.Z.this' // cannot call system function 'object.opEquals'

Re: opEquals unsafe? Please tell me this isnt true...

2014-11-24 Thread Eric via Digitalmars-d-learn
On Tuesday, 25 November 2014 at 02:48:43 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Monday, November 24, 2014 22:12:08 Eric via Digitalmars-d-learn wrote: @safe class Y { } @safe class X { } @safe class Z { int x; this() { if (typeid(X) == typeid(Y)) x

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 :

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 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 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: 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 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

how to compare the type of a subclass

2014-11-21 Thread Eric via Digitalmars-d-learn
Suppose I have: module test; class X { } class Y : X { } Y y = new Y; X x = y; assert(is(typeof(x) == test.Y); // this assertion will fail assert(typeid(x).toString() == test.Y); // this assertion will pass Is there a way I can check the type of x without doing a string comparison? -Eric

Re: how to compare the type of a subclass

2014-11-21 Thread Eric via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote: On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: Suppose I have: module test; class X { } class Y : X { } Y y = new Y; X x = y; assert(is(typeof(x) == test.Y); // this assertion will fail assert(typeid(x).toString() ==

Re: how to compare the type of a subclass

2014-11-21 Thread Eric via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:52:54 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Fri, Nov 21, 2014 at 10:30:51PM +, Eric via Digitalmars-d-learn wrote: On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote: On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote

overiding mutable methods in immutable classes

2014-11-21 Thread Eric via Digitalmars-d-learn
immutable class X { private int x; this(int x) { this.x = x; } ... override size_t toHash(); // error: can't override mutable method } Since toHash() cannot be overridden in an immutable class, is there a work-around? In other words, immutable X x1 = new immutable X(5);

Re: overiding mutable methods in immutable classes

2014-11-21 Thread Eric via Digitalmars-d-learn
But think about if enforced immutability is really what you want. You don't need to mark the fields immutable to be able to construct immutable Xs. A `pure` constructor is handy, as it can construct both mutable and immutable objects. class X { private int x; this(int x) pure {

Recursive template

2014-11-15 Thread Eric via Digitalmars-d-learn
Hi - I've never designed a recursive template before, but I think that would solve my problem. What I would like is someting like this: class X(V, K...) { // I want to declare a type based on K and V such // that for X!(V, int, string, double) the resulting // declaration would be:

Re: Recursive template

2014-11-15 Thread Eric via Digitalmars-d-learn
Thanks! -Eric On Saturday, 15 November 2014 at 18:49:32 UTC, anonymous wrote: On Saturday, 15 November 2014 at 18:30:00 UTC, Eric wrote: Hi - I've never designed a recursive template before, but I think that would solve my problem. What I would like is someting like this: class X(V,

memory/array question

2014-07-31 Thread Eric via Digitalmars-d-learn
Suppose I have some memory allocated on the heap, and I have two pointers pointing to the beginning and end of a contiguous segment of that memory. Is there a way I can convert those two pointers to an array slice without actually copying anything within the segment? Thx, Eric

Re: memory/array question

2014-07-31 Thread Eric via Digitalmars-d-learn
On Thursday, 31 July 2014 at 19:43:00 UTC, bearophile wrote: Eric: Suppose I have some memory allocated on the heap, and I have two pointers pointing to the beginning and end of a contiguous segment of that memory. Is there a way I can convert those two pointers to an array slice without

Re: memory/array question

2014-07-31 Thread Eric via Digitalmars-d-learn
On Thursday, 31 July 2014 at 20:59:46 UTC, Vlad Levenfeld wrote: On Thursday, 31 July 2014 at 20:43:11 UTC, bearophile wrote: Take a look at the asm! Bye, bearophile I use DMD and Dub, how do I view the asm? Actually I did't think to look at the asm, mainly because I've never bothered to

Need help with basic functional programming

2014-07-22 Thread Eric via Digitalmars-d-learn
I have been writing several lexers and parsers. The grammars I need to parse are really complex, and consequently I didn't feel confident about the code quality, especially in the lexers. So I decided to jump on the functional progamming bandwagon to see if that would help. It definitely

Re: Need help with basic functional programming

2014-07-22 Thread Eric via Digitalmars-d-learn
By the way, do you really mean to stop on '0' and '9'? Do you perhaps mean a '0' || a '9'? Yes, my bad...

Re: Need help with basic functional programming

2014-07-22 Thread Eric via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 17:09:29 UTC, bearophile wrote: Eric: while (!buf.empty()) { p++; buf.popFront(); Those () can be omitted, if you mind the noise (but you can also keep them). if (buf.front() = '0' || buf.front() = '9') break; std.ascii.isDigit

Really nooB question - @property

2014-07-21 Thread Eric via Digitalmars-d-learn
There are a lot of discussions in the forums about how @property should or could be implemented. But I can't seem to find anything that explains why or when I should use @property with the current compiler. Can anyone explain why and when I should use the @property tag? Thx. Eric

Re: Really nooB question - @property

2014-07-21 Thread Eric via Digitalmars-d-learn
Use @property when you want a pseudo-variable or something that might be conceptually considered a property of the object, i.e. to do this: auto blah = thing.someProperty; thing.someProperty = blahblah; This is basically what I suspected. But why write: @property int getValue() {