Re: Struct initialization syntax

2018-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 18, 2018 at 03:50:15AM +, arturg via Digitalmars-d-learn wrote: > On Wednesday, 17 January 2018 at 17:37:07 UTC, H. S. Teoh wrote: > > On Wed, Jan 17, 2018 at 05:31:03PM +, Azi Hassan via > > Digitalmars-d-learn wrote: > > > The D tour for structs uses a syntax similar to that

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m = abs(n); Well, since I'm in the learn forum and you seem to

Re: Vibe-d issue with timer in separate thread on debug builds

2018-01-17 Thread Andres Clari via Digitalmars-d-learn
On Tuesday, 16 January 2018 at 09:04:18 UTC, Sönke Ludwig wrote: Am 10.01.2018 um 15:40 schrieb Andres Clari: Hi, I have an app that uses vibe tasks, fibers and timers extensively, and I found an issue only for debug builds, when canceling a timer. However the code in question works just fine

Re: C++ function mangling Linux GCC

2018-01-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 18 January 2018 at 04:16:18 UTC, Laeeth Isharc wrote: Am I missing something, or should extern(C++) just work for binding to gcc C++ on Linux. It works fine for primitives but fails for pointer type arguments. Extern "C" works fine. Does D know how to mangle function names

C++ function mangling Linux GCC

2018-01-17 Thread Laeeth Isharc via Digitalmars-d-learn
Am I missing something, or should extern(C++) just work for binding to gcc C++ on Linux. It works fine for primitives but fails for pointer type arguments. Extern "C" works fine. Does D know how to mangle function names based on pointer types? I have created matching types on both sides.

Re: Struct initialization syntax

2018-01-17 Thread arturg via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 17:37:07 UTC, H. S. Teoh wrote: On Wed, Jan 17, 2018 at 05:31:03PM +, Azi Hassan via Digitalmars-d-learn wrote: The D tour for structs uses a syntax similar to that of C++ in order to initialize a Person struct : Person p(30, 180). Is this syntax supported

Re: New integer promotion rules

2018-01-17 Thread Rubn via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m = abs(n);

Re: Implicit conversion

2018-01-17 Thread Mike Franklin via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 23:15:33 UTC, Jiyan wrote: I want to convert from ints implicit to a struct type, so for example: I'm not sure what your actual use case is, but based on the example, you can just template `useV`. import std.stdio; struct use { int x;

Re: Implicit conversion

