Re: Speed of synchronized

2016-10-17 Thread Daniel Kozak via Digitalmars-d-learn
Dne 17.10.2016 v 23:40 Christian Köstlin via Digitalmars-d-learn napsal(a): Could someone check the numbers on another OS-X machine? Unfortunately I only have one available. Thanks in advance! Can you try it on OSX with ldc compiler: dub run --build=release --compiler=ldc

Re: Speed of synchronized

2016-10-17 Thread Daniel Kozak via Digitalmars-d-learn
Dne 16.10.2016 v 10:41 Christian Köstlin via Digitalmars-d-learn napsal(a): Hi, for an exercise I had to implement a thread safe counter. This is what I came up with: btw. I run the code with dub run --build=release Thanks in advance, Christian So I have done some testing, on my pc: Java

Re: Is this should work?

2016-10-17 Thread Daniel Kozak via Digitalmars-d-learn
Dne 17.10.2016 v 11:56 markov via Digitalmars-d-learn napsal(a): Thanks. So something like this would be helpful in core.thread? void startThread(alias fun, P...)(P p){ new Thread({fun(p);}).start(); } or without delegate import std.stdio; import core.thread; void fun(alias a, alias ms

Re: Speed of synchronized

2016-10-16 Thread Daniel Kozak via Digitalmars-d-learn
On Monday, 17 October 2016 at 06:38:08 UTC, Daniel Kozak wrote: Dne 17.10.2016 v 07:55 Christian Köstlin via Digitalmars-d-learn napsal(a): [...] I am still unable to get your java code working: [kozak@dajinka threads]$ ./gradlew clean build :clean :compileJava :processResources UP-TO-DATE

Re: Speed of synchronized

2016-10-16 Thread Daniel Kozak via Digitalmars-d-learn
Dne 17.10.2016 v 07:55 Christian Köstlin via Digitalmars-d-learn napsal(a): to run java call ./gradlew clean build -> counter.AtomicIntCounter@25992ae3 expected: 200 got: 100 in: 22ms counter.AtomicLongCounter@2539f946 expected: 200 got: 100 in: 17ms counter.ThreadSafe2Counter@52

Re: Speed of synchronized

2016-10-16 Thread Daniel Kozak via Digitalmars-d-learn
Dne 16.10.2016 v 10:41 Christian Köstlin via Digitalmars-d-learn napsal(a): My question now is, why is each mutex based thread safe variant so slow compared to a similar java program? The only hint could be something like: https://blogs.oracle.com/dave/entry/java_util_concurrent_reentrantlock_vs

Re: Building DMD with DMD or LDC

2016-10-14 Thread Daniel Kozak via Digitalmars-d-learn
Dne 14.10.2016 v 00:06 Nordlöw via Digitalmars-d-learn napsal(a): On Thursday, 13 October 2016 at 19:28:11 UTC, Daniel Kozak wrote: You can easy try it. Just build dmd with dmd, than with ldc. And then try to compile DMD frontend with both dmd versions :) Dne 13.10.2016 v 21:07 Nordlöw via

Re: Building DMD with DMD or LDC

2016-10-13 Thread Daniel Kozak via Digitalmars-d-learn
You can easy try it. Just build dmd with dmd, than with ldc. And then try to compile DMD frontend with both dmd versions :) Dne 13.10.2016 v 21:07 Nordlöw via Digitalmars-d-learn napsal(a): Is there a large speed difference in compilation time depending on whether the DMD used is built using D

Re: Easy sockets - don't exist yet?

2016-10-09 Thread Daniel Kozak via Digitalmars-d-learn
Dne 10.10.2016 v 03:43 Konstantin Kutsevalov via Digitalmars-d-learn napsal(a): On Monday, 26 September 2016 at 23:40:10 UTC, Vincent wrote: Hello, guys! I was very surprised that module 'socketstream' was deprecated. Usually if something become obsolete, there is some perfect replacement!

Re: How dub select versions?

2016-10-05 Thread Daniel Kozak via Digitalmars-d-learn
That makes sense :). Thanks Dne 5.10.2016 v 10:27 Mike Parker via Digitalmars-d-learn napsal(a): On Wednesday, 5 October 2016 at 08:23:25 UTC, Mike Parker wrote: The ~> constrains the dependency to the minor version number, meaning DUB will not try to use a version of the dependency that ha

How dub select versions?

2016-10-05 Thread Daniel Kozak via Digitalmars-d-learn
I really does not understand how does DUB works. I have small app which use vibe-d:core as dependency, and I use libasync as subConfiguration. When I try to build my app it always try to download libasync-0.7.9 instead of libasync-0.8.0. Why? I would expect to select the latest one frum dub rep

