Re: How to use the Among method with a string array

2017-09-16 Thread Andrew Chapman via Digitalmars-d-learn
On Saturday, 16 September 2017 at 12:09:28 UTC, Adam D. Ruppe wrote: On Saturday, 16 September 2017 at 11:18:45 UTC, Andrew Chapman wrote: string[] fruit = ["apple", "pear", "strawberry"]; How do I use "among" to see if "apple" is present. E.g. I want to do this: if ("apple".among(fruit))

How to use the Among method with a string array

2017-09-16 Thread Andrew Chapman via Digitalmars-d-learn
Hi all, sorry for the very simple question, but I'm looking at the "among" function in std.comparison: https://dlang.org/phobos/std_algorithm_comparison.html#among If I have a string array: string[] fruit = ["apple", "pear", "strawberry"]; How do I use "among" to see if "apple" is present.

Re: Web servers in D

2017-09-02 Thread Andrew Chapman via Digitalmars-d-learn
On Friday, 25 August 2017 at 05:25:09 UTC, Hasen Judy wrote: What libraries are people using to run webservers other than vibe.d? Don't get me wrong I like the async-io aspect of vibe.d but I don't like the weird template language and the fact that it caters to mongo crowd. I think for D

Re: Confusion over enforce and assert - both are compiled out in release mode

2017-08-27 Thread Andrew Chapman via Digitalmars-d-learn
On Sunday, 27 August 2017 at 10:37:50 UTC, Moritz Maxeiner wrote: On Sunday, 27 August 2017 at 10:17:47 UTC, Andrew Chapman wrote: On Sunday, 27 August 2017 at 10:08:15 UTC, ag0aep6g wrote: [...] Thanks, that explains it. I think it's a bit of a shame that the "in" blocks can't be used in

Re: Confusion over enforce and assert - both are compiled out in release mode

2017-08-27 Thread Andrew Chapman via Digitalmars-d-learn
On Sunday, 27 August 2017 at 10:08:15 UTC, ag0aep6g wrote: On 08/27/2017 12:02 PM, Andrew Chapman wrote: However, I am finding that BOTH enforce and assert are compiled out by dmd and ldc in release mode. Is there a standard way of doing what enforce does inside an "in" contract block that

Confusion over enforce and assert - both are compiled out in release mode

2017-08-27 Thread Andrew Chapman via Digitalmars-d-learn
In the docs regarding contract programming and the use of enforce / assert: https://dlang.org/library/std/exception/enforce.html it says: "enforce is used to throw exceptions and is therefore intended to aid in error handling. It is not intended for verifying the logic of your program. That

Re: How to store data when using parallel processing

2017-08-27 Thread Andrew Chapman via Digitalmars-d-learn
On Sunday, 27 August 2017 at 01:58:04 UTC, Jonathan M Davis wrote: [...] Thanks Jonathan, that makes sense. As it turns out, the Mutex approach actually makes things slower. In this case I believe trying to use multiple cores isn't worth it. Cheers.

How to store data when using parallel processing