2018-01-17 Thread Ali Çehreli via Digitalmars-d-learn
On 01/17/2018 03:15 PM, Jiyan wrote: > Hello, > > I want to convert from ints implicit to a struct type, so for example: > > struct use > { > int x; > > int toInt() > { > return x; > } > > use fromInt(int v) > { > return use(v); > } > >

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 11:30 PM, rumbu wrote: 1. Why do I need explicitely to promote my byte to int in order to assign it to an ulong? 2.077: ulong u = -b; 2.088: ulong u = -cast(int)b; Those two snippets are not equivalent. When b = byte.min, the 2.077 snippet gives u = 18446744073709551488, while

Re: New integer promotion rules

2018-01-17 Thread Ali Çehreli via Digitalmars-d-learn
On 01/17/2018 02:30 PM, rumbu wrote: > 1. Why do I need explicitely to promote my byte to int in order to > assign it to an ulong? > 2.077: ulong u = -b; 2.088: ulong u = -cast(int)b; You're not assigning your byte to ulong; you're assigning the expression -b to ulong. -b is discovered to have

Implicit conversion

2018-01-17 Thread Jiyan via Digitalmars-d-learn
Hello, I want to convert from ints implicit to a struct type, so for example: struct use { int x; int toInt() { return x; } use fromInt(int v) { return use(v); } alias toInt this; // implicit

Re: __gshared as part of alias

2018-01-17 Thread kinke via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 22:01:57 UTC, Johan Engelen wrote: ``` struct GSharedVariable(AddrSpace as, T) { static __gshared T val; alias val this; } alias Global(T) = GSharedVariable!(AddrSpace.Global, T); Global!float bar1; // __gshared ``` Only 1 value per T though. ;)

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 21:12:07 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral

Re: __gshared as part of alias

2018-01-17 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 12 January 2018 at 04:25:25 UTC, Nicholas Wilson wrote: Is there a way to make __gshared part of an alias? Hi Nick, how about this? ``` struct GSharedVariable(AddrSpace as, T) { static __gshared T val; alias val this; } alias Global(T) = GSharedVariable!(AddrSpace.Global,

Re: New integer promotion rules

2018-01-17 Thread Rubn via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078:

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 09:30 PM, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078: static if (T.sizeof >= 4)   

Re: New integer promotion rules

2018-01-17 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078:

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078: static if (T.sizeof >= 4) auto max = isNegative ?

Re: Any sample how to use Sqlite-d?

2018-01-17 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 13:36:26 UTC, Marc wrote: I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db =

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 19:54:50 UTC, ag0aep6g wrote: On 01/17/2018 08:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b)

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 08:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b) Why do I need a to promote a byte to int to obtain an ulong?

New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b) Why do I need a to promote a byte to int to obtain an ulong? Even in the extreme case where b is

Re: Struct initialization syntax

2018-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2018 at 05:31:03PM +, Azi Hassan via Digitalmars-d-learn wrote: > The D tour for structs uses a syntax similar to that of C++ in order > to initialize a Person struct : Person p(30, 180). Is this syntax > supported in D ? Running that part of the code neither works on the >

Re: Any sample how to use Sqlite-d?

2018-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2018 at 01:36:26PM +, Marc via Digitalmars-d-learn wrote: > I was looking for a library to use SQLite with D, found this > (https://code.dlang.org/packages/sqlite-d) but it has no documentation > or code example. I looked into files in the source code and wrote > this: > > >

Struct initialization syntax

2018-01-17 Thread Azi Hassan via Digitalmars-d-learn
The D tour for structs uses a syntax similar to that of C++ in order to initialize a Person struct : Person p(30, 180). Is this syntax supported in D ? Running that part of the code neither works on the playground nor on my machine (dmd v2.076.0).

Re: __gshared as part of alias

2018-01-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 17, 2018 10:44:24 Nicholas Wilson via Digitalmars-d- learn wrote: > On Wednesday, 17 January 2018 at 07:53:24 UTC, Jonathan M Davis > > wrote: > > I don't know what you're doing, and maybe __gshared is the > > appropriate solution for what you're trying to do, but in > >

Any sample how to use Sqlite-d?

2018-01-17 Thread Marc via Digitalmars-d-learn
I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db = Database(name); auto table = db.table(tableName); auto rows =

Re: @safe matching on subclass type

2018-01-17 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 13:19:42 UTC, Nordlöw wrote: Why isn't polymorphic down-casts such as in the following pattern matching on sub-class class Base {} class Sub : Base {} @safe unittest { auto base = new Base(); if (auto sub = cast(Sub)base) { // use sub }

@safe matching on subclass type

2018-01-17 Thread Nordlöw via Digitalmars-d-learn
Why isn't polymorphic down-casts such as in the following pattern matching on sub-class class Base {} class Sub : Base {} @safe unittest { auto base = new Base(); if (auto sub = cast(Sub)base) { // use sub } } allowed in safe D?

Re: __gshared as part of alias

2018-01-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 07:53:24 UTC, Jonathan M Davis wrote: I don't know what you're doing, and maybe __gshared is the appropriate solution for what you're trying to do, but in general, if you're not trying to bind to a C global variable, you should be using shared, and using

Re: private selective import + overload = breaks accessibility rules

2018-01-17 Thread Seb via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 07:40:36 UTC, Joakim wrote: Are you sure about this? I thought such module-scope selective imports were supposed to be private by default since Martin's fixes for bug 314, which is why you submitted pull 5584. Bug 17630 is about something different, that