Re: Is it possible to check if a type is an instance of a template?

2014-05-06 Thread Andrej Mitrovic via Digitalmars-d-learn
On 5/6/14, bearophile via Digitalmars-d-learn wrote: > There is now std.traits.isInstanceOf that could do what you need. Someone resurrected a thread from 2011. Of course there's isInstanceOf when I added it myself at the end of 2012.

Re: Reading a single whitespace-separated word from stdin

2014-05-06 Thread bearophile via Digitalmars-d-learn
Mark Isaacson: I'm trying my hand at reading from standard input and having little luck. In particular, I would like to be able to do the rough equivalent of C++'s: cin >> myString; There isn't always a 1:1 mapping between C++ and D. In D if you want a single word you usually read the whol

Re: Reading a single whitespace-separated word from stdin

2014-05-06 Thread Mark Isaacson via Digitalmars-d-learn
Fair enough. I've done stuff like that in the past. I'm trying to implement a university project that was originally designed for C++ style I/O... and so where I'd have otherwise jumped at something like that from the beginning, my hands are slightly tied. Suppose I'll make due/not fully comp

Re: Reading a single whitespace-separated word from stdin

2014-05-06 Thread bearophile via Digitalmars-d-learn
Mark Isaacson: Fair enough. I've done stuff like that in the past. I'm trying to implement a university project that was originally designed for C++ style I/O... and so where I'd have otherwise jumped at something like that from the beginning, my hands are slightly tied. If you need/want to

Re: Reading a single whitespace-separated word from stdin

2014-05-06 Thread Mark Isaacson via Digitalmars-d-learn
Indeed. However, doing so looks more painful than redefining my goals. Upon further examination it seems that I had more flexibility than I originally estimated. Besides, the real reason I'm implementing this project is just to practice for when I get to write production D code in a week anyway

Re: Reading a single whitespace-separated word from stdin

2014-05-06 Thread bearophile via Digitalmars-d-learn
Mark Isaacson: Indeed. However, doing so looks more painful than redefining my goals. Upon further examination it seems that I had more flexibility than I originally estimated. Besides, the real reason I'm implementing this project is just to practice for when I get to write production D code

Re: Implicit static->dynamic arr and modifying

2014-05-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 05 May 2014 22:16:58 -0400 Nick Sabalausky via Digitalmars-d-learn wrote: > On 5/5/2014 10:11 PM, Nick Sabalausky wrote: > > Is this kinds stuff a sane thing to do, or does it just work by > > accident?: > > > > void modify(ubyte[] dynamicArr) > > { > > dynamicArr[$-1] = 5; > > } > >

The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread FrankLike via Digitalmars-d-learn
Hi,everyone, I find the The writeln() function's args can't be ["一" ,"二"]? why? Thank you. Frank.

Re: The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread JR via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 09:43:10 UTC, FrankLike wrote: Hi,everyone, I find the The writeln() function's args can't be ["一" ,"二"]? why? Thank you. Frank. The problem is that you have a wide-character comma (,) there. This works: void main() { writeln(["一", "二"]); }

Re: Global variables read at compile time?

2014-05-06 Thread Suliman via Digitalmars-d-learn
I have got same error. I need to pass in instance of class constant, but got error "Error: static variable cannot be read at compile" http://www.everfall.com/paste/id.php?1mc9mb9cxyie When I had create instance of class in main, and create confvarible above it all worked, but when I had move

Re: Need help with movement from C to D

2014-05-06 Thread Andrey via Digitalmars-d-learn
On Monday, 5 May 2014 at 17:55:37 UTC, Meta wrote: enum offsetof(T, string field) = mixin(type.stringof ~ "." ~ field ~ ".offsetof"); To ensure that a syntactically valid symbol is passed as the type. Interestingly, but this code doesn't compile: enum offsetof(typenfield) = mixin(type.st

Simple matching on a range