2017-08-26 Thread Andrew Chapman via Digitalmars-d-learn
Hi all, just wanting some advice on parallel processing and specifically how to deal with access violations. I am reading a list of words from a file like this: auto fileHandle = File("wordlist.txt", "r"); string word; string[] words; string[ulong] hashMap; while ((word =

Re: Using templates with interfaces

2017-06-27 Thread Andrew Chapman via Digitalmars-d-learn
On Sunday, 25 June 2017 at 17:30:58 UTC, Petar Kirov [ZombineDev] wrote: On Sunday, 25 June 2017 at 13:32:57 UTC, Andrew Chapman wrote: I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing

Re: Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing this. Cheers.

Re: Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
On Sunday, 25 June 2017 at 13:04:32 UTC, Nicholas Wilson wrote: On Sunday, 25 June 2017 at 11:39:27 UTC, Andrew Chapman wrote: Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol

Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol Undefined _D12relationaldb10interfaces21RÇëÜDBIÇêÿ35__T7loadRowTS6prefix÷6P¶ZÇêáMFAyaAS3std7variant18Çâ└8VÇåìNVki20ZÇëÅZÇûð

Re: Get the address of an object, within the object itself

2017-02-15 Thread Andrew Chapman via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 21:37:12 UTC, Jonathan M Davis wrote: On Wednesday, February 15, 2017 13:33:23 Jonathan M Davis via Digitalmars-d- learn wrote: On Wednesday, February 15, 2017 21:27:00 Andrew Chapman via Digitalmars-d- learn wrote: > Hi all, sorry if this question is si

Get the address of an object, within the object itself

2017-02-15 Thread Andrew Chapman via Digitalmars-d-learn
Hi all, sorry if this question is silly, but is it possible to get the address of an object within the object itself? e.g. class Node { this() { writeln(); // Doesn't work } } auto node = new Node(); writeln(); // Does work Thanks very much, Cheers, Andrew.

Re: How to use a char[] buffer in D

2016-06-23 Thread Andrew Chapman via Digitalmars-d-learn
Perfect, thank you! :-) Works like a charm. On Wednesday, 22 June 2016 at 22:41:24 UTC, H. S. Teoh wrote: On Wed, Jun 22, 2016 at 09:57:04PM +, Andrew Chapman via Digitalmars-d-learn wrote: Maybe try: if (buffer[] in myHash) { ... } ? Does that make a difference? T

How to use a char[] buffer in D

2016-06-22 Thread Andrew Chapman via Digitalmars-d-learn
Hi everyone, just wanting some help with optimisation if anyone is kind enough :-) I have a loop that iterates potentially millions of times, and inside that loop I have code that appends some strings together, e.g.: string key = s1 ~ "_" ~ s2; I discovered that due to the memory

Re: Dynamically setting struct values from hash map

2016-05-12 Thread Andrew Chapman via Digitalmars-d-learn
On Thursday, 12 May 2016 at 21:01:06 UTC, Adam D. Ruppe wrote: foreach(member; __traits(allMembers, YourStruct)) if(member in yourhash) __traits(getMember, your_object, member) = to!right_type(yourhash[member]); basically, it is a bit more complex to filter out inappropriate fields

Dynamically setting struct values from hash map

2016-05-12 Thread Andrew Chapman via Digitalmars-d-learn
Hi guys, apologies for the silly question, but I come from the world of dynamic languages and I'm wondering if it's possible to set struct values basic on dynamic variables? e.g. struct Person { string firstName; string lastName; } void main() { string[string] map;

Re: Most performant way of converting int to string

2015-12-23 Thread Andrew Chapman via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 11:46:37 UTC, Jakob Ovrum wrote: On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum wrote: Dynamic memory allocation is expensive. If the string is short-lived, allocate it on the stack: See also std.conv.toChars[1] for stringifying lazily/on-demand.

Re: Most performant way of converting int to string

2015-12-22 Thread Andrew Chapman via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 18:11:24 UTC, rumbu wrote: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s =

Re: Most performant way of converting int to string

2015-12-22 Thread Andrew Chapman via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:43:00 UTC, H. S. Teoh wrote: I wonder if the slowdown is caused by GC collection cycles (because calling to!string will allocate, and here you're making a very large number of small allocations, which is known to cause GC performance issues). Try inserting

Most performant way of converting int to string

2015-12-22 Thread Andrew Chapman via Digitalmars-d-learn
Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s = to!string(100); I'm seeing a pretty dramatic slow down in my code when I use a conversion like this (when looped over 10 million

Re: Most performant way of converting int to string

2015-12-22 Thread Andrew Chapman via Digitalmars-d-learn
On Tuesday, 22 December 2015 at 17:18:16 UTC, cym13 wrote: On Tuesday, 22 December 2015 at 17:15:27 UTC, Andrew Chapman wrote: Sorry if this is a silly question but is the to! method from the conv library the most efficient way of converting an integer value to a string? e.g. string s =