Re: union alignment

2016-05-21 Thread Iain Buclaw via Digitalmars-d-learn
On Wednesday, 18 May 2016 at 01:46:37 UTC, tsbockman wrote: Shouldn't a union type always have an `alignof` at least as great as the `alignof` for its largest member? On x86, there's a difference between the type alignment and the field alignment. The type align of ulong and double are 8

Re: Enum that can be 0 or null

2016-05-21 Thread tsbockman via Digitalmars-d-learn
On Saturday, 21 May 2016 at 01:09:42 UTC, Alex Parrill wrote: On Friday, 20 May 2016 at 22:10:51 UTC, tsbockman wrote: If that's not a satisfactory answer, please show some specific examples of code that you don't know how to make work without VK_NULL_HANDLE so that I can propose a workaround.

Re: union alignment

2016-05-21 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 18 May 2016 at 01:46:37 UTC, tsbockman wrote: Shouldn't a union type always have an `alignof` at least as great as the `alignof` for its largest member? Apparently not; it's actually DMD and LDC that are wrong here: http://bugzilla.gdcproject.org/show_bug.cgi?id=226

Re: Enum that can be 0 or null

2016-05-21 Thread tsbockman via Digitalmars-d-learn
On Saturday, 21 May 2016 at 01:53:21 UTC, Mike Parker wrote: When binding to a C library, it's desirable to have as close to the original C API as possible so that you *can* drop C snippets and examples into D code and have them just work. Obviously, 100% compatibility is not possible, but it

Re: Immutable objects and constructor ?

2016-05-21 Thread chmike via Digitalmars-d-learn
Unfortunately it is not possible to write this import std.typecons; class Info{...} rebindable!Info x; I get the following error message source/app.d(11,3): Error: template std.typecons.rebindable matches more than one template declaration: /usr/include/dmd/phobos/std/typecons.d(1675,14):

Re: Immutable objects and constructor ?

2016-05-21 Thread chmike via Digitalmars-d-learn
Since I'm trying to implement a flyweight pattern, the opEqual need only comparision of reference in my case. By the way, what operation is the switch performing ? OpEqual or is ?

Re: Single-Allocation Variable-Sized Array

2016-05-21 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 18 May 2016 at 23:45:07 UTC, Alex Parrill wrote: In C it's called a variable-length struct or object. I don't think D implements them, but this could probably work: Thanks!

Re: Immutable objects and constructor ?

2016-05-21 Thread Ali Çehreli via Digitalmars-d-learn
On 05/21/2016 01:07 AM, chmike wrote: > Unfortunately it is not possible to write this > > import std.typecons; > class Info{...} > rebindable!Info x; You have a capitalization typo. Rebindable is a type template, rebindable is a function template. import std.typecons; class Info{} void

Re: mutable keyword

2016-05-21 Thread ciechowoj via Digitalmars-d-learn
On Saturday, 21 May 2016 at 00:39:21 UTC, Jonathan M Davis wrote: Well, if you actually tried marking functions with pure, you'd see pretty fast that this won't work with pure. A function that's marked with pure cannot access any global, mutable state. It can only access what's passed to it

Re: problems with Rebindable

2016-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 05/21/2016 12:42 PM, chmike wrote: Rebindable!Info x1, x2 = Infos.one; Rebindable!(immutable Info) x1, x2 = Infos.one;

Re: Confusion with anonymous functions and method overloads

