Re: How to generate a random number from system clock as seed

2024-06-10 Thread Eric P626 via Digitalmars-d-learn
On Sunday, 9 June 2024 at 23:31:47 UTC, drug007 wrote: ```d const seed = cast(uint) Clock.currStdTime; ``` Casting like this looks nice. It fits my type of thinking.

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Eric P626 via Digitalmars-d-learn
On Sunday, 9 June 2024 at 13:20:09 UTC, Joseph Rushton Wakeling wrote: On Saturday, 8 June 2024 at 16:09:04 UTC, monkyyy wrote: rng is an optional parameter, `uniform(0,100).writeln;` alone works; the docs not telling you that is really bad The docs do tell you that `rng` is an optional parame

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Eric P626 via Digitalmars-d-learn
On Saturday, 8 June 2024 at 18:25:20 UTC, drug007 wrote: ~~~ { const seed = castFrom!long.to!uint(Clock.currStdTime); auto rng = Random(seed); auto result = generate!(() => uniform(0, 10, rng))().take(7); // new random numbers sequence every time res

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Eric P626 via Digitalmars-d-learn
On Saturday, 8 June 2024 at 21:04:16 UTC, monkyyy wrote: generate is a very rare function and do novices understand lamdas? Yes I know lamdas, but try not to use them. I am not very picky about the exact source of time, I just want a different integer every time I run the program. But while l

How to generate a random number from system clock as seed

2024-06-08 Thread Eric P626 via Digitalmars-d-learn
I managed to create a random number generator using the following code: ~~~ auto rng = Random(42); // uniform(0,10,rng); ~~~ Now I want to seed the generator using system time. I looked at Date & time functions/classes and systime functions/classes. The problem is that they all require a

Re: How to pass in reference a fixed array in parameter

2024-06-05 Thread Eric P626 via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 10:36:50 UTC, Nick Treleaven wrote: ```d import std.stdio; alias s_cell = int; void main() { writeln("Maze generation demo"); s_cell [5][5] maze; int n; foreach (i, row; maze) foreach (j, col; row) maze[i][j] = n++; s_cell[][5] slic

Re: How to pass in reference a fixed array in parameter

2024-06-04 Thread Eric P626 via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 16:19:39 UTC, Andy Valencia wrote: On Tuesday, 4 June 2024 at 12:22:23 UTC, Eric P626 wrote: I tried to find a solution on the internet, but could not find anything, I stumble a lot on threads about Go or Rust language even if I specify "d language" in

How to pass in reference a fixed array in parameter

2024-06-04 Thread Eric P626 via Digitalmars-d-learn
I am currently trying to learn how to program in D. I thought that I could start by trying some maze generation algorithms. I have a maze stored as 2D array of structure defined as follow which keep tracks of wall positions: ~~~ struct s_cell { bool north = true; bool east = true; boo

Re: A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.

2023-05-02 Thread Eric P626 via Digitalmars-d-learn
Any D function marked as extern(C) can be called from C. As long as you have a C header file defining the functions and the appropriate C declarations any custom types you have, the C code will have no idea it's calling into a D library. Thanks for the example. It clarify things up. The drunti

Re: A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.

2023-05-01 Thread Eric P626 via Digitalmars-d-learn
This is a false dilemma: D has full C compatibility. From what I understand, D can use C, but C cannot use D? It's like C++: C++ can call C but C cannot call C++. 50% or more of my code will be put in re-usabled libraries. If I want people to use those libs, I would need to compile them in C

A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.

2023-04-30 Thread Eric P626 via Digitalmars-d-learn
The title of this thread might be weird, but I am currently reconsidering the language and tools I am using before returning to production again. # Objective and projects Make simple turn based (no animation) video games using Allegro 4, maybe 5, and eventually SDL on multiple platforms: Linu

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

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 time.

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 that's

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 explicitl

Re: crash when using &this 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 Tes

Re: crash when using &this 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 &this 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 &this 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 = &this; // <-- 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, N2.s

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)) < __traits(identifier

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 id;

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
In the above code, the function with the simple enum type argument can be overloaded, but the function with the complex enum type argument cannot be overloaded. Is this a bug? Thx. Eric

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. D

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 pa

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 exte

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’ v

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
declaration A(T) if (is(T : A!T)) //while looking for match for A!(B) class B : A!(B) { } void main(string[] args) { B b = new B(); A!B a = b; // compiles fine } -Eric

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;

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
nverted to I!(V) then this template can be used". However, line 6 does not give an error, and it seems to be automaticaly converting J to I!(J). -Eric

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

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

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

2014-11-24 Thread Eric via Digitalmars-d-learn
object.opEquals' Isn't this analagous to saying that the "instanceof" operator in java endangers the GC? Is it correct to replace '==' with 'is'? -Eric

Re: overiding mutable methods in immutable classes

2014-11-22 Thread Eric via Digitalmars-d-learn
; } } void main() { immutable(Y) y = new immutable Y(4); X!(immutable(Y)) x = new X!(immutable(Y))(y); } Thanks for your help. -Eric

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 /

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

2014-11-22 Thread Eric via Digitalmars-d-learn
at has a limit. Try this: import std.stdio; enum A = 65536; enum B = 32; alias MyType = int[A][B]; void foo(ref MyType arr) { writeln(arr[3][3]); } MyType arr; void main() { writeln("arr[3][3] = ", arr[3][3]); foo(arr); } -Eric

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 wrote: Maybe this is not so lame because change() can take any length of static array. void change (int[] arr) { arr[1] = 42

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

2014-11-22 Thread Eric via Digitalmars-d-learn
2, 3]; writeln("a = ", a); change(a.ptr); writeln("a = ", a); } Maybe this is not so lame because change() can take any length of static array. -Eric

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

2014-11-22 Thread Eric via Digitalmars-d-learn
writeln("a = ", a); } -Eric

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: overiding mutable methods in immutable classes

2014-11-21 Thread Eric via Digitalmars-d-learn
. 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. -Eric

overiding mutable methods in immutable classes

2014-11-21 Thread Eric via Digitalmars-d-learn
e X(5); immutable X x2 = new immutable X(5); I would like for x1.toHash() to equal x2.toHash(), but this is not the case because toHash() cannot be overridden. Note also that (x1 != x2) even though they should be equal (I think...) Is this a bug or a feature? -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: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 wr

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

how to compare the type of a subclass

2014-11-21 Thread Eric via Digitalmars-d-learn
comparison? -Eric

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

Recursive template

2014-11-15 Thread Eric via Digitalmars-d-learn
ld be: SomeType!(int, SomeType!(string, SomeType!(double, V))) var; // or put another way: SomeType!(K[0], SomeType!(K[1], SomeType(K[2], V))) var; } Can anyone give me some ideas on how to set up the declaration? Thanks, Eric

Re: memory/array question

2014-07-31 Thread Eric via Digitalmars-d-learn
othered to do it before. But I was just reading Adam's book the other day, and I remember seeing this: objdump -d -M intel simpleOctal Not sure what the switches are for; the name of the program is simpleOctal. But the name of the utility is objdump. (on Linux). Not sure about Windoze. -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

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

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

Need help with basic functional programming

2014-07-22 Thread Eric via Digitalmars-d-learn
curTok.image = to!string(s); } The problem is that "until" seems to not stop at the end of the number, and instead continues until the end of the buffer. Am I doing something wrong here? Also, what is the fastest way to convert a range to a string? Thanks, Eric

Re: Really nooB question - @property

2014-07-21 Thread Eric via Digitalmars-d-learn
t getValue() { return(value); } When you could just have a public field: int value; That lets you set and get the value without the parens anyways? thanks, Eric

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: Update to TDPL?

2014-04-13 Thread Eric
ive D" and "D CTFE" -Eric

Re: two questions on enums

2014-04-04 Thread Eric
tever type the enum happens to implement. In java, all enums are of enum type. So it's probably me that's confused. -Eric

Re: two questions on enums

2014-04-03 Thread Eric
On Thursday, 3 April 2014 at 22:34:19 UTC, bearophile wrote: Eric: I disagree. If you just think of a class type enum as a class type, then what you say makes sense. But if you instead think of it as a more powerful enum then it can enhance data safety in a program. I was speaking about

Re: two questions on enums

2014-04-03 Thread Eric
they are designed mostly for integral built-in types, including chars, etc. I disagree. If you just think of a class type enum as a class type, then what you say makes sense. But if you instead think of it as a more powerful enum then it can enhance data safety in a program. -Eric

two questions on enums

2014-04-03 Thread Eric
nsistent. Would it make sense to have like an "uint opOrdinal()" method that would return a value known at compile time so that class or struct enums can be used in switch statements? Thanks, Eric

RE: enum question

2014-03-18 Thread eric
Awesome... it works!-Eric Original Message Subject: Re: enum question From: Ali Çehreli <acehr...@yahoo.com> Date: Tue, March 18, 2014 3:51 pm To: digitalmars-d-learn@puremagic.com On 03/18/2014 01:40 PM, Eric wrote: > Apparently you can't pass an enum as a ref

Re: enum question

2014-03-18 Thread Eric
On Tuesday, 18 March 2014 at 20:56:45 UTC, Adam D. Ruppe wrote: On Tuesday, 18 March 2014 at 20:40:36 UTC, Eric wrote: However, using struct type seems inefficient because structs are pass by value. That's not necessarily a problem, especially if the struct is small, passing by val

enum question

2014-03-18 Thread Eric
have read on this forum that someday enums may be able to be made with class elements. Can enums be made of classes yet, or is there a way to make the enum based on structs more efficient? Thanks, Eric

Re: Cannot implicitly convert derived type

2014-02-22 Thread Eric Suen
4 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 eit

Re: Cannot implicitly convert derived type

2014-02-21 Thread Eric Suen
Generic? "Frustrated" ... > interface iGui > { > @property iButton button(ref iButton button); > } > > class WindowsGui : iGui > { > WindowsButton _button; > > @property WindowsButton button(ref WindowsButton button) > //@property iButton button(ref iButton button) > { > _button = button; > retur

Question on static declaration

2014-01-11 Thread Eric
Apparently the line, static shared static int x; will compile just fine. Is this sort of a bug, or does it mean something different from just static shared int x; ? Also, the line, static static static int x; will also compile. Does this mean x is extra static? -Eric

Re: Overload of ! operator

2013-06-25 Thread Eric
I should have also added that the overloaded ! method returns a class instance and not a bool. -Eric

Re: Overload of ! operator

2013-06-25 Thread Eric
On Wednesday, 26 June 2013 at 04:16:30 UTC, Ali Çehreli wrote: On 06/25/2013 09:05 PM, Jonathan M Davis wrote: > On Wednesday, June 26, 2013 05:35:03 cal wrote: >> On Wednesday, 26 June 2013 at 02:50:51 UTC, Eric wrote: >>> Is there a way to overload the ! operator? I can&#x

Overload of ! operator

2013-06-25 Thread Eric
Is there a way to overload the ! operator? I can't seem to get it to work with the standard unaryOp method. I need this because I am making a wrapper for a C++ API that has ! overloaded. -Eric

Re: static class instances not allowed?

2013-06-11 Thread Eric
On Tuesday, 11 June 2013 at 16:09:39 UTC, Steven Schveighoffer wrote: On Tue, 11 Jun 2013 10:04:21 -0400, Eric wrote: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error These can

Re: static class instances not allowed?

2013-06-11 Thread Eric
ances is a compiler bug? -Eric

static class instances not allowed?

2013-06-11 Thread Eric
ass thread local variable are allowed, not T.Foo T.d(5): Error: variable T.g is mutable. Only const or immutable class thread local variable are allowed, not T.Foo Why aren't static class instances allowed? Is there a work-around, or alternative approach to this? Thanks, Eric

Re: std.traits functions causing the compiler to crash

2013-06-07 Thread Eric
On Saturday, 8 June 2013 at 02:32:57 UTC, bearophile wrote: Eric: Yes, the template constraint is much better. However, the compiler still crashes, even with the new code: Because there's a type definition loop, regardless. Using a constraint doesn't change that situat

Re: std.traits functions causing the compiler to crash

2013-06-07 Thread Eric
ass Foo(K): Identity!(Foo!K, K) { K k; } void main() { new Foo!double; } (dmd7) mrbig:~/tp/d_test2/dlib>dmd Test.d Segmentation fault (core dumped) In D return is not a function, so don't use the ( ). Yeah, I know. return returns an expression, and parenthesis are legal expression syntax:) -Eric

std.traits functions causing the compiler to crash

2013-06-07 Thread Eric
using compiler version v2.063-devel-53aa503. Is this a known problem, or is there a work-around? Thanks, Eric

Re: Question on class templates

2013-06-07 Thread Eric
On Friday, 7 June 2013 at 18:06:26 UTC, anonymous wrote: On Friday, 7 June 2013 at 17:52:48 UTC, Eric wrote: interface Identity(V, K) { } class X(V, K) : Identity!(V, K) { private K k; public this(K k) { this.k = k; } } void main() { auto x = new X!(X, double)(6.0); } Hi - I have

Question on class templates

2013-06-07 Thread Eric
, double) does not match template declaration X(V, K) If I change the template parameter X to something else, like string, it compiles fine. But I want the Identity interface to know the type of the implementing class. Is that possible? Thanks, Eric

Re: Question about calling D method from C/C++

2013-06-03 Thread Eric
On Monday, 3 June 2013 at 17:20:22 UTC, Jacob Carlborg wrote: On 2013-06-03 17:42, Eric wrote: Thanks. That fixed my problem. This is my first D program, so I wouldn't have figured it out on my own... If it's not obvious, you should terminate the runtime as well when your pr

Re: Question about calling D method from C/C++

2013-06-03 Thread Eric
first D program, so I wouldn't have figured it out on my own... -Eric

Question about calling D method from C/C++

2013-06-02 Thread Eric
If I use "new" inside a D method that is called from a c++ program it causes a segmentation fault. For example: C++ code: #include "dcode.h" int main(int argc, char *argv[]) { hello(); return(0); } D code: class X { private int x; this() { x = 5; } public int getX() { ret