Const/Immutable Slicing Syntax

2016-11-22 Thread Nordlöw via Digitalmars-d-learn
What's the cleanest way of doing const or immutable slicing in D? My first thought is cast((const typeof(x))x)[] cast((immutable typeof(x))x)[] but that's too verbose for my/taste. Is there a Phobos function for this?

Re: Const/Immutable Slicing Syntax

2016-11-22 Thread Jack Applegame via Digitalmars-d-learn
cast(const) x[]; cast(immutable) x[];

Re: How to muldiv in D?

2016-11-22 Thread Kagamin via Digitalmars-d-learn
Yep, I need muldiv for long values on x86-64.

Re: How to muldiv in D?

2016-11-22 Thread rumbu via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 08:54:36 UTC, Kagamin wrote: Yep, I need muldiv for long values on x86-64. Quick and dirty assembler: version(D_InlineAsm_X86_64): long muldiv(long a, long b, long c) { //windows RCX, RDX, R8 //linux RDI, RSI, RDX version(Windows) { asm

mqtt client id

2016-11-22 Thread kushal bhattacharya via Digitalmars-d-learn
hi, I am totally following what hivemq and mqtt specs are telling.But i have confusion regarding their implementation.In mqtt specs they are suggesing to generate random client id if cleansession flag is true and not for cleansession flag being false.My question is how do i really implement t

Re: Is there a way to identfy Windows version?

2016-11-22 Thread Bauss via Digitalmars-d-learn
On Monday, 21 November 2016 at 09:11:39 UTC, Jonathan M Davis wrote: On Monday, November 21, 2016 08:57:11 Bauss via Digitalmars-d-learn wrote: [...] Phobos doesn't have anything like that, but you can use the C functions from the Windows API to do it. A quick search turned up GetVersion and

Get return type of a template function without instantiating it

2016-11-22 Thread Yuxuan Shui via Digitalmars-d-learn
Is there a way to get a template function return type with instantiating it? The return type is independent of the template arguments. I'm asking because there's potentially recursive template instantiation if I do try to instantiate it.

Re: Get return type of a template function without instantiating it

2016-11-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 12:21:18 UTC, Yuxuan Shui wrote: Is there a way to get a template function return type with instantiating it? The return type is independent of the template arguments. I'm asking because there's potentially recursive template instantiation if I do try to instan

Re: Get return type of a template function without instantiating it

2016-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 22, 2016 12:21:18 Yuxuan Shui via Digitalmars-d-learn wrote: > Is there a way to get a template function return type with > instantiating it? The return type is independent of the template > arguments. No. There _is_ no function unless the template is instantiated. Remember t

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Nordlöw via Digitalmars-d-learn
On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: Let me know if it's not the equivalent of the original. Ali Nice. What about putting this in a druntime or phobos PR, making it standardized?

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Nordlöw via Digitalmars-d-learn
On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: mixin template RvalueRef()// <-- DOES NOT TAKE A PARAMETER ANY MORE { alias T = typeof(this); static assert (is(T == struct)); @nogc @safe ref const(T) byRef() const pure nothrow return Why do you need to qual

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Ali Çehreli via Digitalmars-d-learn
On 11/22/2016 05:06 AM, Nordlöw wrote: On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: mixin template RvalueRef()// <-- DOES NOT TAKE A PARAMETER ANY MORE { alias T = typeof(this); static assert (is(T == struct)); @nogc @safe ref const(T) byRef() const pure n

Char representation

2016-11-22 Thread RazvanN via Digitalmars-d-learn
Given the following code: char[5] a = ['a', 'b', 'c', 'd', 'e']; alias Range = char[]; writeln(is(ElementType!Range == char)); One would expect that the program will print true. In fact, it prints false and I noticed that if Range is char[], wchar[], dchar[], string, wstring, dstring Unqual

Re: Char representation

2016-11-22 Thread rikki cattermole via Digitalmars-d-learn
On 23/11/2016 2:29 AM, RazvanN wrote: Given the following code: char[5] a = ['a', 'b', 'c', 'd', 'e']; alias Range = char[]; writeln(is(ElementType!Range == char)); One would expect that the program will print true. In fact, it prints false and I noticed that if Range is char[], wchar[], dch

Re: Char representation

2016-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 13:29:47 UTC, RazvanN wrote: Given the following code: char[5] a = ['a', 'b', 'c', 'd', 'e']; alias Range = char[]; writeln(is(ElementType!Range == char)); One would expect that the program will print true. In fact, it prints false and I noticed that if Range

Re: Char representation

2016-11-22 Thread Daniel Kozak via Digitalmars-d-learn
Dne 22.11.2016 v 14:29 RazvanN via Digitalmars-d-learn napsal(a): Given the following code: char[5] a = ['a', 'b', 'c', 'd', 'e']; alias Range = char[]; writeln(is(ElementType!Range == char)); One would expect that the program will print true. In fact, it prints false and I noticed that if

Re: Char representation

2016-11-22 Thread Daniel Kozak via Digitalmars-d-learn
Dne 22.11.2016 v 14:29 RazvanN via Digitalmars-d-learn napsal(a): Given the following code: char[5] a = ['a', 'b', 'c', 'd', 'e']; alias Range = char[]; writeln(is(ElementType!Range == char)); One would expect that the program will print true. In fact, it prints false and I noticed that if

Re: Char representation

2016-11-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 13:29:47 UTC, RazvanN wrote: Is this a bug? The language is sane. The standard library is not alas, it is insane by design, so not a bug.

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Nordlöw via Digitalmars-d-learn
On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: ref const(T) byRef() const pure nothrow return Add when DIP-1000 has been implemented into compiler this should be `scope`-qualified aswell, right?

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Namespace via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 13:06:27 UTC, Nordlöw wrote: On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: mixin template RvalueRef()// <-- DOES NOT TAKE A PARAMETER ANY MORE { alias T = typeof(this); static assert (is(T == struct)); @nogc @safe ref const(

Re: Get return type of a template function without instantiating it

2016-11-22 Thread Meta via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 12:21:18 UTC, Yuxuan Shui wrote: Is there a way to get a template function return type with instantiating it? The return type is independent of the template arguments. I'm asking because there's potentially recursive template instantiation if I do try to instan

Re: Char representation

2016-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 22, 2016 13:29:47 RazvanN via Digitalmars-d-learn wrote: > Given the following code: > > char[5] a = ['a', 'b', 'c', 'd', 'e']; > alias Range = char[]; > writeln(is(ElementType!Range == char)); > > One would expect that the program will print true. In fact, it > prints f

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Guillaume Piolat via Digitalmars-d-learn
On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: Let me know if it's not the equivalent of the original. Ali I've changed the idiom, thanks. The place to discuss this is the d-idioms bugtracker, else I would have skipped this message.

Re: Char representation

2016-11-22 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 13:29:47 UTC, RazvanN wrote: Given the following code: char[5] a = ['a', 'b', 'c', 'd', 'e']; alias Range = char[]; writeln(is(ElementType!Range == char)); One would expect that the program will print true. In fact, it prints false and I noticed that if Range

Re: Is there a way to identfy Windows version?

2016-11-22 Thread rumbu via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 11:00:52 UTC, Bauss wrote: On Monday, 21 November 2016 at 09:11:39 UTC, Jonathan M Davis wrote: On Monday, November 21, 2016 08:57:11 Bauss via Digitalmars-d-learn wrote: [...] Phobos doesn't have anything like that, but you can use the C functions from the Wi

Re: Memory allocation failed. Why?

2016-11-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/21/16 11:53 AM, ag0aep6g wrote: On Monday, 21 November 2016 at 16:37:32 UTC, Kagamin wrote: Anything in .data and .bss sections and stack. See https://issues.dlang.org/show_bug.cgi?id=15723 Ok, not an actual reference then, but a false pointer. Yes. 100 million bytes is 1/40 of all add

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Satoshi via Digitalmars-d-learn
On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: First, a reminder that we have this great resource of D idioms: https://p0nce.github.io/d-idioms/#Rvalue-references:-Understanding-auto-ref-and-then-not-using-it The link above has an idiom of mixing in a byRef() member function

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread kink via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 16:05:35 UTC, Satoshi wrote: Sorry, but D seems to be worse and worse day by day. This should be resolved by language and not doing it by template function. I hate this 'idiom' too (just a clumsy workaround for something that should work out of the box), but th

Re: implementing --version?

2016-11-22 Thread mab-on via Digitalmars-d-learn
Thanks! These tips are exactly what i needed :)

