inout, delegates, and visitor functions.

2015-10-24 Thread Sebastien Alaiwan via Digitalmars-d-learn
Hi all, I'm trying to get the following code to work. (This code is a simplified version of some algebraic type). Is it possible to only declare one version of the 'apply' function? Or should I declare the const version and the non-const version? I tried using "inout", but I got the following

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-24 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 21:52:05 UTC, anonymous wrote: On 22.10.2015 21:13, Nordlöw wrote: Hmm, why isn't this already in Phobos? Working first version at https://github.com/nordlow/justd/blob/master/conv_ex.d#L207 Next I'll make it a range.

Merging two named Tuples

2015-10-24 Thread Edwin van Leeuwen via Digitalmars-d-learn
I am trying to write a function to merge two named structs, but am completely stuck on how to do that and was wondering if anyone good provide any help. I know I can access the different names with tup.fieldNames, but basically can't work out how to use that to build the new return type. Below

Re: inout, delegates, and visitor functions.

2015-10-24 Thread ponce via Digitalmars-d-learn
On Saturday, 24 October 2015 at 08:51:58 UTC, Sebastien Alaiwan wrote: Hi all, I'm trying to get the following code to work. (This code is a simplified version of some algebraic type). Is it possible to only declare one version of the 'apply' function? Or should I declare the const version and

Re: inout, delegates, and visitor functions.

