Re: question on map

2021-05-12 Thread visitor via Digitalmars-d-learn
On Wednesday, 12 May 2021 at 09:52:52 UTC, Alain De Vos wrote: As oppposed to what i expect code below prints nothing nothing on the screen. What is wrong and how to fix it ? ``` import std.stdio; import std.range:iota; import std.algorithm:map; bool mywriteln(int x){ writeln(x);

Re: rgba.ptr[0] vs rgba[0]

2020-11-23 Thread visitor via Digitalmars-d-learn
On Monday, 23 November 2020 at 17:39:09 UTC, Adam D. Ruppe wrote: On Monday, 23 November 2020 at 17:34:27 UTC, visitor wrote: Hi all, I would like to know why in the code below, rgba.ptr[0] is used instead of rgba[0] and allowing the method to be @safe The .ptr[0] skips bounds checking.

rgba.ptr[0] vs rgba[0]

2020-11-23 Thread visitor via Digitalmars-d-learn
Hi all, I would like to know why in the code below, rgba.ptr[0] is used instead of rgba[0] and allowing the method to be @safe float[4] rgba = 0; ref inout(float) r() inout pure @trusted { pragma(inline, true); return rgba.ptr[0]; } why not : ref inout(float) r() inout pure @safe {

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
https://run.dlang.io/is/xiqi4P not pretty :)) but ...

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
On Wednesday, 9 September 2020 at 17:02:26 UTC, visitor wrote: On Friday, 14 February 2020 at 06:41:02 UTC, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); static foreach (idx, field; A) { static if (__traits(compiles, THREELOOP)) {} else { static if (field == 3) {

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
On Friday, 14 February 2020 at 06:41:02 UTC, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); static foreach (idx, field; A) { static if (__traits(compiles, THREELOOP)) {} else { static if (field == 3) { pragma(msg, "Got a 3!"); enum

Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread visitor via Digitalmars-d-learn
On Friday, 16 March 2018 at 20:19:59 UTC, aberba wrote: On Friday, 16 March 2018 at 17:11:17 UTC, visitor wrote: On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote: I creating one simple desktop application using dlang. I need to display some html file in my desktop application. How can

Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread visitor via Digitalmars-d-learn
On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote: I creating one simple desktop application using dlang. I need to display some html file in my desktop application. How can make it works ? There's also gtkd sourceview :

Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread visitor via Digitalmars-d-learn
On Sunday, 4 March 2018 at 19:53:59 UTC, ag0aep6g wrote: On 03/04/2018 08:45 PM, ag0aep6g wrote: I don't know what's going on here. The error message doesn't make sense to me. Might be a bug in the compiler. This one works: struct Stack(T) { T[] stack; alias stack this; bool

Re: How to concatenate a tuple of strings at compile time?

2018-01-06 Thread visitor via Digitalmars-d-learn
On Saturday, 6 January 2018 at 19:35:33 UTC, paul wrote: Hi! How to concatenate a tuple of strings at compile time? Something like that maybe ? import std.stdio; import std.meta; enum connected = () { auto something = AliasSeq!("one", "two", "three"); string res = ""; static

Re: Putting function pointers / delegates into associative array.

2018-01-03 Thread visitor via Digitalmars-d-learn
On Thursday, 4 January 2018 at 01:40:21 UTC, Mark wrote: What I'm trying to do here is to be able to call a function based off of a key. class tester { private void delegate() [char] funcs; this() { funcs = ['a': , 'b': ]; } public void

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 21:35:18 UTC, visitor wrote: On Monday, 25 December 2017 at 21:11:08 UTC, aliak wrote: On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote: On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote:

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 21:11:08 UTC, aliak wrote: On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote: On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: I was kind of hoping for some magical D variadic alias

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote: On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: I was kind of hoping for some magical D variadic alias template on Tuple or something that will just deconstruct the

Re: Converting array in to aliased tuple type.

2017-12-25 Thread visitor via Digitalmars-d-learn
On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote: On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote: I was kind of hoping for some magical D variadic alias template on Tuple or something that will just deconstruct the arguments in to tuple components. i don't think it's

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread visitor via Digitalmars-d-learn
On Thursday, 15 December 2016 at 17:44:23 UTC, David Zhang wrote: would something like this be a solution ? import std.stdio; import std.experimental.allocator; class SomeClass { int someint = 42; static SomeClass opCall(int a) { auto inst = theAllocator.make!SomeClass;

Re: functional way doing array stuff/ lambda functions

2015-12-14 Thread visitor via Digitalmars-d-learn
On Monday, 14 December 2015 at 11:45:50 UTC, Namal wrote: foreach(k;1..11){ auto t = prim_factors(k,P); v~= [k,product(t)]; } it crashes because your first t in the loop is an empty array because 1 is not a prime ( in "prim_sieve" :

Re: functional way doing array stuff/ lambda functions

2015-12-13 Thread visitor via Digitalmars-d-learn
On Sunday, 13 December 2015 at 03:08:33 UTC, Namal wrote: This works for me : import std.stdio, std.algorithm, std.range; int[] prim_factors(int n, const int[] P) { int[] v; P.filter!( x => x*x <= n).each!( (i) { while (n % i == 0) { v ~= i; n /= i;

Re: benchmark on binary trees

2015-12-11 Thread visitor via Digitalmars-d-learn
ok, i have a working version (memory is nice, twice the speed as non parallel) ; http://dpaste.dzfl.pl/504a652c6c47 real0m14.427s user1m19.347s sys 0m0.124s i've got similar performances, without Allocators, using directly malloc and free i had to recursively deallocate ...

Re: benchmark on binary trees

2015-12-09 Thread visitor via Digitalmars-d-learn
version with apr (like in c version) http://dpaste.dzfl.pl/68c0157225e7 compiled with ldc it's indeed a bit faster on average : real0m1.999s user0m9.810s sys 0m0.148 btw Rust version is even faster than my little bit outdated gcc (4.9) latest try with allocators :

Re: benchmark on binary trees

2015-12-08 Thread visitor via Digitalmars-d-learn
using Apache Portable Runtime(APR) like in the C version : http://dpaste.dzfl.pl/6ca8b5ffd6dc works like a charm, 2.061s on my machine ! if file name is binarytrees.d dmd -w -inline -O -release -I/usr/include/apr-1.0 -L/usr/lib/x86_64-linux-gnu/libapr-1.so -of"binarytrees" "binarytrees.d"

Re: benchmark on binary trees

2015-12-08 Thread visitor via Digitalmars-d-learn
C++ version : real0m3.587s user0m9.211s sys 0m7.341s

Re: benchmark on binary trees

2015-12-07 Thread visitor via Digitalmars-d-learn
On Monday, 7 December 2015 at 10:55:25 UTC, Alex wrote: On Sunday, 6 December 2015 at 12:23:52 UTC, visitor wrote: Hello, interesting exercise for me to learn about allocators :-) Nice to know, a novice can inspire someone :) i managed to parallelize the code reaching similar performance, in

Re: benchmark on binary trees

2015-12-06 Thread visitor via Digitalmars-d-learn
On Sunday, 6 December 2015 at 08:35:33 UTC, Alex wrote: Thanks for commenting to everyone! If anybody has further ideas - all of them would be appreciated :) The original site is not interested in any further languages to be tested, so my experiment ends here for now... Hello, interesting

Re: Pixelbuffer to draw on a surface

2015-12-06 Thread visitor via Digitalmars-d-learn
gtkd demos for examples, might be of interest, like clock : https://github.com/gtkd-developers/GtkD/blob/master/demos/cairo/cairo_clock/clock.d

Re: having problem with `std.algorithm.each`

2015-11-30 Thread visitor via Digitalmars-d-learn
On Monday, 30 November 2015 at 09:56:08 UTC, ref2401 wrote: DMD 2.069.1 OS Win8.1 Enterprise in a multiline statement, i believe you must use : arr.each!((ref e) { writeln(e); ++e; }) "=>" is for oneliner though i don"t understand why it fails silently ??

Re: Pixelbuffer to draw on a surface

2015-11-30 Thread visitor via Digitalmars-d-learn
but there is no specific solution inside GTKD? for example, in pseudo code auto surf = new Surface(...); // look for cairo.Surface doc auto cr = cairo.Context.Context.create(surf); // pb is an existing gdkpixbuf.Pixbuf gdk.Cairo.setSourcePixbuf(cr, pb, width, height); cr.paint(); adding

Re: having problem with `std.algorithm.each`

2015-11-30 Thread visitor via Digitalmars-d-learn
On Monday, 30 November 2015 at 12:03:08 UTC, anonymous wrote: On 30.11.2015 11:50, visitor wrote: though i don"t understand why it fails silently ?? ref2491's original code is valid, but doesn't have the intended meaning. `e => {foo(e);}` is the same as `(e) {return () {foo(e);};}`, i.e. a