Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-08 Thread Picaud Vincent via Digitalmars-d-learn
Hi Basile, Thank you for your code, it allowed me to grasp a little bit more about how to do things in D. Vincent

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Basile B. via Digitalmars-d-learn
On Monday, 7 November 2016 at 23:03:32 UTC, Picaud Vincent wrote: I need: 1/ a way to detect compile-time constant vs "dynamic" values /** * Indicates if something is a value known at compile time. * * Params: * V = The value to test. * T = Optional, the expected value type. *

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 23:07:27 UTC, Picaud Vincent wrote: typo... auto capacity = max(0,(size_-1)*stride_+1); To be more correct I have something like: alias IntergralConstant!(int,0) Zero_c; alias IntergralConstant!(int,1) One_c; auto capacity = max(Zero_c,(size_-One_c)*stride_+One_c

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
typo... auto capacity = max(0,(size_-1)*stride_+1);

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 22:18:56 UTC, Jerry wrote: On Monday, 7 November 2016 at 21:37:50 UTC, Picaud Vincent wrote: static if ( isIntegralConstant!(typeof(required_capacity()) ) { } else { } } Premature post send by error sorry Well something like: static if ( isIntegralCons

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn
On Monday, 7 November 2016 at 21:37:50 UTC, Picaud Vincent wrote: static if ( isIntegralConstant!(typeof(required_capacity()) ) { } else { } } Premature post send by error sorry Well something like: static if ( isIntegralConstant!(typeof(required_capacity()) ) ElementType[requir

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 21:23:37 UTC, Picaud Vincent wrote: On Monday, 7 November 2016 at 18:59:24 UTC, Jerry wrote: On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralCo

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 18:59:24 UTC, Jerry wrote: On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralConstant"; } A bit more elegant way of doing that would be: enum

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn
On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralConstant"; } A bit more elegant way of doing that would be: enum isIntegralConstant(T) = is(T : IntegralConstant!U, U...);

Re: New to D

2016-10-27 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 27 October 2016 at 13:43:26 UTC, Steven Schveighoffer wrote: It depends on the size of the file and the expectation of duplicate words. I'm assuming the number of words is limited, so you are going to allocate far less data by duping on demand. In addition, you may incur penalties

Re: New to D

2016-10-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/27/16 2:40 AM, Era Scarecrow wrote: On Tuesday, 25 October 2016 at 14:40:17 UTC, Steven Schveighoffer wrote: I will note, that in addition to the other comments, this is going to result in corruption. Simply put, the buffer that 'line' uses is reused for each line. So the string data used

Re: New to D

2016-10-26 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 25 October 2016 at 14:40:17 UTC, Steven Schveighoffer wrote: I will note, that in addition to the other comments, this is going to result in corruption. Simply put, the buffer that 'line' uses is reused for each line. So the string data used inside the associative array is going to

Re: New to D

2016-10-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/22/16 1:25 AM, Mark wrote: Hello, Im a 3rd year Comp Sci student in Edmonton Alberta, Canada. Ive learned how to use C, and dabbled in C++ in school. Im also in a Oop course using Java. I picked up the book The D Programming Language by Alexrei Alexandrescu a few years ago. Lately Im real

Re: New to D

2016-10-23 Thread Daniel Kozak via Digitalmars-d-learn
Dne 22.10.2016 v 11:04 Mike Parker via Digitalmars-d-learn napsal(a): On Saturday, 22 October 2016 at 08:05:12 UTC, Daniel Kozak wrote: uint[string] dictionary; should be uint[size_t] dictionary; because size_t is 32bit on x86 system and 64bit on x86_64 and you are trying to put array length

Re: New to D

2016-10-22 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 22 October 2016 at 08:05:12 UTC, Daniel Kozak wrote: uint[string] dictionary; should be uint[size_t] dictionary; because size_t is 32bit on x86 system and 64bit on x86_64 and you are trying to put array length to dictionary which is size_t I believe you meant: size_t[string];

Re: New to D

2016-10-22 Thread Daniel Kozak via Digitalmars-d-learn
Dne 22.10.2016 v 07:41 Mark via Digitalmars-d-learn napsal(a): Thanks for the fast reply. That did work. But now the error is on the line: dictionary[word] = newId; I changed the value to 10, still errors. ?? everything else is as before. thanks. uint[string] dictionary; should b

Re: New to D

2016-10-21 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 22 October 2016 at 05:41:34 UTC, Mark wrote: Thanks for the fast reply. That did work. But now the error is on the line: dictionary[word] = newId; I changed the value to 10, still errors. ?? everything else is as before. thanks. For simple single file experiments lik

Re: New to D

2016-10-21 Thread Mark via Digitalmars-d-learn
Thanks for the fast reply. That did work. But now the error is on the line: dictionary[word] = newId; I changed the value to 10, still errors. ?? everything else is as before. thanks.

Re: New to D

2016-10-21 Thread rikki cattermole via Digitalmars-d-learn
On 22/10/2016 6:25 PM, Mark wrote: Hello, Im a 3rd year Comp Sci student in Edmonton Alberta, Canada. Ive learned how to use C, and dabbled in C++ in school. Im also in a Oop course using Java. I picked up the book The D Programming Language by Alexrei Alexandrescu a few years ago. Lately Im re

Re: New to D - playing with Thread and false Sharing

2015-08-21 Thread Russel Winder via Digitalmars-d-learn
On Thu, 2015-08-20 at 20:01 +, tony288 via Digitalmars-d-learn wrote: > […] > Now what I would like to know, how would I make this code more > efficient? Which is basically the aim I'm trying to achieve. > > Any pointers would be really help full. Should I use > concurrency/parallelism etc.

Re: New to D - playing with Thread and false Sharing

2015-08-21 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2015-08-21 at 01:22 +, Nicholas Wilson via Digitalmars-d -learn wrote: > […] > Keep in mind java may be using green threads as opposed to kernel > threads. > The equivalent in D is a Fiber. I believe Java itself hasn't used green threads in an awful long time: Threads are mapped to k

Re: New to D - playing with Thread and false Sharing

2015-08-21 Thread tony288 via Digitalmars-d-learn
On Friday, 21 August 2015 at 12:45:52 UTC, Kagamin wrote: On Thursday, 20 August 2015 at 15:31:13 UTC, tony288 wrote: So I wrong some code. But it seems the time to process a shared struct & shared long is always the same. Regardless of adding paddings. Should it be different? Hi all thank

Re: New to D - playing with Thread and false Sharing

2015-08-21 Thread Kagamin via Digitalmars-d-learn
On Thursday, 20 August 2015 at 15:31:13 UTC, tony288 wrote: So I wrong some code. But it seems the time to process a shared struct & shared long is always the same. Regardless of adding paddings. Should it be different?

Re: New to D - playing with Thread and false Sharing

2015-08-21 Thread John Colvin via Digitalmars-d-learn
On Friday, 21 August 2015 at 02:44:50 UTC, Rikki Cattermole wrote: On 8/21/2015 3:37 AM, Dejan Lekic wrote: Keep in mind that in D everything is thread-local by default! :) For shared resources use __gshared or shared (although I do not know for sure whether shared works or not). Note: share

Re: New to D - playing with Thread and false Sharing

2015-08-20 Thread Rikki Cattermole via Digitalmars-d-learn
On 8/21/2015 3:37 AM, Dejan Lekic wrote: Keep in mind that in D everything is thread-local by default! :) For shared resources use __gshared or shared (although I do not know for sure whether shared works or not). Note: shared is __gshared but with mutex's added.

Re: New to D - playing with Thread and false Sharing

2015-08-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 20 August 2015 at 20:01:58 UTC, tony288 wrote: On Thursday, 20 August 2015 at 15:37:35 UTC, Dejan Lekic wrote: [...] Thanks, I changed the code and the previous one was already using shared. import std.stdio; import core.time; import core.thread; [...] Keep in mind java may b

Re: New to D - playing with Thread and false Sharing

2015-08-20 Thread tony288 via Digitalmars-d-learn
On Thursday, 20 August 2015 at 15:37:35 UTC, Dejan Lekic wrote: Keep in mind that in D everything is thread-local by default! :) For shared resources use __gshared or shared (although I do not know for sure whether shared works or not). Thanks, I changed the code and the previous one was alrea

Re: New to D - playing with Thread and false Sharing

2015-08-20 Thread Dejan Lekic via Digitalmars-d-learn
Keep in mind that in D everything is thread-local by default! :) For shared resources use __gshared or shared (although I do not know for sure whether shared works or not).

Re: New to D: parse a binary file

2011-02-06 Thread Mafi
Am 06.02.2011 19:38, schrieb Jesse Phillips: scottrick Wrote: T[] rawRead(T)(T[] buffer); I understand that T is generic type, but I am not sure of the meaning of the (T) after the method name. That T is defining the symbol to represent the generic type. It can have more than one and D prov

Re: New to D: parse a binary file

2011-02-06 Thread bearophile
scottrick: > Where is the function 'format' defined? You need to add at the top of the module: import std.conv: format; Or: import std.conv; > Also, what is that 'unittest' block? It compiles fine as is, but if I refer > to format outside of > unittest, it will not compile. Also, if I compil

Re: New to D: parse a binary file

2011-02-06 Thread scottrick
Thanks, your post was very helpful. Two more questions (probably related): Where is the function 'format' defined? Also, what is that 'unittest' block? It compiles fine as is, but if I refer to format outside of unittest, it will not compile. Also, if I compile and run your example, it doesn't

Re: New to D: parse a binary file

2011-02-06 Thread Jesse Phillips
scottrick Wrote: > T[] rawRead(T)(T[] buffer); > > I understand that T is generic type, but I am not sure of the > meaning of the (T) after the method name. That T is defining the symbol to represent the generic type. It can have more than one and D provides other things like aliases... Another

Re: New to D: parse a binary file

2011-02-05 Thread bearophile
spir: > Out[] map (In, Out) (In[] source, Out delegate (In) f) { > // (0) ... > string hex (uint i) { return format("0x%03X", i); } > uint[] decs = [1, 3, 9, 27, 81, 243, 729]; > auto hexes = map!(uint,string)(decs, &hex); ... > (0) The func must be declared as delegate (instea

Re: New to D: parse a binary file

2011-02-05 Thread spir
On 02/05/2011 06:26 PM, scottrick wrote: Hi, I am new to D. I am trying to write a binary file parser for a project of mine and I thought it would be fun to try and learn a new language at the same time. So I chose D! :D I have been struggling however and have not been able to find very many

Re: New to D: Building multiple files

2009-04-01 Thread Jesse Phillips
On Sun, 29 Mar 2009 17:43:51 +0200, torhu wrote: > On 29.03.2009 17:04, chris wrote: >> Alright so I'm not too familiar with building D or having to build >> multiple files from the command line (Java usually takes care of that). >> Basically I have a small game I put together as a test project.

Re: New to D: Building multiple files

2009-03-29 Thread chris
Yea I just realized it follows the directory structure and not some arbitrary system I made up. Thanks for the .config info, I was just putting one together of similar structure, this'll absolutely help. Much appreciated

Re: New to D: Building multiple files

2009-03-29 Thread Mike Parker
chris wrote: Alright so I'm not too familiar with building D or having to build multiple files from the command line (Java usually takes care of that). Basically I have a small game I put together as a test project. Here's the structure: clo/clo.d clo/Main.d clo/common/GameState.d clo is in mo

Re: New to D: Building multiple files

2009-03-29 Thread Trass3r
chris schrieb: The file clo.d is in module clo; while GameState is in module slo.common; you probably mean it is in package clo. Also thanks for the link, I was going to ask about .conf files. > You're welcome.

Re: New to D: Building multiple files

2009-03-29 Thread chris
The file clo.d is in module clo; while GameState is in module slo.common; I just import clo; and import clo.common; when using stuff in either of those files, I hope that's correct. Also thanks for the link, I was going to ask about .conf files.

Re: New to D: Building multiple files

2009-03-29 Thread Trass3r
How do you import the modules? You must specify the correct name, i.e. import clo.clo; Oh and you should get familiar with the dsss.conf file. This is the way you normally build your project. http://www.dsource.org/projects/dsss/wiki/DSSSForSoftwareEngineers

Re: New to D: Building multiple files

2009-03-29 Thread torhu
On 29.03.2009 17:04, chris wrote: Alright so I'm not too familiar with building D or having to build multiple files from the command line (Java usually takes care of that). Basically I have a small game I put together as a test project. Here's the structure: clo/clo.d clo/Main.d clo/common/Game