2016-05-21 Thread Anonymouse via Digitalmars-d-learn
On Saturday, 21 May 2016 at 14:39:59 UTC, pineapple wrote: void clean(in void delegate(in T value) func){ this.clean((in T values[]) => { foreach(value; values) func(value); }); This doesn't do what you think it does. It passes a lambda that *returns* that

Re: Is there a 128-bit integer in D?

2016-05-21 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 21 May 2016 at 09:43:38 UTC, Saurabh Das wrote: I see that 'cent' and 'ucent' are reserved for future use but not yet implemented. Does anyone have a working implementation of these types? Alternatively, is there an any effort towards implementation of arbitrary-sized integers

Re: problems with Rebindable

2016-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 05/21/2016 03:36 PM, chmike wrote: Note however that it doesn't work with immutable. It only works with constant. I guess this is because immutable is "stronger" than const. I determined that only const was supported by looking at Rebindable's code. Here is the code that finally works as I

Re: Immutable objects and constructor ?

2016-05-21 Thread chmike via Digitalmars-d-learn
On Saturday, 21 May 2016 at 08:24:19 UTC, Ali Çehreli wrote: On 05/21/2016 01:07 AM, chmike wrote: > Unfortunately it is not possible to write this > > import std.typecons; > class Info{...} > rebindable!Info x; You have a capitalization typo. Rebindable is a type template, rebindable is a

problems with Rebindable

2016-05-21 Thread chmike via Digitalmars-d-learn
This thread is a followup of https://forum.dlang.org/post/vuljzyufphsywzevu...@forum.dlang.org with a refocused subject and question. I'm looking for a mutable reference to a none mutable object to implement the flyweight pattern. It is for a library and its user interface. So I'm not

Re: problems with Rebindable

2016-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 05/21/2016 02:17 PM, chmike wrote: On Saturday, 21 May 2016 at 10:42:13 UTC, chmike wrote: source/app.d(23,27): Error: cannot implicitly convert expression (one) of type immutable(Obj) to app.Info Apparently Rebindable doesn't support polymorphism. This is hopefully fixable. No, the

Confusion with anonymous functions and method overloads

2016-05-21 Thread pineapple via Digitalmars-d-learn
I wrote a pair of methods that looked like this: void clean(in void delegate(in T value) func){ this.clean((in T values[]) => { foreach(value; values) func(value); }); } void clean(in void delegate(in T values[]) func){ ... } I was getting a

Re: Confusion with anonymous functions and method overloads

2016-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 05/21/2016 04:39 PM, pineapple wrote: But I don't understand why. Could someone clarify the difference between the two? Common mistake, because other languages (e.g. C#) use similar but different syntax. The `foo => bar` syntax doesn't use braces. When you add braces around bar, that's

Is there a 128-bit integer in D?

2016-05-21 Thread Saurabh Das via Digitalmars-d-learn
I see that 'cent' and 'ucent' are reserved for future use but not yet implemented. Does anyone have a working implementation of these types? Alternatively, is there an any effort towards implementation of arbitrary-sized integers in Phobos? Thanks, Saurabh

Re: mutable keyword

2016-05-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 21, 2016 07:00:43 ciechowoj via Digitalmars-d-learn wrote: > On Saturday, 21 May 2016 at 00:39:21 UTC, Jonathan M Davis wrote: > > Well, if you actually tried marking functions with pure, you'd > > see pretty fast that this won't work with pure. A function > > that's marked with

Re: problems with Rebindable

2016-05-21 Thread chmike via Digitalmars-d-learn
On Saturday, 21 May 2016 at 13:17:11 UTC, ag0aep6g wrote: On 05/21/2016 12:42 PM, chmike wrote: Rebindable!Info x1, x2 = Infos.one; Rebindable!(immutable Info) x1, x2 = Infos.one; Indeed. Thanks. Reading the unit tests in the source code and the implementation of Rebindable helped.

Re: Game Development Using D

2016-05-21 Thread ParticlePeter via Digitalmars-d-learn
On Saturday, 21 May 2016 at 16:01:26 UTC, Stefan Koch wrote: On Saturday, 21 May 2016 at 15:53:18 UTC, David wrote: Hi, I want to try to create a game using D. I'm a complete newbie though (other than having C/C++ experience). Where would I start? Does D have an openGL binding? I am assuming

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread dan via Digitalmars-d-learn
Thanks Vit, Meta, and Yuxuan for your speedy help! So 3 pieces to put together, function, const, and @property (and i guess final for protection against subclasses).

Re: binary expression...

2016-05-21 Thread captain_fid via Digitalmars-d-learn
On Saturday, 21 May 2016 at 18:33:53 UTC, Anonymouse wrote: On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote: Please forgive if asked before. My google skills seemed to fail me and didn't see any result from search. My problem is simple (though not my understanding LOL). struct D

Re: Is there a 128-bit integer in D?

2016-05-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 21, 2016 09:43:38 Saurabh Das via Digitalmars-d-learn wrote: > I see that 'cent' and 'ucent' are reserved for future use but not > yet implemented. Does anyone have a working implementation of > these types? The keywords are reserved for future use not in current use. So, no,

Re: mutable keyword

2016-05-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 21, 2016 17:15:16 Jack Applegame via Digitalmars-d-learn wrote: > On Friday, 20 May 2016 at 20:46:18 UTC, Jonathan M Davis wrote: > > Casting away const and mutating is undefined behavior in D. No > > D program should ever do it. > > Really? Mutating immutable is UB too, but look

Division - precision

2016-05-21 Thread Rygel via Digitalmars-d-learn
Hi there. I'm a beginners, so my questions could be silly. double x1 = 7.0; double x2 = 3.0; writeln(x1 / x2); from this code i get: 2.3 this is ok but how can i get more digits? For example: 2.3. thx :-)

Re: Basic question about stderr

2016-05-21 Thread chaseratx via Digitalmars-d-learn
On Saturday, 21 May 2016 at 21:40:36 UTC, Era Scarecrow wrote: On Saturday, 21 May 2016 at 21:21:31 UTC, chaseratx wrote: I'm learning D and I have a basic question. I'm trying to write stderr to a file using open() (rather than shell piping/redirection). It works for stdout but doesn't

Re: Game Development Using D

2016-05-21 Thread Rishub Nagpal via Digitalmars-d-learn
On Saturday, 21 May 2016 at 15:53:18 UTC, David wrote: Hi, I want to try to create a game using D. I'm a complete newbie though (other than having C/C++ experience). Where would I start? Does D have an openGL binding? I am assuming I'll need to leverage a good amount C APIs? Any list of

Re: problems with Rebindable

2016-05-21 Thread Kagamin via Digitalmars-d-learn
On Saturday, 21 May 2016 at 10:42:13 UTC, chmike wrote: switch(x1) { case Infos.one: writeln("case Infos.one"); break; default: writeln("default"); break; } You can generate fairly unique ids and use them in switch statements like this: https://dpaste.dzfl.pl/873b5b4cf71e

Re: Game Development Using D

2016-05-21 Thread Rishub Nagpal via Digitalmars-d-learn
On Saturday, 21 May 2016 at 15:53:18 UTC, David wrote: Hi, I want to try to create a game using D. I'm a complete newbie though (other than having C/C++ experience). Where would I start? Does D have an openGL binding? I am assuming I'll need to leverage a good amount C APIs? Any list of

Re: binary expression...

2016-05-21 Thread captain_fid via Digitalmars-d-learn
On Saturday, 21 May 2016 at 18:31:46 UTC, vit wrote: On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote: Please forgive if asked before. My google skills seemed to fail me and didn't see any result from search. My problem is simple (though not my understanding LOL). struct D {

Re: Basic question about stderr

2016-05-21 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 21 May 2016 at 21:21:31 UTC, chaseratx wrote: I'm learning D and I have a basic question. I'm trying to write stderr to a file using open() (rather than shell piping/redirection). It works for stdout but doesn't seem to work with stderr. http://pastebin.com/KgzR9wAF stdout is

Re: Small-Size-Optimized Array

2016-05-21 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 19 May 2016 at 06:20:24 UTC, Nikolay wrote: You can look to my experement (see iarray.d): https://bitbucket.org/sibnick/inplacearray.git Thanks!

Basic question about stderr

2016-05-21 Thread chaseratx via Digitalmars-d-learn
I'm learning D and I have a basic question. I'm trying to write stderr to a file using open() (rather than shell piping/redirection). It works for stdout but doesn't seem to work with stderr. http://pastebin.com/KgzR9wAF stdout is written to the file, but stderr is not and outputs to the

Game Development Using D

2016-05-21 Thread David via Digitalmars-d-learn
Hi, I want to try to create a game using D. I'm a complete newbie though (other than having C/C++ experience). Where would I start? Does D have an openGL binding? I am assuming I'll need to leverage a good amount C APIs? Any list of these that would be useful it a game setting? Obviously

Re: Game Development Using D

2016-05-21 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 21 May 2016 at 15:53:18 UTC, David wrote: Hi, I want to try to create a game using D. I'm a complete newbie though (other than having C/C++ experience). Where would I start? Does D have an openGL binding? I am assuming I'll need to leverage a good amount C APIs? Any list of

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread Meta via Digitalmars-d-learn
On Saturday, 21 May 2016 at 17:32:47 UTC, dan wrote: Is it possible to have a class which has a variable which can be seen from the outside, but which can only be modified from the inside? Something like: class C { int my_var = 3; // semi_const?? void do_something() { my_var = 4; } }

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 21 May 2016 at 17:32:47 UTC, dan wrote: Is it possible to have a class which has a variable which can be seen from the outside, but which can only be modified from the inside? Something like: class C { int my_var = 3; // semi_const?? void do_something() { my_var = 4; } }

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread vit via Digitalmars-d-learn
On Saturday, 21 May 2016 at 17:32:47 UTC, dan wrote: Is it possible to have a class which has a variable which can be seen from the outside, but which can only be modified from the inside? Something like: class C { int my_var = 3; // semi_const?? void do_something() { my_var = 4; } }

Re: problems with Rebindable

2016-05-21 Thread Kagamin via Digitalmars-d-learn
On Saturday, 21 May 2016 at 13:36:02 UTC, chmike wrote: static Info one() { static auto x = Info(new Obj("I'm one")); return x; } static Info two() { static auto x = Info(new Obj("I'm two")); return x; } FYI those are thread local

Re: mutable keyword

2016-05-21 Thread Jack Applegame via Digitalmars-d-learn
On Friday, 20 May 2016 at 20:46:18 UTC, Jonathan M Davis wrote: Casting away const and mutating is undefined behavior in D. No D program should ever do it. Really? Mutating immutable is UB too, but look at std.typecons.Rebindable.

Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread dan via Digitalmars-d-learn
Is it possible to have a class which has a variable which can be seen from the outside, but which can only be modified from the inside? Something like: class C { int my_var = 3; // semi_const?? void do_something() { my_var = 4; } } And then in another file auto c = new C(); c.my_var

binary expression...

2016-05-21 Thread captain_fid via Digitalmars-d-learn
Please forgive if asked before. My google skills seemed to fail me and didn't see any result from search. My problem is simple (though not my understanding LOL). struct D { int value; bool opEquals()(bool value) const { return (value == value); } } D aD; if (aD == 1) { // OK }

Re: binary expression...

2016-05-21 Thread Anonymouse via Digitalmars-d-learn
On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote: Please forgive if asked before. My google skills seemed to fail me and didn't see any result from search. My problem is simple (though not my understanding LOL). struct D { int value; bool opEquals()(bool value) const {

Re: binary expression...

2016-05-21 Thread vit via Digitalmars-d-learn
On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote: Please forgive if asked before. My google skills seemed to fail me and didn't see any result from search. My problem is simple (though not my understanding LOL). struct D { int value; bool opEquals()(bool value) const {

Re: problems with Rebindable

2016-05-21 Thread chmike via Digitalmars-d-learn
On Saturday, 21 May 2016 at 10:42:13 UTC, chmike wrote: source/app.d(23,27): Error: cannot implicitly convert expression (one) of type immutable(Obj) to app.Info Apparently Rebindable doesn't support polymorphism. This is hopefully fixable. source/app.d(43,5): Error: 'x1' must be of

Re: Basic question about stderr

2016-05-21 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote: On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote: Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output. I wonder, this sounds like a TLS (Thread Local Storage)

Re: binary expression...

2016-05-21 Thread Ali Çehreli via Digitalmars-d-learn
On 05/21/2016 12:56 PM, captain_fid wrote: > On Saturday, 21 May 2016 at 18:33:53 UTC, Anonymouse wrote: >> On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote: >>> Please forgive if asked before. My google skills seemed to fail me >>> and didn't see any result from search. >>> >>> My

Re: Basic question about stderr

2016-05-21 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote: Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output. I'm trying to figure out how to get ALL stderr output directed to a file the same as if I had used a "2>error.log"

Re: mutable keyword

2016-05-21 Thread ag0aep6g via Digitalmars-d-learn
On 05/21/2016 07:15 PM, Jack Applegame wrote: Really? Mutating immutable is UB too, but look at std.typecons.Rebindable. Rebindable uses a union of a mutable and an immutable variant of the type. No access to the mutable union member is provided, and it's never dereferenced by Rebindable.

Re: Is there a 128-bit integer in D?

2016-05-21 Thread Saurabh Das via Digitalmars-d-learn
On Saturday, 21 May 2016 at 21:51:34 UTC, Jonathan M Davis wrote: On Saturday, May 21, 2016 09:43:38 Saurabh Das via Digitalmars-d-learn wrote: I see that 'cent' and 'ucent' are reserved for future use but not yet implemented. Does anyone have a working implementation of these types? The

Re: Basic question about stderr

2016-05-21 Thread chaseratx via Digitalmars-d-learn
On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote: On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote: Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output. I'm trying to figure out how to get ALL stderr output

Re: Basic question about stderr

2016-05-21 Thread chaseratx via Digitalmars-d-learn
On Saturday, 21 May 2016 at 22:08:15 UTC, Era Scarecrow wrote: On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote: On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote: Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr

Re: Division - precision

2016-05-21 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 21 May 2016 at 21:45:19 UTC, Rygel wrote: Hi there. I'm a beginners, so my questions could be silly. double x1 = 7.0; double x2 = 3.0; writeln(x1 / x2); this is ok but how can i get more digits? For example: 2.3. I'm not sure how to globally

Re: Division - precision

2016-05-21 Thread Ali Çehreli via Digitalmars-d-learn
On 05/21/2016 02:45 PM, Rygel wrote: > Hi there. I'm a beginners, so my questions could be silly. > > double x1 = 7.0; > double x2 = 3.0; > writeln(x1 / x2); > > from this code i get: > > 2.3 > > this is ok but how can i get more digits? For example: > > 2.3. > >

Re: Division - precision

2016-05-21 Thread Rygel via Digitalmars-d-learn
Ah, ok, got it. thx you all.

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 22 May 2016 at 03:06:44 UTC, Mike Parker wrote: As for 'const' and '@property', neither is strictly a requirement to implement this idiom. Adding const means that Oh, and the same holds true for final, of course. It's probably what you want most of the time, but it isn't strictly

Generation of AST for semantic rule checking

2016-05-21 Thread Chris Katko via Digitalmars-d-learn
I have an idea for something. I know I can't be the only one to think this way but I can't find very much information on it. Basically, I want compile-time enforcement of semantic rules. For one example--I asked previously here--if it was possible to generate a compile-time warning or error

Re: Basic question about stderr

2016-05-21 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 21 May 2016 at 22:11:30 UTC, chaseratx wrote: On Saturday, 21 May 2016 at 22:08:15 UTC, Era Scarecrow wrote: On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote: On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote: Thanks Era, but I am not trying to fix the range

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 21 May 2016 at 19:17:00 UTC, dan wrote: Thanks Vit, Meta, and Yuxuan for your speedy help! So 3 pieces to put together, function, const, and @property (and i guess final for protection against subclasses). Minimally, there are two pieces to this: a private member variable and a