Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Justin Whear via Digitalmars-d-learn
On Thu, 22 Oct 2015 11:55:37 +, Nordlöw wrote: > What's wrong? HashSet has a disabled default constructor; you need to supply the allocator instance to the constructor here https://github.com/nordlow/ justd/blob/master/containers_ex.d#L17

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 17:32:34 UTC, Justin Whear wrote: On Thu, 22 Oct 2015 11:55:37 +, Nordlöw wrote: What's wrong? HashSet has a disabled default constructor; you need to supply the allocator instance to the constructor here https://github.com/nordlow/

Re: Implicit conversion rules

2015-10-22 Thread Sigg via Digitalmars-d-learn
On Wednesday, 21 October 2015 at 22:49:16 UTC, Marco Leise wrote: God forbid anyone implement such nonsense into D ! That would be the last thing we need Slight nitpick, but what I suggested for our hypothetical situation was only to apply for auto, once variable was assigned to auto and

Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8?

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 18:28:50 UTC, Ali Çehreli wrote: If you already have a piece of memory, it is trivial to convert it to a slice in D: auto slice = existing_pointer[0 .. number_of_elements]; http://ddili.org/ders/d.en/pointers.html#ix_pointers.slice%20from%20pointer The

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/2015 11:20 AM, pineapple wrote: > I'd like to use fread and fwrite in place of File.rawRead and > File.rawWrite which force the creation of an array where I'd rather > specify a buffer location and length. Would you not create that buffer? :) If you already have a piece of memory, it

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
Answered my own question: Turns out File.getFP() does exactly what I needed

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On Thursday, October 22, 2015 08:10 PM, Nordlöw wrote: > How do I convert a `string` containing Unicode escape sequences > such as "\u" into UTF-8? Ali explained that "\u" is already UTF-8. But if you actually want to interpret such escape sequences from user input or some such, then

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread Kagamin via Digitalmars-d-learn
On Thursday, 22 October 2015 at 15:10:58 UTC, pineapple wrote: What does if(isIntegral!T) do? It looks like it would verify that the template type is a discrete number? It doesn't verify, but filters: you can have several templates with the same name, when filter doesn't match, compiler tries

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 19:16:36 UTC, Nordlöw wrote: Can somebody point out in which function/file DMD does this decoding? std.conv.parseEscape includes this logic. But why is it private?

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Justin Whear via Digitalmars-d-learn
On Thu, 22 Oct 2015 19:41:08 +, Nordlöw wrote: > My existing call to > > auto set = HashSet!(E, Allocator)(); > > works for Mallocator as in > > https://github.com/nordlow/justd/blob/master/containers_ex.d#L17 > > but not for > > InSituRegion!(1024*1024, T.alignof) > > Why?

Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
I'd like to use fread and fwrite in place of File.rawRead and File.rawWrite which force the creation of an array where I'd rather specify a buffer location and length. I'd like to do this using a File object but the handle for the C stream is a private member and I can't find any way to access

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 18:40:06 UTC, anonymous wrote: On Thursday, October 22, 2015 08:10 PM, Nordlöw wrote: How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8? Ali explained that "\u" is already UTF-8. But if you actually want to

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/2015 11:10 AM, Nordlöw wrote: How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8? It's already UTF-8 because it's a 'string'. :) import std.stdio; void main() { auto s = "\u1234"; foreach (codeUnit; s) { writefln("%02x %08b",

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread John Colvin via Digitalmars-d-learn
On Thursday, 22 October 2015 at 18:20:07 UTC, pineapple wrote: I'd like to use fread and fwrite in place of File.rawRead and File.rawWrite which force the creation of an array where I'd rather specify a buffer location and length. D's arrays *are* just buffer locations and lengths with a few

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 19:13:20 UTC, Nordlöw wrote: * Drop the backslash and the 'u'. * Parse as a hexadecimal integer, and cast to dchar. * Use std.utf.encode to convert to UTF-8. std.conv.to can probably do it too, and possibly simpler, but would allocate. Also be aware of the

Array of subclasses

2015-10-22 Thread DarkRiDDeR via Digitalmars-d-learn
Hello. I have a class: abstract class Addon { public activate(){...} ... } its children: class A: Addon {... } class B: Addon {... } How do I create an array of subclasses Addon? For example, one could to do so: T[2] addons = [new A(), new B()]; foreach(T addon; addons){

Re: Array of subclasses

2015-10-22 Thread DarkRiDDeR via Digitalmars-d-learn
This works: abstract class Addon { public void activate() { } } class A: Addon {} class B: Addon {} void main() { Addon[2] addons = [new A(), new B()]; } This works too: Addon[] addons = [new A(), new B()]; I am happy to report that even the following works with dmd

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 11:55:39 UTC, Nordlöw wrote: https://github.com/nordlow/justd/blob/master/containers_ex.d The current GitHub of containers_ex.d (using dmd git master) version works if justd repo is cloned recursively.

Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
At https://github.com/nordlow/justd/blob/master/containers_ex.d I want to benchmark Economic Modelings container packages. Specifically HashSet with different allocators. But when I try to use `LocalAllocator` defined as alias LocalAllocator = InSituRegion!(n, T.alignof); at

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 11:57:37 UTC, Nordlöw wrote: On Thursday, 22 October 2015 at 11:55:39 UTC, Nordlöw wrote: https://github.com/nordlow/justd/blob/master/containers_ex.d The current GitHub of containers_ex.d (using dmd git master) version works if justd repo is cloned

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On 22.10.2015 21:13, Nordlöw wrote: Hmm, why isn't this already in Phobos? I think parsing only Unicode escape sequences is not a common task. You usually need to parse some larger language of which escape sequences are only a part. For example, parsing JSON or XML are common tasks, and we

Re: [sdc] linker problems when building programs with sdc

2015-10-22 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
... or, it turns out, sdc doesn't like it when you forget to rewrite `void main()` as `int main()`, and its error messages are still in the cryptic stage :-P Onwards and upwards, then ... :-) On 18/10/15 19:58, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: Turns out even `return

Re: Overloading an imported function

2015-10-22 Thread anonymous via Digitalmars-d-learn
On 22.10.2015 06:14, Shriramana Sharma wrote: anonymous wrote: Huh. I can't find any specification on this, but apparently the local overload set shadows any imported overload sets completely. Should I file a bug on this then? I'm not sure. Maybe make a thread on the main group first. It's

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Brian Schott via Digitalmars-d-learn
On Thursday, 22 October 2015 at 22:06:47 UTC, Nordlöw wrote: Can't I use InSituRegion in this way? No. InSituRegion is not copyable. Try creating a `HashSet!(InSituRegion*)` instead.

Re: D serialization temporary fixup?

2015-10-22 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma wrote: I wanted a D equivalent to: http://doc.qt.io/qt-5/qdatastream.html https://docs.python.org/3/library/pickle.html and saw that one is under construction: http://wiki.dlang.org/Review/std.serialization But till it's

Re: What's wrong in this templatized operator overload ?

2015-10-22 Thread MobPassenger via Digitalmars-d-learn
On Thursday, 22 October 2015 at 05:17:29 UTC, Cauterite wrote: On Thursday, 22 October 2015 at 04:25:01 UTC, MobPassenger wrote: On Thursday, 22 October 2015 at 04:01:16 UTC, Mike Parker wrote: On Thursday, 22 October 2015 at 03:19:49 UTC, MobPassenger wrote: code: --- struct Foo { bool

Re: Array of subclasses

2015-10-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 22 October 2015 at 06:14:34 UTC, DarkRiDDeR wrote: T[2] addons = [new A(), new B()]; Until pretty recently the compiler was a little picky about the types here so you might have to explicitly cast the first element to the base clas type. T[2] addons = [cast(T) new A(), new

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 13:58:56 UTC, Adam D. Ruppe wrote: D's templates are easy (you actually used one in there, the Generator is one!) Try this: import std.concurrency; Generator!T sequence(T)(T i){ return new Generator!T({ yield(i); while(i > 1){

Re: Array of subclasses

2015-10-22 Thread Maxim Fomin via Digitalmars-d-learn
On Thursday, 22 October 2015 at 13:29:06 UTC, DarkRiDDeR wrote: I don't need the base class data. How to create a array of subclasses objects with the derived data members? The language is implemented in this way. You have already have the answer: writeln(Core.users.name) Out: USERS

Re: Array of subclasses

2015-10-22 Thread DarkRiDDeR via Digitalmars-d-learn
I found the following solution: abstract class Addon { public string name = "0"; public void updateOfClassFields() { } } class Users: Addon { override { public void updateOfClassFields() {

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread John Colvin via Digitalmars-d-learn
On Thursday, 22 October 2015 at 13:53:33 UTC, pineapple wrote: I'm just starting to hammer D's very pleasant syntax into my head. After "Hello world", the first thing I do when learning any language is to write a simple program which generates and outputs the Collatz sequence for an arbitrary

Re: error detected at """ ch in unicode.C """ Library error?

2015-10-22 Thread Charles Hixson via Digitalmars-d-learn
On 10/21/2015 06:21 PM, Charles Hixson via Digitalmars-d-learn wrote: To me this looks like a library error, but I'm not sure. Any suggestions importstd.uni; chargcCat1(dchar ch) { if(ch in unicode.L)return'L';// Letter if(ch in unicode.M)

Re: Array of subclasses

2015-10-22 Thread DarkRiDDeR via Digitalmars-d-learn
On Thursday, 22 October 2015 at 12:24:05 UTC, Maxim Fomin wrote: On Thursday, 22 October 2015 at 11:02:05 UTC, DarkRiDDeR wrote: This variant works strangely. Example: abstract class Addon { public string name = "0"; } class Users: Addon { override {

Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
I'm just starting to hammer D's very pleasant syntax into my head. After "Hello world", the first thing I do when learning any language is to write a simple program which generates and outputs the Collatz sequence for an arbitrary number. (I also like to golf it.) This is what I wrote in D:

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 22 October 2015 at 13:53:33 UTC, pineapple wrote: import std.concurrency; Generator!int sequence(int i){ return new Generator!int({ yield(i); while(i > 1){ yield(i = (i % 2) ? (i * 3 + 1) : (i >> 1)); } }); } Which can be used like so:

Re: Array of subclasses

2015-10-22 Thread Maxim Fomin via Digitalmars-d-learn
On Thursday, 22 October 2015 at 11:02:05 UTC, DarkRiDDeR wrote: This variant works strangely. Example: abstract class Addon { public string name = "0"; } class Users: Addon { override { public string name = "USERS"; } } static final class Core {

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 14:36:52 UTC, John Colvin wrote: Using ranges instead of threads or fibers, slightly over-engineered to show off features: What does if(isIntegral!T) do? It looks like it would verify that the template type is a discrete number? If I were to create my own

Re: Array of subclasses

2015-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/21/2015 11:14 PM, DarkRiDDeR wrote: Hello. I have a class: abstract class Addon { public activate(){...} ... } its children: class A: Addon {... } class B: Addon {... } How do I create an array of subclasses Addon? For example, one could to do so: T[2] addons = [new A(), new

Re: D serialization temporary fixup?

2015-10-22 Thread Laeeth Isharc via Digitalmars-d-learn
On Thursday, 22 October 2015 at 16:28:30 UTC, Laeeth Isharc wrote: On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma wrote: I wanted a D equivalent to: http://doc.qt.io/qt-5/qdatastream.html https://docs.python.org/3/library/pickle.html and saw that one is under construction:

Re: D serialization temporary fixup?

2015-10-22 Thread Laeeth Isharc via Digitalmars-d-learn
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma wrote: I wanted a D equivalent to: http://doc.qt.io/qt-5/qdatastream.html https://docs.python.org/3/library/pickle.html and saw that one is under construction: http://wiki.dlang.org/Review/std.serialization But till it's

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread John Colvin via Digitalmars-d-learn
On Thursday, 22 October 2015 at 15:10:58 UTC, pineapple wrote: On Thursday, 22 October 2015 at 14:36:52 UTC, John Colvin wrote: Using ranges instead of threads or fibers, slightly over-engineered to show off features: What does if(isIntegral!T) do? It looks like it would verify that the

D serialization temporary fixup?

2015-10-22 Thread Shriramana Sharma via Digitalmars-d-learn
I wanted a D equivalent to: http://doc.qt.io/qt-5/qdatastream.html https://docs.python.org/3/library/pickle.html and saw that one is under construction: http://wiki.dlang.org/Review/std.serialization But till it's finalized, I'd just like to have a quick but reliable way to store real and int

Re: D serialization temporary fixup?

2015-10-22 Thread John Colvin via Digitalmars-d-learn
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma wrote: I wanted a D equivalent to: http://doc.qt.io/qt-5/qdatastream.html https://docs.python.org/3/library/pickle.html and saw that one is under construction: http://wiki.dlang.org/Review/std.serialization But till it's