Re: Complex numbers are harder to use than in C

2016-11-22 Thread Marduk via Digitalmars-d-learn
On Sunday, 20 November 2016 at 12:08:23 UTC, Ilya Yaroshenko wrote: You can use builtin complex numbers (cfloat/cdouble/creal). The idea of std.complex is wrong . Mir GLAS uses builtin complex numbers and I don't think they will be really deprecated. --Ilya Good to know! The builtin syntax i

Re: Complex numbers are harder to use than in C

2016-11-22 Thread Marduk via Digitalmars-d-learn
On Sunday, 20 November 2016 at 11:46:04 UTC, Marc Schütz wrote: Try placing it outside the function. Method call syntax doesn't work with nested functions, see here: https://dlang.org/spec/function.html#pseudo-member "The reason why local symbols are not considered by UFCS, is to avoid unexp

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Ali Çehreli via Digitalmars-d-learn
On 11/22/2016 08:05 AM, Satoshi wrote: > Sorry, but D seems to be worse and worse day by day. I don't have extensive experience with other languages. In fact, the only other languages that I can claim proficiency are C and C++. (I also know Python just enough to find it incredible how it's use

Re: Char representation

2016-11-22 Thread RazvanN via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 14:23:28 UTC, Jonathan M Davis wrote: On Tuesday, November 22, 2016 13:29:47 RazvanN via Digitalmars-d-learn wrote: [...] You misunderstand. char[] is a dynamic array of char, wchar[] is a dynamic array of wchar[], and dchar[] is a dynamic array of dchar. Ther

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Satoshi via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 19:16:56 UTC, Ali Çehreli wrote: On 11/22/2016 08:05 AM, Satoshi wrote: I don't have extensive experience with other languages. In fact, the only other languages that I can claim proficiency are C and C++. (I also know Python just enough to find it incredible

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Satoshi via Digitalmars-d-learn
or I have simple class class View { this(Rectangle frame) {...} this(float, float, float, float) { ... } this(Point, Size) { ... } } then struct Point, Size and Rectangle (Point, Size) now I need to write 2 overloads for View class taking 4 floats or (Point, Size) and this must do in every des

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Guillaume Piolat via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 16:57:28 UTC, kink wrote: I hate this 'idiom' too (just a clumsy workaround for something that should work out of the box), but the non-bindability of rvalues to ref params and the associated dispute is veeery old, nothing new, so I don't agree that the languag

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 16:05:35 UTC, Satoshi wrote: Sorry, but D seems to be worse and worse day by day. This should be resolved by language and not doing it by template function. Same thing should be applied for maybe monad and tuples. I'm reminded of trying to follow the rules and

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 22:03:14 UTC, Satoshi wrote: or I have simple class class View { this(Rectangle frame) {...} this(float, float, float, float) { ... } this(Point, Size) { ... } } then struct Point, Size and Rectangle (Point, Size) now I need to write 2 overloads for View class t