2014-05-06 Thread bearophile via Digitalmars-d-learn
Is it a good idea to add a function like this to Phobos? This is just a first draft of the idea. void main() { import std.stdio, std.algorithm, std.range, range_matcher; auto primes = iota(2, uint.max) .filter!(x => iota(2, x) .all!(t =

newbie question about dub

2014-05-06 Thread Oleg via Digitalmars-d-learn
Hello. I'm developing library and want to add an examples to the same project. If I understand corecly, DUB allows to build a dependencies from another folder and use them to build a program. I've tried two ways - subConfigurations and subPackages. For example, there is subConfigurations confi

Re: Need help with movement from C to D

2014-05-06 Thread via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 11:09:37 UTC, Andrey wrote: On Monday, 5 May 2014 at 17:55:37 UTC, Meta wrote: enum offsetof(T, string field) = mixin(type.stringof ~ "." ~ field ~ ".offsetof"); To ensure that a syntactically valid symbol is passed as the type. Interestingly, but this code does

Re: Create many objects using threads

2014-05-06 Thread hardcoremore via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 03:26:52 UTC, Ali Çehreli wrote: On 05/05/2014 04:32 PM, Caslav Sabani wrote: > So basically using threads in D for creating multiple instances of class is > actually slower. Not at all! That statement can be true only in certain programs. :) Ali But what does ex

Re: The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread FrankLike via Digitalmars-d-learn
The problem is that you have a wide-character comma (,) there. This works: void main() { writeln(["一", "二"]); } No,I mean the execute result is error.That doesn't get the ["一", "二"],but get the ["涓C","浜?]. Why? Thank you. Frank.

Re: Global variables read at compile time?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 03:16 AM, Suliman wrote: > When I had create instance of class in main, and create confvarible > above it all worked, but when I had moved it's in module I got error. There is module 'static this()' for such runtime initialization: Config config; static this() { config = new

Re: Need help with movement from C to D

2014-05-06 Thread Artur Skawina via Digitalmars-d-learn
I'm not sure why you'd want to wrap the .offsetof expression in a template, but it can easily be done like this: enum offsetOf(alias A, string S) = mixin("A."~S~".offsetof"); Keep in mind that D's offsetof is flawed - if the object does not contain the requested member, but implicitly convert

Re: Need help with movement from C to D

2014-05-06 Thread bearophile via Digitalmars-d-learn
Artur Skawina: Keep in mind that D's offsetof is flawed - if the object does not contain the requested member, but implicitly converts to another one that does have such field then the expression compiles, but yields a bogus value. Eg struct S { int a, b, c; S2 s2; alias s2 this; } stru

Re: Global variables read at compile time?

2014-05-06 Thread Suliman via Digitalmars-d-learn
Thanks! But is there any other solution? I am thinking that I am trying to specify config name by wrong way...

Re: The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 13:35:57 UTC, FrankLike wrote: The problem is that you have a wide-character comma (,) there. This works: void main() { writeln(["一", "二"]); } No,I mean the execute result is error.That doesn't get the ["一", "二"],but get the ["涓C","浜?]. Why? Thank yo

Re: Need help with movement from C to D

2014-05-06 Thread via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 14:25:01 UTC, Artur Skawina via Digitalmars-d-learn wrote: I'm not sure why you'd want to wrap the .offsetof expression in a template, but it can easily be done like this: enum offsetOf(alias A, string S) = mixin("A."~S~".offsetof"); Great, that's even shorter. So

Re: The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread Regan Heath via Digitalmars-d-learn
On Tue, 06 May 2014 15:48:44 +0100, Marc Schütz wrote: On Tuesday, 6 May 2014 at 13:35:57 UTC, FrankLike wrote: The problem is that you have a wide-character comma (,) there. This works: void main() { writeln(["一", "二"]); } No,I mean the execute result is error.That doesn't ge

Re: Need help with movement from C to D

2014-05-06 Thread Artur Skawina via Digitalmars-d-learn
On 05/06/14 16:45, via Digitalmars-d-learn wrote: > On Tuesday, 6 May 2014 at 14:25:01 UTC, Artur Skawina via Digitalmars-d-learn > wrote: >> I'm not sure why you'd want to wrap the .offsetof expression in >> a template, but it can easily be done like this: >> >>enum offsetOf(alias A, string S

Re: Need help with movement from C to D

2014-05-06 Thread bearophile via Digitalmars-d-learn
Artur Skawina: And, I have no idea if the, hmm, /unconventional/ D offsetof semantics are in the bugzilla. It's not really a "bug", but a design mistake... Design mistakes are valid bugzilla entries. At worst the bad behavior could be documented. But often it's possible to fix the design to

Re: Implicit static->dynamic arr and modifying

2014-05-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 06, 2014 at 01:06:14AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Mon, 05 May 2014 22:16:58 -0400 > Nick Sabalausky via Digitalmars-d-learn > wrote: > > > On 5/5/2014 10:11 PM, Nick Sabalausky wrote: > > > Is this kinds stuff a sane thing to do, or does it just work

Re: Implicit static->dynamic arr and modifying

2014-05-06 Thread bearophile via Digitalmars-d-learn
H. S. Teoh: Exercise for the reader: spot the bug. https://issues.dlang.org/show_bug.cgi?id=5212 https://issues.dlang.org/show_bug.cgi?id=11657 Bye, bearophile

Re: Create many objects using threads

2014-05-06 Thread Kapps via Digitalmars-d-learn
On Monday, 5 May 2014 at 22:11:39 UTC, Ali Çehreli wrote: On 05/05/2014 02:38 PM, Kapps wrote: > I think that the GC actually blocks when > creating objects, and thus multiple threads creating instances would not > provide a significant speedup, possibly even a slowdown. Wow! That is the case.

Re: Global variables read at compile time?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 07:40 AM, Suliman wrote: Thanks! But is there any other solution? I am thinking that I am trying to specify config name by wrong way... Sorry, I don't understand what exactly you are trying to do. :( Is config file a compile-time concept? Do you want to read it at compile time?

Re: Create many objects using threads

2014-05-06 Thread Kapps via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 15:56:11 UTC, Kapps wrote: On Monday, 5 May 2014 at 22:11:39 UTC, Ali Çehreli wrote: On 05/05/2014 02:38 PM, Kapps wrote: > I think that the GC actually blocks when > creating objects, and thus multiple threads creating instances would not > provide a significant speed

Re: Global variables read at compile time?

2014-05-06 Thread Suliman via Digitalmars-d-learn
I am tying to hardcode name of config file name. Then I would read and parse it.

Re: Reading a single whitespace-separated word from stdin

2014-05-06 Thread Mark Isaacson via Digitalmars-d-learn
An exceptionally generous offer! May take you up on that. Thank you :).

Re: Create many objects using threads

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 05:46 AM, hardcoremore wrote: > But what does exactly means that Garbage Collector blocks? What > does it blocks and in which way? I know this much: The current GC that comes in D runtime is a single-threaded GC (aka "a stop-the-world GC"), meaning that all threads are stopped wh

Re: Read Complete File to Array of Lines

2014-05-06 Thread Suliman via Digitalmars-d-learn
I am trying to write simple parser, that split text to key value name = david lastname = wood here is my code: foreach (line; readText(confname).splitLines()) { writeln(line); foreach (str; split(line, "="))

Register allocation algorithm

2014-05-06 Thread asmman via Digitalmars-d-learn
I'm working on small compiler to understand these stuff and maybe get involved with the D compiler. I wrote a front-end to a C-like language and now I'm working on the code generator. To be more specific, in the register allocation phase. I was using a old and one where I put everything on stac

Re: Implicit static->dynamic arr and modifying

2014-05-06 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 02:17:06 UTC, Nick Sabalausky wrote: So all is well, and deliberately so. Pardon the noise. IMO it's not. I once had a particularly nasty bug because of this: struct S { @safe: string str; this(string data) { im

Atom text editor

2014-05-06 Thread Joshua Niehus via Digitalmars-d-learn
FYI: If anyone is using GitHub's text editor "Atom" and would like basic D syntax highlighting: apm init --package ~/.atom/packages/language-d --convert https://github.com/textmate/d.tmbundle https://atom.io/docs/v0.94.0/converting-a-text-mate-bundle

Re: The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread FrankLike via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 15:03:11 UTC, Regan Heath wrote: On Tue, 06 May 2014 15:48:44 +0100, Marc Schütz wrote: On Tuesday, 6 May 2014 at 13:35:57 UTC, FrankLike wrote: The problem is that you have a wide-character comma (,) there. This works: void main() { writeln(["一", "二"]);

Re: The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 04:56 PM, FrankLike wrote: > On Tuesday, 6 May 2014 at 15:03:11 UTC, Regan Heath wrote: >> IIRC you need to type "chcp 65001" and set the command prompt to the >> Lucida font... >> >> R > > No,it's error.My OS is windows 7,chcp 936. SimpleChinese. > I use the 'go language' to test

Re: The writeln() function's args can't be ["一" ,"二"]?

2014-05-06 Thread FrankLike via Digitalmars-d-learn
That is understandable: Since the console is set to 936, it interprets D program's UTF-8 output incorrectly. Please do what Regan Heath says and test again: 1) Set the code page to 65001 2) Use a font that includes your Unicode characters Ali Thank you. I modify it by the 'Regedit'(my O