Re: unittest blocks not being run inside of class and struct templates

2017-07-24 Thread NoBigDeal256 via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 02:18:41 UTC, Adam D. Ruppe wrote: On Tuesday, 25 July 2017 at 02:11:20 UTC, NoBigDeal256 wrote: it passes when it should fail because the unittest block is never executed. Why is this? Did you actually instantiate the class somewhere? A template has no concrete

Re: unittest blocks not being run inside of class and struct templates

2017-07-24 Thread NoBigDeal256 via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 02:18:41 UTC, Adam D. Ruppe wrote: On Tuesday, 25 July 2017 at 02:11:20 UTC, NoBigDeal256 wrote: it passes when it should fail because the unittest block is never executed. Why is this? Did you actually instantiate the class somewhere? A template has no concrete

Re: unittest blocks not being run inside of class and struct templates

2017-07-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 02:11:20 UTC, NoBigDeal256 wrote: it passes when it should fail because the unittest block is never executed. Why is this? Did you actually instantiate the class somewhere? A template has no concrete code unless created with an argument somewhere...

unittest blocks not being run inside of class and struct templates

2017-07-24 Thread NoBigDeal256 via Digitalmars-d-learn
For example this code: class Test { unittest { assert(false); } } fails when ran with dmd test.d -unittest like you'd expect. But if I make it a class template: class Test(T) { unittest { assert(false); } } it passes when it should fail because the unittest

Re: Csharp para Digital Mars D[AJUDA]

2017-07-24 Thread Nick B via Digitalmars-d-learn
On Monday, 24 July 2017 at 22:15:05 UTC, dark777 wrote: Eu tenho um projeto em windows form C# feito no virual studio um amigo meu e eu criamos para a semana academica ele faz cadastros e marca a presença das visitas na semana por um id de quem ja pagou pelas palestras queria portar ele para

Re: Why D have two function contains and canFind?

2017-07-24 Thread Timon Gehr via Digitalmars-d-learn
On 24.07.2017 20:19, Suliman wrote: Why D have two function `contains` and `canFind` `contains` guarantees logarithmic running time, while `canFind` can be linear.

Csharp para Digital Mars D[AJUDA]

2017-07-24 Thread dark777 via Digitalmars-d-learn
Eu tenho um projeto em windows form C# feito no virual studio um amigo meu e eu criamos para a semana academica ele faz cadastros e marca a presença das visitas na semana por um id de quem ja pagou pelas palestras queria portar ele para D. Que biblioteca para forms vcs me recomendam para

traits compiles does not work for symbols from other modules

2017-07-24 Thread Andre Pany via Digitalmars-d-learn
Hi, I want to validate whether a class contains a specific attribute. I have the attribute name as compile time string. This string could either be a direct attribute of the class or a hierarchy (TextSettings.Font.Size). As example T is the class Label and p.name contains the text