2015-10-24 Thread Sebastien Alaiwan via Digitalmars-d-learn
Hi ponce, Thanks for your suggestion. I think I may have found the beginning of a solution: class E { import std.traits; void apply(this F, U)(void delegate(U e) f) if(is(Unqual!U == E)) { f(this); } int val; } int main() { void setToZero(E e) { e.val = 0; } void

Re: inout, delegates, and visitor functions.

2015-10-24 Thread ponce via Digitalmars-d-learn
On Saturday, 24 October 2015 at 11:28:17 UTC, Sebastien Alaiwan wrote: Hi ponce, Thanks for your suggestion. I think I may have found the beginning of a solution: class E { import std.traits; void apply(this F, U)(void delegate(U e) f) if(is(Unqual!U == E)) { f(this); } int v

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-24 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 24 October 2015 at 08:54:40 UTC, Nordlöw wrote: Working first version at https://github.com/nordlow/justd/blob/master/conv_ex.d#L207 Next I'll make it a range. Made it a range: https://github.com/nordlow/justd/blob/master/conv_ex.d#L207

`clear`ing a dynamic array

2015-10-24 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted consequences that `[]` actually seems to allocate a new dynamic array and

Re: `clear`ing a dynamic array

2015-10-24 Thread anonymous via Digitalmars-d-learn
On 24.10.2015 15:18, Shriramana Sharma wrote: int a[] = [1,2,3,4,5]; Aside: `int[] a;` is the preferred style for array declarations. How to make it so that after clearing `a`, `b` will also point to the same empty array? IOW the desired output is: [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [] [] .

Re: `clear`ing a dynamic array

2015-10-24 Thread Cauterite via Digitalmars-d-learn
I'm afraid what you're asking for is impossible. Because 'a' and 'b' are both slices, they each have their own 'length' field. When you do 'a = []', you're effectively doing 'a.length = 0'. There's no way to change 'b.length' through 'a'. To get that effect, you'd have to do something like this

Re: `clear`ing a dynamic array

2015-10-24 Thread John Colvin via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted co

Re: `clear`ing a dynamic array

2015-10-24 Thread rsw0x via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted co

Array of templated classes or structs

2015-10-24 Thread Dandyvica via Digitalmars-d-learn
Hi guys, Apart from deriving from the same class and declaring an array of that root class, is there a way to create an array of templates? This seems not possible since template are compile-time generated, but just to be sure. For example, it seems logical to get an array of complex numbers

Re: How to install DMD 64bit on Windows?

2015-10-24 Thread ric maicle via Digitalmars-d-learn
On Thursday, 22 October, 2015 02:50 AM, Adam D. Ruppe wrote: Use the .exe installer and it will offer to download and install visual studio for you as part for its process. Sorry to ask this but could anyone please explain why Visual Studio is required by DMD 64-bit? (I have been away far too l

Re: How to install DMD 64bit on Windows?

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 16:06:24 UTC, ric maicle wrote: On Thursday, 22 October, 2015 02:50 AM, Adam D. Ruppe wrote: Use the .exe installer and it will offer to download and install visual studio for you as part for its process. Sorry to ask this but could anyone please explain why Vi

Re: Array of templated classes or structs

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 15:57:09 UTC, Dandyvica wrote: Hi guys, Apart from deriving from the same class and declaring an array of that root class, is there a way to create an array of templates? This seems not possible since template are compile-time generated, but just to be sure. F

Re: Array of templated classes or structs

2015-10-24 Thread Dandyvica via Digitalmars-d-learn
On Saturday, 24 October 2015 at 16:58:58 UTC, qsdfghjk wrote: On Saturday, 24 October 2015 at 15:57:09 UTC, Dandyvica wrote: Hi guys, Apart from deriving from the same class and declaring an array of that root class, is there a way to create an array of templates? This seems not possible sin

Re: Array of templated classes or structs

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 17:06:13 UTC, Dandyvica wrote: On Saturday, 24 October 2015 at 16:58:58 UTC, qsdfghjk wrote: On Saturday, 24 October 2015 at 15:57:09 UTC, Dandyvica wrote: Hi guys, Apart from deriving from the same class and declaring an array of that root class, is there a w

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 15:57:09 UTC, Dandyvica wrote: Hi guys, Apart from deriving from the same class and declaring an array of that root class, is there a way to create an array of templates? This seems not possible since template are compile-time generated, but just to be sure. F

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 18:29:08 UTC, TheFlyingFiddle wrote: Variant[] array; array ~= S!int(...); array ~= S!double(...); array ~= S!long(...); array ~= "I am a string!"; And this is probably not what you want. You can do this if you want to ensure that items stored in the variant ar

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 19:00:57 UTC, TheFlyingFiddle wrote: One thing about variant is that if the struct you are trying to insert is larger then (void delegate()).sizeof it will allocate the wrapped type on the gc heap. This is not a concern if you want to have class templates as the

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 18:40:02 UTC, TheFlyingFiddle wrote: To complete TemplateStruct simply forward the remaing members of the variant. Or use something like proxy!T in std.typecons. Or use an alias this v. (I don't really recommend alias this it has all kinds of problems) One thin

Compilation time profiling

2015-10-24 Thread tired_eyes via Digitalmars-d-learn
Hi, are there any tools for compilation time profiling? I'm trying to find what part of the code increases compilation time and don't want to stumble around.

Re: Compilation time profiling

2015-10-24 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 24 October 2015 at 21:56:05 UTC, tired_eyes wrote: Hi, are there any tools for compilation time profiling? I'm trying to find what part of the code increases compilation time and don't want to stumble around. There's this: https://github.com/CyberShadow/DBuildStat Example output

No shortcircuit for static if or template constraints?

2015-10-24 Thread stewart via Digitalmars-d-learn
Hi All, Given this code: --- import std.traits; import std.range; import std.stdio; enum isSupportedRange(T) = (isInputRange!T && isIntegral!(ForeachType!T)); void func(T)(T vals) { static if(isSupportedRange!T) { // Do something with a range } else { // Do something

Re: No shortcircuit for static if or template constraints?

2015-10-24 Thread stewart via Digitalmars-d-learn
On Saturday, 24 October 2015 at 23:26:09 UTC, stewart wrote: Hi All, Given this code: --- import std.traits; import std.range; import std.stdio; enum isSupportedRange(T) = (isInputRange!T && isIntegral!(ForeachType!T)); void func(T)(T vals) { static if(isSupportedRange!T) { // D

Re: No shortcircuit for static if or template constraints?

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 23:34:19 UTC, stewart wrote: On Saturday, 24 October 2015 at 23:26:09 UTC, stewart wrote: [...] Oh and the workaround I'm using is this: --- void func(T)(T vals) { static if(isInputRange!T) { static if(isIntegral!(ForeachType!T)) { // D

Re: No shortcircuit for static if or template constraints?

2015-10-24 Thread stewart via Digitalmars-d-learn
On Saturday, 24 October 2015 at 23:59:02 UTC, qsdfghjk wrote: On Saturday, 24 October 2015 at 23:34:19 UTC, stewart wrote: On Saturday, 24 October 2015 at 23:26:09 UTC, stewart wrote: [...] Oh and the workaround I'm using is this: --- void func(T)(T vals) { static if(isInputRange!T) {

Re: No shortcircuit for static if or template constraints?

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 23:59:02 UTC, qsdfghjk wrote: On Saturday, 24 October 2015 at 23:34:19 UTC, stewart wrote: On Saturday, 24 October 2015 at 23:26:09 UTC, stewart wrote: [...] Oh and the workaround I'm using is this: --- void func(T)(T vals) { static if(isInputRange!T) {

Re: `clear`ing a dynamic array

2015-10-24 Thread Shriramana Sharma via Digitalmars-d-learn
rsw0x wrote: > use std.container.array Thanks all for all the recommendations. When would one use std.array.appender with a built-in array vs std.container.array.Array? What are the pros and cons on either side? -- Shriramana Sharma, Penguin #395953

Does D's GC release memory back to the OS?

2015-10-24 Thread Richard White via Digitalmars-d-learn
Just wondering if D's GC release memory back to the OS? The documentation for the GC.minimize (http://dlang.org/phobos/core_memory.html#.GC.minimize) seems to imply that it does, but watching my OS's memory usage for various D apps doesn't support this.

Re: `clear`ing a dynamic array

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted co