Re: How to make a Currency class from std.BigInt?

2015-01-31 Thread zeljkog via Digitalmars-d-learn
On 31.01.15 15:45, RuZzz wrote: Maybe I need good examples on C++, for this class, because a lot of examples on C++. Maybe this can help you: https://github.com/andersonpd/decimal

Re: How to make a Currency class from std.BigInt?

2015-01-31 Thread zeljkog via Digitalmars-d-learn
On 31.01.15 15:56, zeljkog wrote: On 31.01.15 15:45, RuZzz wrote: Maybe I need good examples on C++, for this class, because a lot of examples on C++. Maybe this can help you: https://github.com/andersonpd/decimal Also http://code.dlang.org/packages/eris

Re: Labels in struct

2015-01-31 Thread zeljkog via Digitalmars-d-learn
On 31.01.15 17:04, tcak wrote: I do not have a big example in the end to show, but is there any way to put labels into struct definitions? struct CommunicationMessage{ char[2] signature; mainData: int info1; int info2; extraData: ushort checksum; content: } Members of

Error: closures are not yet supported in CTFE

2015-01-23 Thread zeljkog via Digitalmars-d-learn
I tried: -- import std.stdio, std.algorithm; auto unique(){ bool[int] c; return (int a){ if (a in c) return false; else{ c[a] = true; return true; } }; } void main() { [1, 5, 5, 2, 1, 5, 6,

Re: Defining a static array with values in a range

2015-01-22 Thread zeljkog via Digitalmars-d-learn
On 22.01.15 20:05, Meta wrote: On Thursday, 22 January 2015 at 19:00:47 UTC, zeljkog wrote: On 22.01.15 19:26, Meta wrote: On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote: Whoops, I forgot to make it a template to force CTFE. You can force CTFE assigning to manifest constant. enum

Re: Defining a static array with values in a range

2015-01-22 Thread zeljkog via Digitalmars-d-learn
On 22.01.15 19:26, Meta wrote: On Thursday, 22 January 2015 at 18:23:00 UTC, Meta wrote: Whoops, I forgot to make it a template to force CTFE. You can force CTFE assigning to manifest constant. enum t = charRange!...

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread zeljkog via Digitalmars-d-learn
On 19.12.14 16:25, Steven Schveighoffer wrote: This is surprising to me. I would expect especially ints to be faster. In reality, there is no difference between arr ~= args and arr.length += args.length, and then copying, it's just how you do the copying. Perhaps it's the call to memcpy in the

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread zeljkog via Digitalmars-d-learn
On 19.12.14 23:56, Ali Çehreli wrote: Can we see the test code please. Ali import std.stdio, std.datetime, std.random; int N = 10_000; int len = 1000; int k = 4; struct S{ int n1, n2; //~ this(this){ //~ writeln(this(this)); //~ } } ref T[] append(T, Args...)(ref T[]

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread zeljkog via Digitalmars-d-learn
If you wish run this just add: struct S{ int n1, n2, n3, n4, n5 ...; }

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-18 Thread zeljkog via Digitalmars-d-learn
On 18.12.14 14:50, Steven Schveighoffer wrote: I wonder how your code compares to this: void append(T)(ref T[] arr, T[] args...) { arr ~= args; } This is ~20% slower for ints, but it difference increases for bigger structs.

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-17 Thread zeljkog via Digitalmars-d-learn
On 15.12.14 01:00, Nordlöw wrote: Isn't this algorithm already encoded somewhere in Phobos? void append(T, Args...)(ref T[] arr, auto ref Args args){ { static if (args.length == 1) arr ~= args[0]; // inlined else{ arr.length += args.length; foreach(i, e; args)

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-17 Thread zeljkog via Digitalmars-d-learn
On 17.12.14 13:30, Tobias Pankrath wrote: void append(T, Args...)(ref T[] data, Args args) { static size_t estimateLength(Args args) { size_t result; foreach(e; args) static if(hasLength!(typeof(e))) result += e.length; else

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread zeljkog via Digitalmars-d-learn
On 15.12.14 00:16, Nordlöw wrote: or some other trick? void append(T, Args...)(ref T[] arr, Args args){ arr.length += args.length; foreach(i, e; args) arr[$ - args.length + i] = args[i]; } void main() { int[] arr = [1, 2, 3, 4, 5]; arr.append(3, 10, 14); writeln(arr); } output:

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-14 Thread zeljkog via Digitalmars-d-learn
On 15.12.14 01:00, Nordlöw wrote: Isn't this algorithm already encoded somewhere in Phobos? I don't know.

fibers and ranges: what's wrong here?

2014-12-13 Thread zeljkog via Digitalmars-d-learn
import std.stdio, core.thread; struct Tree{ int val; Tree[] tree; } struct TreeRange{ Tree curtree; bool empty; Fiber worker; this(Tree t){ worker = new Fiber(fiberFunc); curtree = t; popFront(); } void fiberFunc(){ Tree t = curtree; Fiber.yield();

Re: fibers and ranges: what's wrong here?

2014-12-13 Thread zeljkog via Digitalmars-d-learn
On 13.12.14 13:01, zeljkog wrote: void main() { auto tt = Tree(5, [Tree(7,[Tree(11), Tree(4)]), Tree(10)]); auto tr1 = TreeRange(tt); foreach(v; tr1){ writef(%2d, , v); } writeln(); for(auto r = TreeRange(tt); !r.empty; r.popFront()) writef(%2d, , r.front);