Re: criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread dark777 via Digitalmars-d-learn
On Monday, 24 July 2017 at 20:33:42 UTC, dark777 wrote: On Monday, 24 July 2017 at 20:06:37 UTC, ag0aep6g wrote: On 07/24/2017 09:45 PM, dark777 wrote: principal.d(18): Error: octal literals 01023040 are no longer supported, use std.conv.octal!1023040 instead Failed: ["dmd", "-v", "-o-",

Re: criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread dark777 via Digitalmars-d-learn
On Monday, 24 July 2017 at 20:06:37 UTC, ag0aep6g wrote: On 07/24/2017 09:45 PM, dark777 wrote: principal.d(18): Error: octal literals 01023040 are no longer supported, use std.conv.octal!1023040 instead Failed: ["dmd", "-v", "-o-", "principal.d", "-I."] [...] https://pastebin.com/CYinHWyQ

Re: Why D have two function contains and canFind?

2017-07-24 Thread Seb via Digitalmars-d-learn
On Monday, 24 July 2017 at 19:53:34 UTC, Cym13 wrote: On Monday, 24 July 2017 at 18:31:09 UTC, Ali Çehreli wrote: On 07/24/2017 11:19 AM, Suliman wrote: > [...] only > [...] std.algorithm.canFind and std.range.SortedRange.contains: [...] I'm gessing this predates design by introspection as

Re: criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread SrMordred via Digitalmars-d-learn
On Monday, 24 July 2017 at 20:14:23 UTC, SrMordred wrote: On Monday, 24 July 2017 at 19:45:03 UTC, dark777 wrote: pessoal eu tenho umas classes java e estava portando para D e para usar as importaçoes criei os modules nescessarios todos estao dentro da mesma pasta porem ao fazer: $rdmd

Re: criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread SrMordred via Digitalmars-d-learn
On Monday, 24 July 2017 at 19:45:03 UTC, dark777 wrote: pessoal eu tenho umas classes java e estava portando para D e para usar as importaçoes criei os modules nescessarios todos estao dentro da mesma pasta porem ao fazer: $rdmd principal ele retorna o seguinte erro: principal.d(18): Error:

Re: criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread ag0aep6g via Digitalmars-d-learn
On 07/24/2017 09:45 PM, dark777 wrote: principal.d(18): Error: octal literals 01023040 are no longer supported, use std.conv.octal!1023040 instead Failed: ["dmd", "-v", "-o-", "principal.d", "-I."] [...] https://pastebin.com/CYinHWyQ From there: e = new Endereco();

Re: Why D have two function contains and canFind?

2017-07-24 Thread Cym13 via Digitalmars-d-learn
On Monday, 24 July 2017 at 18:31:09 UTC, Ali Çehreli wrote: On 07/24/2017 11:19 AM, Suliman wrote: > [...] only > [...] std.algorithm.canFind and std.range.SortedRange.contains: [...] I'm gessing this predates design by introspection as it would be cleaner to let the compiler do the switch

Re: criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread Cym13 via Digitalmars-d-learn
On Monday, 24 July 2017 at 19:45:03 UTC, dark777 wrote: pessoal eu tenho umas classes java e estava portando para D e para usar as importaçoes criei os modules nescessarios todos estao dentro da mesma pasta porem ao fazer: $rdmd principal ele retorna o seguinte erro: principal.d(18): Error:

criando modulos em D para classe pessoa[AJUDA]

2017-07-24 Thread dark777 via Digitalmars-d-learn
pessoal eu tenho umas classes java e estava portando para D e para usar as importaçoes criei os modules nescessarios todos estao dentro da mesma pasta porem ao fazer: $rdmd principal ele retorna o seguinte erro: principal.d(18): Error: octal literals 01023040 are no longer supported, use

Re: No polymorphism?

2017-07-24 Thread Dgame via Digitalmars-d-learn
On Monday, 24 July 2017 at 18:15:20 UTC, Steven Schveighoffer wrote: On 7/24/17 1:29 PM, Dgame wrote: Why isn't the compiler able to deduce S[] => I[]? Or is it just me? I've tried dmd 2.075 I know you got the explanation already, but just in case you actually need to call something like

Re: Why D have two function contains and canFind?

2017-07-24 Thread Ali Çehreli via Digitalmars-d-learn
On 07/24/2017 11:19 AM, Suliman wrote: > Why D have two function `contains` and `canFind` if C# have only > contains and it's enough? std.algorithm.canFind and std.range.SortedRange.contains: https://dlang.org/phobos/std_algorithm_searching.html#.canFind

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread Clinton via Digitalmars-d-learn
On Monday, 24 July 2017 at 18:01:19 UTC, ketmar wrote: Clinton wrote: On Monday, 24 July 2017 at 14:51:04 UTC, rikki cattermole wrote: Stuff the GC. You don't need it to care about collecting (or destroying for that matter). Tell it to free[0] the array directly. ```D T[] array;

Re: howto touch a file - setTimes

2017-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/24/17 1:11 PM, Martin Tschierschke wrote: When I tried to set the atime and mtime of a file (f) via: import std.datetime; auto time = Clock.currTime(); setTimes(f,time,time); I get "Operation not permitted." This is caused on linux by the rule, that if you are not the owner of the file

Why D have two function contains and canFind?

2017-07-24 Thread Suliman via Digitalmars-d-learn
Why D have two function `contains` and `canFind` if C# have only contains and it's enough?

Re: No polymorphism?

2017-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/24/17 1:29 PM, Dgame wrote: Why isn't the compiler able to deduce S[] => I[]? Or is it just me? I've tried dmd 2.075 I know you got the explanation already, but just in case you actually need to call something like test1 but only have an S[]: test1(ss.map!((I i) => i).array) -Steve

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread ketmar via Digitalmars-d-learn
Clinton wrote: On Monday, 24 July 2017 at 14:51:04 UTC, rikki cattermole wrote: Stuff the GC. You don't need it to care about collecting (or destroying for that matter). Tell it to free[0] the array directly. ```D T[] array; GC.free(array.ptr); ``` Normally I would suggest to create your

Re: No polymorphism?

2017-07-24 Thread Dgame via Digitalmars-d-learn
On Monday, 24 July 2017 at 17:33:48 UTC, Adam D. Ruppe wrote: On Monday, 24 July 2017 at 17:29:55 UTC, Dgame wrote: S[] ss = [new S()]; test1(ss); // Fails Why isn't the compiler able to deduce S[] => I[]? Or is it just me? This is exactly because of polymorphism. Consider

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread Clinton via Digitalmars-d-learn
On Monday, 24 July 2017 at 14:51:04 UTC, rikki cattermole wrote: Stuff the GC. You don't need it to care about collecting (or destroying for that matter). Tell it to free[0] the array directly. ```D T[] array; GC.free(array.ptr); ``` Normally I would suggest to create your own buffer, but

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/24/17 11:45 AM, Houdini wrote: On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer wrote: Because types with inheritance generally don't work right if you pass by value (i.e. the slicing problem). structs don't support inheritance or virtual functions, so they can be safely

VibeD - RestInterfaceClient - non-constant expression

2017-07-24 Thread holo via Digitalmars-d-learn
Hello I'm trying to move forward with my code from here: https://forum.dlang.org/post/yftgpzlotuqzechcn...@forum.dlang.org I create my client app and trying to use RestInterfaceClient to connect to my api. Here is my present code for client: module sites.frontpage; import vibe.d; import

Re: No polymorphism?

2017-07-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 24 July 2017 at 17:29:55 UTC, Dgame wrote: S[] ss = [new S()]; test1(ss); // Fails Why isn't the compiler able to deduce S[] => I[]? Or is it just me? This is exactly because of polymorphism. Consider the following: ``` S[] ss = [new S()]; I[] i = ss; // pass it

No polymorphism?

2017-07-24 Thread Dgame via Digitalmars-d-learn
I may be just tired, but could somebody explain this behaviour to me? It seems odd to me: interface I { } class S : I { } void test1(I[]) { } void test2(I) { } void main() { test1([new S()]); // Works test2(new S()); // Works I i = new S();

howto touch a file - setTimes

2017-07-24 Thread Martin Tschierschke via Digitalmars-d-learn
When I tried to set the atime and mtime of a file (f) via: import std.datetime; auto time = Clock.currTime(); setTimes(f,time,time); I get "Operation not permitted." This is caused on linux by the rule, that if you are not the owner of the file you may only set the mtime of a file to current

Re: Best syntax for a diagonal and vertical slice

2017-07-24 Thread Timon Gehr via Digitalmars-d-learn
On 22.07.2017 22:55, kerdemdemir wrote: We have awesome way for creating slices like: a = new int[5]; int[] b = a[0..2]; But what about if I have 2D array and I don't want to go vertical. Something like : int[3][3] matrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread Clinton via Digitalmars-d-learn
On Monday, 24 July 2017 at 14:51:04 UTC, rikki cattermole wrote: Stuff the GC. You don't need it to care about collecting (or destroying for that matter). Tell it to free[0] the array directly. ```D T[] array; GC.free(array.ptr); ``` Normally I would suggest to create your own buffer, but

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread via Digitalmars-d-learn
On Mon, Jul 24, 2017 at 03:45:29PM +, Houdini via Digitalmars-d-learn wrote: > But in C++, we pass them by reference also to avoid copies (const &). Exactly... in C++ you basically always pass by reference, so D made that the default.

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Houdini via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:41:33 UTC, Steven Schveighoffer wrote: Because types with inheritance generally don't work right if you pass by value (i.e. the slicing problem). structs don't support inheritance or virtual functions, so they can be safely passed by value. But in C++, we

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Houdini via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:37:51 UTC, Andrea Fontana wrote: Maybe this will help you: https://stackoverflow.com/questions/10965577/usage-preference-between-a-struct-and-a-class-in-d-language Thanks for this informative link.

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/24/17 11:21 AM, Houdini wrote: Hello, I am a C++ coder, and I am learning D (just reading a book, for now). D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in Java ? And why is it

Re: Why structs and classes instanciations are made differently ?

2017-07-24 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 24 July 2017 at 15:21:54 UTC, Houdini wrote: Hello, I am a C++ coder, and I am learning D (just reading a book, for now). D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in

Why structs and classes instanciations are made differently ?

2017-07-24 Thread Houdini via Digitalmars-d-learn
Hello, I am a C++ coder, and I am learning D (just reading a book, for now). D is very similar to C++ (and also grabs godd ideas from Python), but I have a naive question : why does Walter Bright chose to instanciate classes like in Java ? And why is it different for structs ?

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread ketmar via Digitalmars-d-learn
rikki cattermole wrote: Tell it to free[0] the array directly. ```D T[] array; GC.free(array.ptr); or just `delete arr;`. it is marked as "deprecated" in changelog, but who cares? it works.

Re: Cleaning/Releasing large arrays from memory

2017-07-24 Thread rikki cattermole via Digitalmars-d-learn
Stuff the GC. You don't need it to care about collecting (or destroying for that matter). Tell it to free[0] the array directly. ```D T[] array; GC.free(array.ptr); ``` Normally I would suggest to create your own buffer, but because of the DB library probably doesn't support that, no point

Cleaning/Releasing large arrays from memory

2017-07-24 Thread Clinton via Digitalmars-d-learn
Hi guys, I have a question on how to free large arrays in D after they're no longer needed. Let's say I have this: SomeKey[] getKeys() { SomeKey[] n; foreach(batching stuff...) { SomeKey newstuff = db.select!(SomeKey[])(...); // gets around 6M of these from db

Re: Check whether string value represents a type

2017-07-24 Thread Timoses via Digitalmars-d-learn
On Monday, 24 July 2017 at 07:08:56 UTC, Basile B. wrote: On Friday, 21 July 2017 at 14:21:37 UTC, Timoses wrote: I'd love to check whether a string value is the name of a type at run-time. [...] The goal is to identify whether a string represents a custom type within a package. I'm also

Re: Best syntax for a diagonal and vertical slice

2017-07-24 Thread pineapple via Digitalmars-d-learn
On Saturday, 22 July 2017 at 20:55:06 UTC, kerdemdemir wrote: And what if I want to go diagonal like 1,5,9 or 3,5,7 in the example above. Is there a good solution in std without using for loops? I suggest using an actual matrix type for tasks like this. I don't know about diagonal slicing,

Re: map on char[] converts to dchar?

2017-07-24 Thread pineapple via Digitalmars-d-learn
It is worth noting too that mach's map function will not behave this way; UTF encoding and decoding is instructed explicitly and is not done implicitly like in phobos. https://github.com/pineapplemachine/mach.d import mach.range : map, asarray; import mach.text.ascii : toupper;

Re: map on char[] converts to dchar?

2017-07-24 Thread Seb via Digitalmars-d-learn
On Monday, 24 July 2017 at 09:05:43 UTC, Johan wrote: Hi all, What am I doing wrong here? ``` import std.algorithm; int foo(char c) { return 123; } auto mapFoo(char[] chars) { return chars.map!(a => a.foo); } ``` errors with: main.d(14): Error: function main.foo (char c) is not

map on char[] converts to dchar?

2017-07-24 Thread Johan via Digitalmars-d-learn
Hi all, What am I doing wrong here? ``` import std.algorithm; int foo(char c) { return 123; } auto mapFoo(char[] chars) { return chars.map!(a => a.foo); } ``` errors with: main.d(14): Error: function main.foo (char c) is not callable using argument types (dchar)

Re: Check whether string value represents a type

2017-07-24 Thread Basile B. via Digitalmars-d-learn
On Friday, 21 July 2017 at 14:21:37 UTC, Timoses wrote: I'd love to check whether a string value is the name of a type at run-time. [...] The goal is to identify whether a string represents a custom type within a package. I'm also trying to iterate over all modules within the package to get

Re: Check whether string value represents a type

2017-07-24 Thread Timoses via Digitalmars-d-learn
On Friday, 21 July 2017 at 14:44:23 UTC, Steven Schveighoffer wrote: On 7/21/17 10:21 AM, Timoses wrote: I'd love to check whether a string value is the name of a type at run-time. E.g.: string a = "int"; string b = "im no type"; assert( isStringType(a) ); assert( !isStringType(b) ); or