Where can get the strsafe.d by strsafe.h ? Thanks.

2018-02-24 Thread FrankLike via Digitalmars-d-learn
Hi,everyone, Now,I use some code in strsafe.h,but where can get the strsafe.d ? Thanks.

Re: countUntil to print all the index of a given string.

2018-02-24 Thread Vino via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 08:50:27 UTC, Jonathan M Davis wrote: On Tuesday, February 20, 2018 08:44:37 aberba via Digitalmars-d-learn wrote: On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote: > On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote: >> [...] > > Just thought of a

Re: How to split a string to a 2D array

2018-02-24 Thread Domain via Digitalmars-d-learn
On Saturday, 24 February 2018 at 08:59:46 UTC, Domain wrote: On Saturday, 24 February 2018 at 07:51:27 UTC, Domain wrote: [...] And why this not compile: rows.each!(a => data ~= a.split(",").map!(b => b.strip).padRight("", 2)); Error: cannot deduce function from argument types

Re: Double link list

2018-02-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote: I'm trying some code for practice, but it isn't working properly - it prints just one number when printing in reverse. I think the problem is here: void popFront() { head = head.next; if (head !is null) head.prev = null; } void

Re: How to split a string to a 2D array

2018-02-24 Thread Domain via Digitalmars-d-learn
On Saturday, 24 February 2018 at 07:51:27 UTC, Domain wrote: I want to convert a string like " a,b1, 23 " to a 2D array like: [["a", "b"], ["1", "2"], ["3", "" ]] auto html = " a,b1, 23 "; auto rows = html.strip.chomp("").split(""); string[][] data; rows.each!(a => data ~= a.split(","));

Double link list

