Re: C++ Interop

2018-01-06 Thread qznc via Digitalmars-d-learn
On Saturday, 6 January 2018 at 11:20:01 UTC, Seb wrote: On Saturday, 6 January 2018 at 11:17:56 UTC, Seb wrote: On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote: I'm exploring [0] C++ interop after watching Walter's presentation [1]. [...] I know about this:

C++ Interop

2018-01-05 Thread qznc via Digitalmars-d-learn
I'm exploring [0] C++ interop after watching Walter's presentation [1]. I hit a block with classes as template parameters. This means vector works, but vector does not. D seems to map vector!Foo to vector. Likewise shared_ptr is a problem. Any way to fix that on the D side? The ugly

Re: Use of "T"

2017-04-12 Thread qznc via Digitalmars-d-learn
On Wednesday, 12 April 2017 at 13:17:42 UTC, solidstate1991 wrote: How can I make use of T? I've seen it being used many times for this application. What "T"? This letter is often used as a generic template parameter. Are you talking about templates? Maybe you can give some examples of the

Dub and bindings

2017-03-11 Thread qznc via Digitalmars-d-learn
Are there any general tips or best practices for bindings in dub packages? For example, I love the d2sqlite3 package. It just works out of the box. No linker configuration or anything. However, that is probably a testament to sqlite's lack of dependencies. That cannot work for libraries,

Re: About spinlock implementation

2016-09-01 Thread qznc via Digitalmars-d-learn
On Thursday, 1 September 2016 at 10:30:12 UTC, Guillaume Piolat wrote: On Thursday, 1 September 2016 at 07:46:04 UTC, qznc wrote: I find the documentation on MemoryOrder lacking about the semantics of rel. :( [0] https://dlang.org/library/core/atomic/memory_order.html What helped me was

Re: About spinlock implementation

2016-09-01 Thread qznc via Digitalmars-d-learn
On Thursday, 1 September 2016 at 06:44:13 UTC, mogu wrote: I found an implementation of spinlock in concurrency.d. ``` static shared struct SpinLock { void lock() { while (!cas(, false, true)) { Thread.yield(); } } void unlock() { atomicStore!(MemoryOrder.rel)(locked, false); }

Re: Implementing a cache

2016-07-03 Thread qznc via Digitalmars-d-learn
On Saturday, 2 July 2016 at 12:21:14 UTC, Lodovico Giaretta wrote: On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote: Alternatively, any better idea to implement the cache? I guess there is no off-the-shelf/dub solution. For now, I settled for a sorted array of cache entries plus an AA to

Implementing a cache

2016-07-02 Thread qznc via Digitalmars-d-learn
I want to implement some caching for HTTP GET requests. Basically a map of URL to content. A cache needs some additional meta data (size, age, etc). There seem to be two basic data structures available: Associative array (AA) or red black tree (RBT). With AA cache eviction is inefficient.

Re: String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
On Sunday, 29 May 2016 at 17:42:48 UTC, Era Scarecrow wrote: Worse I'm not sure if the code generation already does that and possibly does a better job than what we could do by hand... Not with dmd v2.071.0 or ldc 0.17.1. At least not in all the variations I tried to trick them with, like

Re: String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
On Sunday, 29 May 2016 at 18:15:16 UTC, qznc wrote: On Sunday, 29 May 2016 at 17:38:17 UTC, Jonathan M Davis wrote: And if you're not simply comparing for equality, what are you looking to figure out? Without more information about what you're trying to do, it's kind of hard to help you. If

Re: String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
On Sunday, 29 May 2016 at 17:38:17 UTC, Jonathan M Davis wrote: And if you're not simply comparing for equality, what are you looking to figure out? Without more information about what you're trying to do, it's kind of hard to help you. If I write the comparison naively, the assembly clearly

String compare in words?

2016-05-29 Thread qznc via Digitalmars-d-learn
Given two string (or char[] or ubyte[]) objects, I want to compare them. The naive loop accesses the arrays byte-wise. How could I turn this into a word-wise compare for better performance? Is a cast into size_t[] ok? Some Phobos helper functions?

Re: Newbie to D, first impressions and feedback on the 5 (and more) first minutes.

2016-05-25 Thread qznc via Digitalmars-d-learn
On Wednesday, 25 May 2016 at 09:41:10 UTC, Russel Winder wrote: I do not really have the proper resources to host such a repository and because of this I have not built one. I know I should rather than just moan, but Debian is my main platform and that is covered. Yes, this is the core

Re: Newbie to D, first impressions and feedback on the 5 (and more) first minutes.

2016-05-24 Thread qznc via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 15:27:45 UTC, llaine wrote: As written in the description I'm really new to D, I discovered it a few weeks ago thanks to the D Conf in Berlin. After playing around for couple of days with it, I wanted to share my journey with you guys on several points. Thanks for

Re: reading file byLine

2015-09-02 Thread qznc via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 13:46:54 UTC, Namal wrote: On Wednesday, 2 September 2015 at 13:12:39 UTC, cym13 wrote: On Wednesday, 2 September 2015 at 13:01:31 UTC, Namal wrote: Hello, I want to read a file line by line and store each line in a string. I found this example with byLine

Profiling with LDC/GDC?

2015-09-01 Thread qznc via Digitalmars-d-learn
Is it possible to profile with LDC/GDC? At least LDC lists it as only an "idea". http://wiki.dlang.org/LDC_project_ideas

Re: linking external libs

2015-08-29 Thread qznc via Digitalmars-d-learn
On Thursday, 2 July 2015 at 12:10:52 UTC, Nicholas Wilson wrote: Also is there a binding to GMP somewhere? I just hacked one together. I could need the bindings to fix the pidigits benchmark. There is this 7y old code on dsource: http://www.dsource.org/projects/bindings/browser/trunk/gmp

Packing enums

2015-06-30 Thread qznc via Digitalmars-d-learn
I stumbled upon this interesting programming challenge [0], which imho should be possible to implement in D. Maybe someone here wants to try. Task: Given two enums with less than 256 states, pack them into one byte and provide convenient accessor functions. Something like this: enum X { A,

Re: std.container.Array deep-copy?

2014-10-10 Thread qznc via Digitalmars-d-learn
On Friday, 10 October 2014 at 06:27:35 UTC, yazd wrote: On Thursday, 9 October 2014 at 21:24:55 UTC, qznc wrote: On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote: How can you deep-copy a std.container.Array instance? Ok, the deep-copy problem already got resolved on reddit: Use dup.

Re: std.container.Array deep-copy?

2014-10-10 Thread qznc via Digitalmars-d-learn
On Friday, 10 October 2014 at 10:59:59 UTC, Sag Academy wrote: On Friday, 10 October 2014 at 10:32:17 UTC, yazd wrote: Like the following? That did not work. Array!Foo y = Array!Foo(x[]); How does it not work? It compiles successfully: http://dpaste.dzfl.pl/583d20e426a0 yeah man. You

std.container.Array deep-copy?

2014-10-09 Thread qznc via Digitalmars-d-learn
How can you deep-copy a std.container.Array instance? The actual array data is heap-allocated and reference-counted. Assignment and .dup only create additional references. Using a copy constructor yields an error: Array!Foo x; Array!Foo y = Array!Foo(x); Error: template

Re: std.container.Array deep-copy?

2014-10-09 Thread qznc via Digitalmars-d-learn
On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote: How can you deep-copy a std.container.Array instance? Ok, the deep-copy problem already got resolved on reddit: Use dup. However, the error is still open. You cannot give an Array!X argument to constructor/replace/insertBefore of