struct to json/yaml/xml/whatever codegen

2016-09-29 Thread Daniel N via Digitalmars-d-learn
Is anyone aware of a tool which does something akin to the following: Given a C-like definition, automatically generate pure C code with no dependencies. Input c-struct: struct Person { int id; char* name; } Output minimal c-code: void dumpPerson(Person* p) { prin

Re: bug?

2016-09-15 Thread Daniel Kozak via Digitalmars-d-learn
Dne 15.9.2016 v 15:57 rikki cattermole via Digitalmars-d-learn napsal(a): On 16/09/2016 1:54 AM, deed wrote: void main () { new int[](1); } Compiles with dmd 2.071.2-b2, but no code is generated for `new int[](1);`. Caused a bug due to: char[] arr; got updated to char[] arr; new char[](

Re: Mysql-native with LAMPP

2016-09-12 Thread Daniel Kozak via Digitalmars-d-learn
And are you sure it is using tcp4 socket on port 3306? You can use netstat -tlnp to see if is running on tcpv4 3306 Dne 12.9.2016 v 15:25 Geert via Digitalmars-d-learn napsal(a): On Monday, 12 September 2016 at 09:59:30 UTC, wobbles wrote: On Monday, 12 September 2016 at 05:31:46 UTC, Geert

Re: Removing array element in foreach, safe?

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
On Monday, 5 September 2016 at 17:38:10 UTC, Daniel Kozak wrote: On Monday, 5 September 2016 at 15:53:39 UTC, dom wrote: is this code safe? if not how do i do it correctly? static AsyncHttpGet[] openRequests; static void updateRequests() { foreach(idx

Re: Removing array element in foreach, safe?

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
On Monday, 5 September 2016 at 15:53:39 UTC, dom wrote: is this code safe? if not how do i do it correctly? static AsyncHttpGet[] openRequests; static void updateRequests() { foreach(idx, req; openRequests) { if(req.

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 14:30 Daniel Kozak napsal(a): Dne 5.9.2016 v 14:15 dom via Digitalmars-d-learn napsal(a): ... but what is the difference between a lambda (=>) and a functions/delegates? i think this is a major pitfall for newcomers, and should be adressed somehow. Yes, RTFM :) But to

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 14:15 dom via Digitalmars-d-learn napsal(a): ... but what is the difference between a lambda (=>) and a functions/delegates? i think this is a major pitfall for newcomers, and should be adressed somehow. Yes, RTFM :)

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 14:15 dom via Digitalmars-d-learn napsal(a): I am about to write my own stupid and simple http client .. and i have added a callback function that has the received content as a parameter. class AsyncHttpGet { this(string host, ushort port, string path, void delegate(string)

Re: Custom String vs D String performance

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
gc at all, so no "new" for me. Yes the optimal case will be reserve the memory beforehand, but i´m benchmarking the opBinary. So now a bit better example :) https://dpaste.dzfl.pl/b9356f57a8c8 Daniel Kozak: Ok, now it gets a bit weird. On DPaste it shows: 14 ms and 343 μs - DString 3 ms

Re: Custom String vs D String performance

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 13:20 rikki cattermole via Digitalmars-d-learn napsal(a): ... Don't forget to disable the GC as well so it doesn't try to collect during the tests. This is not true, in many cases it will hurt performance a lot

Re: Custom String vs D String performance

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 13:17 Daniel Kozak napsal(a): Dne 5.9.2016 v 13:11 Patric via Digitalmars-d-learn napsal(a): I´m playing remaking D functionalities with nogc structs, and to at least match D performance. But in this particular case i´m unable to get near D performance. Can someone point me

Re: Custom String vs D String performance

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 13:11 Patric via Digitalmars-d-learn napsal(a): I´m playing remaking D functionalities with nogc structs, and to at least match D performance. But in this particular case i´m unable to get near D performance. Can someone point me out what i´m doing wrong, or if there is some mag

Re: Fast multidimensional Arrays

2016-08-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne 29.8.2016 v 16:43 Steinhagelvoll via Digitalmars-d-learn napsal(a): On Monday, 29 August 2016 at 13:59:15 UTC, Daniel Kozak wrote: Dne 29.8.2016 v 11:53 Steinhagelvoll via Digitalmars-d-learn napsal(a): [...] It is unfair to compare different backend: gfortran -O3 -o test test.f90

Re: Fast multidimensional Arrays

2016-08-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne 29.8.2016 v 16:21 Stefan Koch via Digitalmars-d-learn napsal(a): On Monday, 29 August 2016 at 09:53:12 UTC, Steinhagelvoll wrote: Hello, I'm trying to find a fast way to use multi dimensional arrays. For this I implemented a matrix multiplication and compared the times for different ways

Re: Fast multidimensional Arrays

2016-08-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne 29.8.2016 v 16:08 rikki cattermole via Digitalmars-d-learn napsal(a): Okay looks like I've made a boo boo and ldc is compiling out that entire multiplication loop out. Its passing the array statically and since its never assigned back, its just never compiled in (unless you specify it via

Re: Fast multidimensional Arrays

2016-08-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne 29.8.2016 v 15:57 rikki cattermole via Digitalmars-d-learn napsal(a): My bad, fixed: double[1000][] A, B, C; void main() { A = new double[1000][1000]; B = new double[1000][1000]; C = new double[1000][1000]; import std.conv : to; import std.datetime;

Re: Fast multidimensional Arrays

2016-08-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne 29.8.2016 v 11:53 Steinhagelvoll via Digitalmars-d-learn napsal(a): Hello, I'm trying to find a fast way to use multi dimensional arrays. For this I implemented a matrix multiplication and compared the times for different ways. As a reference I used a Fortran90 implementation. Fortran r

Re: Fast multidimensional Arrays

2016-08-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne 29.8.2016 v 14:13 Steinhagelvoll via Digitalmars-d-learn napsal(a): Ok I added release and implemented the benchmark for 500 iterations, 1 are not reasonable. I build on the 2d array with LDC: http://pastebin.com/aXxzEdS4 (changes just in the beginning) $ ldc2 -release -O3 nd_test.d $

Re: Does D have any construct like Python's with keyword?

2016-08-27 Thread Daniel Kozak via Digitalmars-d-learn
Dne 27.8.2016 v 02:04 pineapple via Digitalmars-d-learn napsal(a): I would just love if I could express this as something more like context(auto file = File("some_file.txt")){ file.write(); } void main(string[] args) { with(File("some_file.txt")) { write();

Re: copy a JSONValue

2016-08-26 Thread Daniel Kozak via Digitalmars-d-learn
On Friday, 26 August 2016 at 06:56:06 UTC, Alex wrote: Hi everybody, I'm little at loss: as documented, a JSONValue is only shallow copied: ... So the effect that the code of "j" is altered was expected. The question is: how to make a deep copy of a JSONValue? Is there a simple way without

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-26 Thread Daniel Kozak via Digitalmars-d-learn
Dne 26.8.2016 v 09:12 magicdmer via Digitalmars-d-learn napsal(a): On Friday, 26 August 2016 at 07:00:37 UTC, rikki cattermole wrote: Okay so your Windows language is non-english, that'll be it. You need to be looking into the encoding that Visual Studio is using for you files. Something to do

Re: copy a JSONValue

2016-08-26 Thread Daniel Kozak via Digitalmars-d-learn
Dne 26.8.2016 v 08:56 Alex via Digitalmars-d-learn napsal(a): void main() { import std.json; import std.stdio; string s = "{ \"language\": \"D\", \"rating\": 3.14, \"code\": 42 }"; JSONValue j = parseJSON(s); writeln("code: ", j["code"].integer); auto j2 = j; j2["c

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-26 Thread Daniel Kozak via Digitalmars-d-learn
Dne 26.8.2016 v 08:52 magicdmer via Digitalmars-d-learn napsal(a): On Friday, 26 August 2016 at 06:38:01 UTC, Daniel Kozak wrote: That image is too small, so I can't see it :) Dne 26.8.2016 v 08:26 magicdmer via Digitalmars-d-learn napsal(a): I use VisualD create a windows dll project

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-25 Thread Daniel Kozak via Digitalmars-d-learn
That image is too small, so I can't see it :) Dne 26.8.2016 v 08:26 magicdmer via Digitalmars-d-learn napsal(a): I use VisualD create a windows dll project , and select the "Use MS-COFF object file fromat for win32" . when i build it ,it display the error follow ,look at the picture I use dmd

Re: nested enum

2016-08-25 Thread Daniel Kozak via Digitalmars-d-learn
Btw, tehre is no need for extra semicolon (`;`) after enum and struct definition Dne 25.8.2016 v 12:23 Cauterite via Digitalmars-d-learn napsal(a): On Wednesday, 24 August 2016 at 23:04:25 UTC, Illuminati wrote: Well those other answers aren't wrong, but I envisioned that you'd have multi

Re: nested enum

2016-08-24 Thread Daniel Kozak via Digitalmars-d-learn
And if you need more levels: struct MyEnum { static struct AnotherEnum { enum X { Y = 10, Z = 20 } } } void main() { import std.stdio; int y = MyEnum.AnotherEnum.X.Y; writeln(y); } Dne 25.8.2016 v 03:37 Mike Parker via Digitalmars-d-learn napsal(a): On Wednesday

Re: Speed up `dub`.

2016-06-02 Thread Daniel Kozak via Digitalmars-d-learn
I am not sure but on Arch linux I always recompile dub myself because by default it is build without release flags too. Dne 2.6.2016 v 15:07 ciechowoj via Digitalmars-d-learn napsal(a): Maybe it would be worth to write something about the issue here https://github.com/dlang/dub#installation .

Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Daniel Kozak via Digitalmars-d-learn
Why not to use distribute oprion? Dne 27. 5. 2016 17:35 napsal uživatel "yawniek via Digitalmars-d-learn" < digitalmars-d-learn@puremagic.com>: > On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote: > >> Hi guys, >> >> In my journey of learning about D I tried to benchmark D with Vibe.d vs >> nod

Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Daniel Kozak via Digitalmars-d-learn
On Friday, 27 May 2016 at 14:18:31 UTC, llaine wrote: On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote: On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote: I am doing something wrong ? So, the benchmark, the Ruby, and the JS all use the path to be / the D seems to use /compa

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

2016-05-24 Thread Daniel Kozak via Digitalmars-d-learn
Dne 24.5.2016 v 17:27 llaine via Digitalmars-d-learn napsal(a): Hi everybody, 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 sev

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-22 Thread Daniel N via Digitalmars-d-learn
On Saturday, 21 May 2016 at 17:32:47 UTC, dan wrote: Is it possible to have a class which has a variable which can be seen from the outside, but which can only be modified from the inside? Something like: class C { int my_var = 3; // semi_const?? void do_something() { my_var = 4; } }

Re: Is this template constraint a bug?

2016-05-12 Thread Daniel N via Digitalmars-d-learn
On Thursday, 12 May 2016 at 15:33:24 UTC, Eric wrote: is(T : A!T) tells if T can automatically be converted to A!T. The last line below is doing just that, yet the template constraint does not work. class A(T) if (is(T : A!T)) { } Yes, it's a bug. Please file an issue. Meanwhile try thi

Re: static import (v2.071.0)

2016-05-11 Thread Daniel Kozak via Digitalmars-d-learn
Dne středa 11. května 2016 16:32:18 CEST, Chris via Digitalmars-d-learn napsal(a): On Wednesday, 11 May 2016 at 14:28:00 UTC, Vladimir Panteleev wrote: On Wednesday, 11 May 2016 at 14:26:37 UTC, Vladimir Panteleev wrote: ... Hm. What's the point then of using import std.string : strip; as

Re: Parallel implementation of map

2016-05-11 Thread Daniel Kozak via Digitalmars-d-learn
Dne středa 11. května 2016 13:25:50 CEST, VlasovRoman via Digitalmars-d-learn napsal(a): Hey, guys! After many attempts pmap function was realized by me. This is analogous to taskPool.amap function, but I do not know how much he is good. In simple tests, it showed a corresponding accelerati

Re: Issue with 2.071: Regression or valid error?

2016-04-08 Thread Daniel Kozak via Digitalmars-d-learn
Dne 8.4.2016 v 14:56 Steven Schveighoffer via Digitalmars-d-learn napsal(a): On 4/8/16 2:08 AM, 9il wrote: On Thursday, 7 April 2016 at 15:55:16 UTC, Steven Schveighoffer wrote: On 4/6/16 11:10 AM, Andre wrote: [...] Just FYI, you don't need a semicolon there. [...] Wow, totally agree

Re: Issue with 2.071: Regression or valid error?

2016-04-08 Thread Daniel Kozak via Digitalmars-d-learn
On Friday, 8 April 2016 at 06:08:38 UTC, 9il wrote: On Thursday, 7 April 2016 at 15:55:16 UTC, Steven Schveighoffer wrote: On 4/6/16 11:10 AM, Andre wrote: [...] Just FYI, you don't need a semicolon there. [...] Wow, totally agree with you. Compiler shouldn't make you jump through this h

Re: Issue with 2.071: Regression or valid error?

2016-04-06 Thread Daniel Kozak via Digitalmars-d-learn
This should not compile. Cat cant access create because it is private. Ok it can access it but only if you move cat into same module as animal Dne 6. 4. 2016 17:16 napsal uživatel "Andre via Digitalmars-d-learn" < digitalmars-d-learn@puremagic.com>: > Hi, > > With 2.071 following coding does not c

Re: What can _not_ be marked pure?

2016-03-09 Thread Daniel Kozak via Digitalmars-d-learn
Dne 9.3.2016 v 11:26 Guillaume Piolat via Digitalmars-d-learn napsal(a): On Wednesday, 9 March 2016 at 10:08:33 UTC, ag0aep6g wrote: On 09.03.2016 10:56, Guillaume Piolat wrote: If I understand purity correctly (http://klickverbot.at/blog/2012/05/purity-in-d/), every function out there can be

Re: Speed up `dub`.

2016-03-07 Thread Daniel Kozak via Digitalmars-d-learn
I would say dub is broken and should be fixed. Even dub run is really slow and try to build everything. So please report a bug: https://github.com/D-Programming-Language/dub/issues Dne 7.3.2016 v 19:58 ciechowoj via Digitalmars-d-learn napsal(a): dub --version DUB version 0.9.24+161-gb9ce700,

Re: Speed up `dub`.

2016-03-07 Thread Daniel Kozak via Digitalmars-d-learn
maybe: dub build --nodeps Dne 7.3.2016 v 10:18 ciechowoj via Digitalmars-d-learn napsal(a): I'm using `dub` to build project. And every time I run `dub` it seems to check if dependencies are up to date, which takes some time. Is there a way to switch of that checking? Or any other way to speed

Re: Unable to instantiate template with same name as function

2016-03-03 Thread Daniel Kozak via Digitalmars-d-learn
Dne 3.3.2016 v 09:58 Shriramana Sharma via Digitalmars-d-learn napsal(a): Hello people and thanks for your replies. Jonathan M Davis via Digitalmars-d-learn wrote: You can't overload a function and an eponymous template like that. They need to have distinct names. Why is it not possible for

Re: Unable to instantiate template with same name as function

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
Dne 3.3.2016 v 07:12 Shriramana Sharma via Digitalmars-d-learn napsal(a): Hello. I have a function I want to make CTFE-able as a template. string ta(string s) { return s ~ "1"; } template ta(string s) { enum ta = ta(s); } void main() { string s = ta!"s"; } Compiling the above I get the errors

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
Dne 2.3.2016 v 21:39 Adam D. Ruppe via Digitalmars-d-learn napsal(a): On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: Is it by design or is it a bug? And, if it is by design, what is the reason for that? That's by design. It allows you to override names from a template mixi

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 14:50:15 UTC, Adrian Matoga wrote: On Wednesday, 2 March 2016 at 14:36:59 UTC, Daniel Kozak wrote: OK maybe this one: template AddField(T) { T b; this(Args...)(T b, auto ref Args args) { this.b = b; this(args); } this(int a

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 13:18:23 UTC, Adrian Matoga wrote: On Wednesday, 2 March 2016 at 12:48:47 UTC, Daniel Kozak wrote: On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: (...) You can use string mixins: template AddField(T) { enum AddField = T.stringof ~ ` b

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: I can do this: struct Foo { int a; string b; this(int a) { this.a = a; } this(Args...)(string b, auto ref Args args) { this.b = b; this(args); } } unittest { auto foo1 = Foo(5); auto foo2

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: I can do this: struct Foo { int a; string b; this(int a) { this.a = a; } this(Args...)(string b, auto ref Args args) { this.b = b; this(args); } } unittest { auto foo1 = Foo(5); auto foo2

Re: Where to go after "Programming in D"

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 19:59:19 UTC, Ali Çehreli wrote: On 03/01/2016 08:50 AM, karabuta wrote: I am almost done with the "programming in D" book. Where will you suggest a go from there. Like others said, I would spend time on Phobos to become familiar with it; there are many gems in th

Re: Combining template conditions and contracts?

2016-02-29 Thread Daniel Kozak via Digitalmars-d-learn
auto square_root(T)(T x) if (isBasicType!T) in { assert(x >= 0); } out (result) { assert((result * result) <= x && (result+1) * (result+1) > x); } body { return cast(long)std.math.sqrt(cast(real)x); } void main() { import std.stdio: writeln; writeln(square_root(2)); } Dne 29.

Re: Combining template conditions and contracts?

2016-02-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne 29.2.2016 v 15:38 Ozan via Digitalmars-d-learn napsal(a): T square_root(T)(T x) if (isBasicType!T) { in { assert(x >= 0); } out (result) { assert((result * result) <= x && (result+1) * (result+1) > x); } body { return cast(long)std.math.sqrt(cast(real)x); } import std.trait

Re: template mixins vs alias

2016-02-22 Thread Daniel Kozak via Digitalmars-d-learn
In your case I would guess with -O -release -inline it would generate assambly with same (similar) speed. But in this case it would be different: mixin template Test() { int returnInit() { return int.init; } } int returnInitImpl() { return int.init; } class A { mixin Test!(); // add

Re: Simple performance question from a newcomer

2016-02-21 Thread Daniel Kozak via Digitalmars-d-learn
So I guess pairwise summation is one to blame here. Dne 21.2.2016 v 16:56 Daniel Kozak napsal(a): You can use -profile to see what is causing it. Num TreeFuncPer CallsTimeTimeCall 2300 550799875 550243765 23 pure

Re: Simple performance question from a newcomer

2016-02-21 Thread Daniel Kozak via Digitalmars-d-learn
You can use -profile to see what is causing it. Num TreeFuncPer CallsTimeTimeCall 2300 550799875 550243765 23 pure nothrow @nogc @safe double std.algorithm.iteration.sumPairwise!(double, std.experimental.ndslice.slice.Sl

Re: Printing a C "string" with write(f)ln

2016-02-09 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 16:58:03 UTC, Daniel Kozak wrote: On Tuesday, 9 February 2016 at 16:52:09 UTC, Gary Willoughby wrote: On Tuesday, 9 February 2016 at 12:50:27 UTC, Jakob Ovrum wrote: writefln et al sensibly does *not* assume that a pointer to char is a C string, for memory safety

Re: Printing a C "string" with write(f)ln

2016-02-09 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 16:52:09 UTC, Gary Willoughby wrote: On Tuesday, 9 February 2016 at 12:50:27 UTC, Jakob Ovrum wrote: writefln et al sensibly does *not* assume that a pointer to char is a C string, for memory safety purposes. Print the result of std.string.fromStringz[1] instead:

Re: std.concurrency: ownerTid vs thisTid

2016-02-09 Thread Daniel Kozak via Digitalmars-d-learn
https://github.com/D-Programming-Language/phobos/blob/v2.070.0/std/concurrency.d#L340 formattedWrite(sink, "Tid(%x)", &mbox); should be: formattedWrite(sink, "Tid(%x)", cast(void *)mbox); On Tue, Feb 9, 2016 at 5:25 PM, Daniel Kozak wrote: > You are right: > imp

Re: std.concurrency: ownerTid vs thisTid

2016-02-09 Thread Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com> wrote: > On 02/09/2016 07:52 AM, Daniel Kozak via Digitalmars-d-learn wrote: > >> It is OK, I guess the output is just mixed >> > > Yes, that's an important point but it is not the reason. (Just tested.) > > I think thi

Re: std.concurrency: ownerTid vs thisTid

2016-02-09 Thread Daniel Kozak via Digitalmars-d-learn
OK it seems wierd On Tue, Feb 9, 2016 at 4:52 PM, Daniel Kozak wrote: > It is OK, I guess the output is just mixed > > On Tue, Feb 9, 2016 at 4:35 PM, miazo via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > >> Hi, >> >> The following

Re: std.concurrency: ownerTid vs thisTid

2016-02-09 Thread Daniel Kozak via Digitalmars-d-learn
It is OK, I guess the output is just mixed On Tue, Feb 9, 2016 at 4:35 PM, miazo via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Hi, > > The following simple program: > > import std.stdio, std.concurrency; > > void f1() { > writeln("owner: ", ownerTid); > writeln("wo

Re: Printing a C "string" with write(f)ln

2016-02-09 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 09 Feb 2016 12:46:59 + Whirlpool via Digitalmars-d-learn napsáno: > Hello, > > When you are using a C function (from an external library) that > returns a pointer on char which is the beginning of a string (I > know that C does not have a string type, that they are just > arrays of

Re: How to warn of unused imports?

2016-02-08 Thread Daniel Kozak via Digitalmars-d-learn
V Mon, 08 Feb 2016 08:25:09 + cy via Digitalmars-d-learn napsáno: > When I factor out code from my modules, it really, really often > leaves import statements that just sit there doing nothing, > making it look like my program is more complex than it is. How do > I get warned for leaving t

Re: Odd Destructor Behavior

2016-02-07 Thread Daniel Kozak via Digitalmars-d-learn
V Sun, 07 Feb 2016 23:47:39 + Matt Elkins via Digitalmars-d-learn napsáno: > On Sunday, 7 February 2016 at 23:11:34 UTC, anonymous wrote: > > On 07.02.2016 23:49, Matt Elkins wrote: > >> Oi. Yes, I can, but it is quite a lot of code even if you > >> don't count > >> that it is dependent on

Re: What reasons are known a thread stops suddenly?

2016-02-04 Thread Daniel Kozak via Digitalmars-d-learn
V Fri, 05 Feb 2016 03:47:40 + tcak via Digitalmars-d-learn napsáno: > On Thursday, 4 February 2016 at 22:27:31 UTC, Ali Çehreli wrote: > > On 02/04/2016 12:25 PM, tcak wrote: > > > > > void threadFunc(){ > > > scope(exit){ > > > writeln("Leaving 2: ", stopRequested); > > >

Re: What reasons are known a thread stops suddenly?

2016-02-04 Thread Daniel Kozak via Digitalmars-d-learn
V Fri, 05 Feb 2016 05:48:27 + tcak via Digitalmars-d-learn napsáno: > On Friday, 5 February 2016 at 03:47:40 UTC, tcak wrote: > > On Thursday, 4 February 2016 at 22:27:31 UTC, Ali Çehreli wrote: > >> On 02/04/2016 12:25 PM, tcak wrote: > >> > >> > [...] > >> > >> That would happen when

Re: Switch with dynamic case

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 15:01:57 UTC, anonymous wrote: On 02.02.2016 15:07, Daniel Kozak wrote: [...] The key thing to understand is that the foreach is a "static" one. A static foreach is unrolled at compile-time. [...] Thanks :), this is all I need to know

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:47:43 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 14:12:54 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issues.dlang.org/show_bug.cgi?id=15640 I would say it is not a bug te

Switch with dynamic case

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
import std.stdio; import std.typetuple : TypeTuple; alias cs = TypeTuple!(0, 1, 2, 3); void main(string[] argv) { switch(argv.length) { default: writeln("Uknown number of args"); break; foreach(c; cs) { case c: writefln("%s args", c); break

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:20:33 UTC, Voitech wrote: Hi, Is it possible to bound T... in template with some type ? For single Parameter declaration it can be done by T:SomeType but variadics does not seems to have that possibility ? Cheers import std.stdio; import std.meta: allSatisfy;

Re: How to set array length for multidimensional static arrays

2016-02-01 Thread Daniel Kozak via Digitalmars-d-learn
V Mon, 01 Feb 2016 12:19:10 + Namal via Digitalmars-d-learn napsáno: > On Monday, 1 February 2016 at 12:12:00 UTC, Jonathan M Davis > wrote: > > On Monday, February 01, 2016 11:15:40 Namal via > > Digitalmars-d-learn wrote: > >> Sorry guys that I didn't express myself well. I also mixed

Re: How to set array length for multidimensional static arrays

2016-02-01 Thread Daniel Kozak via Digitalmars-d-learn
V Mon, 01 Feb 2016 11:15:40 + Namal via Digitalmars-d-learn napsáno: > Sorry guys that I didn't express myself well. I also mixed some > stuff up. What I wanted to ask is this, in c++ this is valid > > int x = 3; > int y = 10; > int arr [x][y]; > > x,y are known at the co

Re: free causes exception

2016-01-26 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 26 Jan 2016 15:24:00 + Igor via Digitalmars-d-learn napsáno: > On Tuesday, 26 January 2016 at 14:48:48 UTC, Daniel Kozak wrote: > > V Tue, 26 Jan 2016 14:20:29 + > > Igor via Digitalmars-d-learn > > napsáno: > > > >> [...] > >

Re: free causes exception

2016-01-26 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 26 Jan 2016 14:20:29 + Igor via Digitalmars-d-learn napsáno: > I have successfully malloc'ed an object but when I go to free it > in the destructor I get an exception. The destructor simply has > > ~this() // destructor for Foo > { > core.stdc.stdlib.free(&this); > } > > > aut

Re: how to allocate class without gc?

2016-01-26 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 26 Jan 2016 13:56:39 + Igor via Digitalmars-d-learn napsáno: > On Tuesday, 26 January 2016 at 09:32:06 UTC, Daniel Kozak wrote: > > V Tue, 26 Jan 2016 05:47:42 + > > Igor via Digitalmars-d-learn > > napsáno: > > > >> On Tuesday, 26 Janua

Re: how to allocate class without gc?

2016-01-26 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 26 Jan 2016 05:47:42 + Igor via Digitalmars-d-learn napsáno: > On Tuesday, 26 January 2016 at 05:11:54 UTC, Mike Parker wrote: > > On Tuesday, 26 January 2016 at 01:09:50 UTC, Igor wrote: > >> Is there any examples that shows how to properly allocate an > >> object of a class type w

Re: Function accepting variadic arguments

2016-01-20 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 13:09:13 UTC, Daniel Kozak wrote: On Wednesday, 20 January 2016 at 13:06:14 UTC, pineapple wrote: On Wednesday, 20 January 2016 at 12:56:51 UTC, Ali Çehreli wrote: And there is another example here: http://ddili.org/ders/d.en/templates_more.html

Re: Function accepting variadic arguments

2016-01-20 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 13:06:14 UTC, pineapple wrote: On Wednesday, 20 January 2016 at 12:56:51 UTC, Ali Çehreli wrote: And there is another example here: http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.tuple%20template%20parameter Ali Thank you! What's the purpo

Re: Function accepting variadic arguments

2016-01-20 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 13:04:23 UTC, Daniel Kozak wrote: V Wed, 20 Jan 2016 12:38:20 + pineapple via Digitalmars-d-learn napsáno: import std.stdio; struct S { this(Args...)(Args args) { foreach(Type, Value;args) { writefln("Type: %s

Re: Function accepting variadic arguments

2016-01-20 Thread Daniel Kozak via Digitalmars-d-learn
V Wed, 20 Jan 2016 12:38:20 + pineapple via Digitalmars-d-learn napsáno: > I'd like to make a constructor which takes a variable list of > arguments, of a short list of possible types, with different > handling depending on the type. I haven't been able to find any > documentation or examp

Re: Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Daniel Kozak via Digitalmars-d-learn
Soviet Friend píše v Út 19. 01. 2016 v 22:12 +: > I just attempted to add one ubyte to another and store the result  > in a ubyte but apparently ubytes get converted to ints when being  > added... and converting what becomes an int becomes impossible to  > store in a ubyte without an explicit c

Re: Regression vs Bug

2016-01-14 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 14 Jan 2016 17:32:47 + NX via Digitalmars-d-learn napsáno: > Please explain. Regression: something works before does not work anymore Bug: something does not work as expected (regression is one type of bug)

Re: mixed-in ctor not on par with explicit one?

2016-01-13 Thread Daniel N via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 12:39:36 UTC, Jacob Carlborg wrote: On 2016-01-13 10:48, Shriramana Sharma wrote: This is not what alias <> this is supposed to do, right? No. So how am I supposed to get the mixed in ctors work? Looks like a limitation in the language. This works: mixi

Re: How to declare an alias to a function literal type

2016-01-12 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 12 Jan 2016 15:41:02 + ParticlePeter via Digitalmars-d-learn napsáno: > I have a function type and variable and assign a function to it: > > void function( int i ) myFunc; > myFunc = void function( int i ) { myCode; } > > How would I declare an alias for void function( int i ) such t

Re: vibe / how to use the Win32EventDriver ?

2016-01-07 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 7 Jan 2016 16:35:24 +0100 "Robert M. Münch via Digitalmars-d-learn" napsáno: > When I build for Windows, it seems that the "libevent" driver is > used. I can see that there is a "Win32EventDriver" which setups a GUI > message loop as well. How can I use this driver instead of the > "libeve

Re: CTFE with C functions not possible?

2015-12-31 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 31 December 2015 at 11:52:01 UTC, Shriramana Sharma wrote: Using DMD 2.0.69.2, the following code: extern (C) double sqrt(double x); enum q = sqrt(4.0); gives the error: Error: sqrt cannot be interpreted at compile time, because it has no available source code But if I do: imp

Re: DUB problems

2015-12-31 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 31 Dec 2015 22:23:43 +1300 Rikki Cattermole via Digitalmars-d-learn napsáno: > On 31/12/15 10:17 PM, Daniel Kozak via Digitalmars-d-learn wrote: > > V Thu, 31 Dec 2015 09:09:20 + > > yawniek via Digitalmars-d-learn > > napsáno: > > > >> On Thursd

Re: DUB problems

2015-12-31 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 31 Dec 2015 09:09:20 + yawniek via Digitalmars-d-learn napsáno: > On Thursday, 31 December 2015 at 08:51:42 UTC, Daniel Kozak wrote: > > I try to build vibe-d Hello world app with dub, but I have many > > problems with dub, nothing works at all > > > > E

Re: DUB problems

2015-12-31 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 31 Dec 2015 09:09:20 + yawniek via Digitalmars-d-learn napsáno: > On Thursday, 31 December 2015 at 08:51:42 UTC, Daniel Kozak wrote: > > I try to build vibe-d Hello world app with dub, but I have many > > problems with dub, nothing works at all > > > > E

DUB problems

2015-12-31 Thread Daniel Kozak via Digitalmars-d-learn
I try to build vibe-d Hello world app with dub, but I have many problems with dub, nothing works at all Error: Output file 'client.o' for module 'vibe.http.client' collides with previous module 'vibe.db.mongo.client'. See the -oq option and allmost nothing works as expected. How can I do one

<    1   2   3   4   5   6   7   8   9   10   >