2018-02-24 Thread Joel via Digitalmars-d-learn
I'm trying some code for practice, but it isn't working properly - it prints just one number when printing in reverse. ''' void main() { import std.stdio, std.algorithm, std.range, std.conv; struct List(T) { class Node { T value;

Re: How to convert C macro to D? Thanks.

2018-02-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 24 February 2018 at 13:50:16 UTC, FrankLike wrote: #define IOCTL_NDIS_QUERY_GLOBAL_STATS _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT) use alias or enum,how to do? neither. those are little functions. auto IOCTL_NDIS_QUERY_GLOBAL_STATS () { return _NDIS_CONTROL_CODE(0,

Re: How to convert C macro to D? Thanks.

2018-02-24 Thread FrankLike via Digitalmars-d-learn
On Saturday, 24 February 2018 at 13:57:27 UTC, Adam D. Ruppe wrote: On Saturday, 24 February 2018 at 13:50:16 UTC, FrankLike wrote: #define IOCTL_NDIS_QUERY_GLOBAL_STATS _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT) auto IOCTL_NDIS_QUERY_GLOBAL_STATS () { return _NDIS_CONTROL_CODE(0,

Re: How to split a string to a 2D array

2018-02-24 Thread Seb via Digitalmars-d-learn
On Saturday, 24 February 2018 at 09:06:09 UTC, Domain wrote: On Saturday, 24 February 2018 at 08:59:46 UTC, Domain wrote: On Saturday, 24 February 2018 at 07:51:27 UTC, Domain wrote: [...] And why this not compile: rows.each!(a => data ~= a.split(",").map!(b => b.strip).padRight("", 2));

Re: Double link list

2018-02-24 Thread ag0aep6g via Digitalmars-d-learn
On 02/24/2018 11:26 AM, TheFlyingFiddle wrote: On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote: [...] void popFront() { head = head.next;  if (head !is null) head.prev = null; } void popBack() { tail = tail.prev; if (tail !is null) tail.next = null; } Head and tail will point to

Re: Double link list

2018-02-24 Thread Alex via Digitalmars-d-learn
On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote: I'm trying some code for practice, but it isn't working properly - it prints just one number when printing in reverse. [...] the first writeln destroys the range via popFront, I think. As if you comment it out, the writeln with

How to convert C macro to D? Thanks.

2018-02-24 Thread FrankLike via Digitalmars-d-learn
Hi,everyone, I can convert some simple C macros, but a bit more complicated will need your help. For example: #define _NDIS_CONTROL_CODE(request,method) \ CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, method, FILE_ANY_ACCESS) #define IOCTL_NDIS_QUERY_GLOBAL_STATS

Re: Vibe.d no more using static this() {}

2018-02-24 Thread bauss via Digitalmars-d-learn
On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote: I recently noticed vibe.d now using main loop which call the vibe.d event loop. Why that change? I can only assume it's because static constructors are a pain in the ass. https://dlang.org/spec/module.html#order_of_static_ctor

short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () { short s, t; t = -s; } --- $ dmd intprom.d intprom.d(6): Deprecation: integral promotion not done for -s, use '-transition=intpromote' switch or -cast(int)(s) What shall I do in order to

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/18 3:07 PM, kdevel wrote: I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () {    short s, t;    t = -s; } --- https://dlang.org/changelog/2.078.0.html#fix16997 $ dmd intprom.d intprom.d(6): Deprecation: integral promotion not done for

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 20:17:12 UTC, Steven Schveighoffer wrote: On 2/24/18 3:07 PM, kdevel wrote: I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () {    short s, t;    t = -s; } --- https://dlang.org/changelog/2.078.0.html#fix16997

formattedRead string without allocation?

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
I want to use formattedRead to enforce a certain format, and easily parse out the data from a string. But if I do: string s = "123:abc:123"; string y; assert(s.formattedRead!"123:%s:123"(y) == 1); y is now a newly-allocated string, not a slice of the input. In the case of parsing strings

Re: Where can get the strsafe.d by strsafe.h ? Thanks.

2018-02-24 Thread bauss via Digitalmars-d-learn
On Saturday, 24 February 2018 at 14:58:52 UTC, FrankLike wrote: Hi,everyone, Now,I use some code in strsafe.h,but where can get the strsafe.d ? Thanks. Basically nowhere. strsafe.h is non-standard. What you have to do is create the binding yourself.

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/18 4:42 PM, kdevel wrote: On Saturday, 24 February 2018 at 20:17:12 UTC, Steven Schveighoffer wrote: https://dlang.org/changelog/2.078.0.html#fix16997 My goodness! So there is currently no negation operator defined on short and some other types? No, that's not the case. It's simply

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread kdevel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 22:30:09 UTC, Steven Schveighoffer wrote: The prime example is this: byte b = -128; int x = -b; What would you expect x to be? a) 128 b) -128 Neither nor. I would prefer the codomain of "-" be the range of byte and hence an exception thrown in that

Re: short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use

2018-02-24 Thread ixid via Digitalmars-d-learn
On Saturday, 24 February 2018 at 20:07:04 UTC, kdevel wrote: I don't get the point of the deprecation message: --- intprom.d import std.stdio; void main () { short s, t; t = -s; } --- $ dmd intprom.d intprom.d(6): Deprecation: integral promotion not done for -s, use

compilers w/ different language features: version block

2018-02-24 Thread kdevel via Digitalmars-d-learn
A code fragment using static foreach https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-beruryblsptnunsowjph:40forum.dlang.org does not compile with the current GDC (GCC 4.9.4 and 5.5.0). I tried to encapsulate this code into a version block but GDC still checks the

Re: compilers w/ different language features: version block

2018-02-24 Thread Seb via Digitalmars-d-learn
On Sunday, 25 February 2018 at 00:36:16 UTC, kdevel wrote: A code fragment using static foreach https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-beruryblsptnunsowjph:40forum.dlang.org does not compile with the current GDC (GCC 4.9.4 and 5.5.0). I tried to encapsulate

Re: compilers w/ different language features: version block

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 00:36:16 kdevel via Digitalmars-d-learn wrote: > A code fragment using static foreach > > https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-b > eruryblsptnunsowjph:40forum.dlang.org > > does not compile with the current GDC (GCC 4.9.4 and 5.5.0).

Re: compilers w/ different language features: version block

2018-02-24 Thread Seb via Digitalmars-d-learn
On Sunday, 25 February 2018 at 00:42:20 UTC, Seb wrote: On Sunday, 25 February 2018 at 00:36:16 UTC, kdevel wrote: [...] Are you looking for something like this? --- static if (__traits(compiles, () { static foreach (i; [0]){} })) version = supportsStaticForeach; void main() {

Re: iota to array

2018-02-24 Thread Seb via Digitalmars-d-learn
On Sunday, 25 February 2018 at 05:24:54 UTC, psychoticRabbit wrote: Hi. Anyone know whether something like this is possible? I've tried various conversions/casts, but no luck yet. Essentially, I want to cast the result set of the iota to an array, during initialisation of the variable. You

Re: countUntil to print all the index of a given string.

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 02:58:33 Seb via Digitalmars-d-learn wrote: > On Sunday, 25 February 2018 at 02:37:00 UTC, Jonathan M Davis > > wrote: > > If any exceptions could be thrown, then a lazy solution can't > > be @nogc (something that's often the case with strings thanks > > to

Re: countUntil to print all the index of a given string.

2018-02-24 Thread Seb via Digitalmars-d-learn
On Tuesday, 20 February 2018 at 08:44:37 UTC, aberba wrote: On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote: On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote: [...] Just thought of a much better/simpler solution for that last case that also doesn't force you to read all

Re: countUntil to print all the index of a given string.

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 01:49:05 Seb via Digitalmars-d-learn wrote: > On Tuesday, 20 February 2018 at 08:44:37 UTC, aberba wrote: > > On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote: > >> On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote: > >>> [...] > >> > >> Just thought of

Re: countUntil to print all the index of a given string.

2018-02-24 Thread Seb via Digitalmars-d-learn
On Sunday, 25 February 2018 at 02:37:00 UTC, Jonathan M Davis wrote: If any exceptions could be thrown, then a lazy solution can't be @nogc (something that's often the case with strings thanks to auto-decoding and UTFExceptions), and a solution could be eager without allocating if the result

Re: Vibe.d no more using static this() {}

2018-02-24 Thread Seb via Digitalmars-d-learn
On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote: I recently noticed vibe.d now using main loop which call the vibe.d event loop. "Recently"? FWIW this has been phased out a long time ago ;-) --- 0.7.23 (2015) Definition of either VibeCustomMain or VibeDefaultMain is now a hard

Re: Template Constraints

2018-02-24 Thread Jonathan via Digitalmars-d-learn
On Saturday, 24 February 2018 at 03:04:07 UTC, Adam D. Ruppe wrote: On Saturday, 24 February 2018 at 02:54:13 UTC, Jonathan wrote: I am having trouble finding many useful explanations of using template constraints beyond basic usage. The constraint is just like static if as to what it allows

Re: iota to array

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 05:24:54 psychoticRabbit via Digitalmars-d- learn wrote: > Hi. Anyone know whether something like this is possible? > > I've tried various conversions/casts, but no luck yet. > > Essentially, I want to cast the result set of the iota to an > array, during

Re: iota to array

2018-02-24 Thread Uknown via Digitalmars-d-learn
On Sunday, 25 February 2018 at 06:22:03 UTC, psychoticRabbit wrote: On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis wrote: int[] intArr = iota(1, 11).array(); - Jonathan M Davis thanks! oh man. It's so easy to do stuff in D ;-) But this leads me to a new problem now.

Re: iota to array

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 06:22:03 psychoticRabbit via Digitalmars-d- learn wrote: > On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis > > wrote: > > int[] intArr = iota(1, 11).array(); > > > > - Jonathan M Davis > > thanks! > > oh man. It's so easy to do stuff in D ;-) > > But

Re: compilers w/ different language features: version block

2018-02-24 Thread Seb via Digitalmars-d-learn
On Sunday, 25 February 2018 at 01:19:02 UTC, Seb wrote: On Sunday, 25 February 2018 at 00:42:20 UTC, Seb wrote: On Sunday, 25 February 2018 at 00:36:16 UTC, kdevel wrote: [...] Are you looking for something like this? --- static if (__traits(compiles, () { static foreach (i; [0]){} }))

Re: iota to array

2018-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 25, 2018 at 06:22:03AM +, psychoticRabbit via Digitalmars-d-learn wrote: [..] > printArray(doubleArr); // why is it printing ints instead of doubles?? [...] > void printArray(T)(const ref T[] a) if (isArray!(T[])) > { > foreach(t; a) > writeln(t); Try:

iota to array

2018-02-24 Thread psychoticRabbit via Digitalmars-d-learn
Hi. Anyone know whether something like this is possible? I've tried various conversions/casts, but no luck yet. Essentially, I want to cast the result set of the iota to an array, during initialisation of the variable. no, I don't want to use 'auto'. I want an array object ;-)

Re: iota to array

2018-02-24 Thread psychoticRabbit via Digitalmars-d-learn
On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis wrote: int[] intArr = iota(1, 11).array(); - Jonathan M Davis thanks! oh man. It's so easy to do stuff in D ;-) But this leads me to a new problem now. When I run my code below, I get ints printed instead of doubles??

Re: Double link list

2018-02-24 Thread Joel via Digitalmars-d-learn
On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote: I'm trying some code for practice, but it isn't working properly - it prints just one number when printing in reverse. [snip] Thanks guys. And I got it working with 'if (head is tail)' etc.