Re: What am I doing wrong here?

2022-05-08 Thread JG via Digitalmars-d-learn
On Saturday, 7 May 2022 at 02:29:59 UTC, Salih Dincer wrote: On Friday, 6 May 2022 at 18:04:13 UTC, JG wrote: ```d //... struct Adder { int a; int opCall(int b) { return a+b; } } auto adder(int a) { auto ret = Adder.init; ret.a=a; return ret; } void main() { auto g =

Re: What am I doing wrong here?

2022-05-06 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 6 May 2022 at 18:04:13 UTC, JG wrote: ```d //... struct Adder { int a; int opCall(int b) { return a+b; } } auto adder(int a) { auto ret = Adder.init; ret.a=a; return ret; } void main() { auto g = adder(5); g(5).writeln; // 10 auto d = toDelegate!(int,

Re: What am I doing wrong here?

2022-05-06 Thread JG via Digitalmars-d-learn
On Friday, 6 May 2022 at 18:35:40 UTC, Ali Çehreli wrote: On 5/6/22 11:04, JG wrote: > [...] This is a segmentation fault. Reduced: import std; [...] Hi, thanks. That was quite silly. (I was thinking the variable lives to the end of scope of main but not thinking about that I am passing

Re: What am I doing wrong here?

2022-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 5/6/22 11:04, JG wrote: > This isn't code to be used for anything (just understanding). This is a segmentation fault. Reduced: import std; struct Delegate(A,B) { B function(void* ptr, A a) f; void* data; B opCall(A a) { return f(data,a); } } auto toDelegate(A,

What am I doing wrong here?

2022-05-06 Thread JG via Digitalmars-d-learn
This isn't code to be used for anything (just understanding). ```d import std; struct Delegate(A,B) { B function(void* ptr, A a) f; void* data; B opCall(A a) { return f(data,a); } } auto toDelegate(A, B,S)(S s) { static B f(void* ptr, A a) { return

Re: D outperformed by C++, what am I doing wrong?

2017-08-17 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 13 August 2017 at 06:09:39 UTC, amfvcg wrote: Hi all, I'm solving below task: given container T and value R return sum of R-ranges over T. An example: input : T=[1,1,1] R=2 output : [2, 1] input : T=[1,2,3] R=1 output : [1,2,3] (see dlang unittests for more examples) Below c++

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread via Digitalmars-d-learn
On Sunday, 13 August 2017 at 09:56:44 UTC, Johan Engelen wrote: On Sunday, 13 August 2017 at 09:15:48 UTC, amfvcg wrote: Change the parameter for this array size to be taken from stdin and I assume that these optimizations will go away. This is paramount for all of the testing, examining,

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread via Digitalmars-d-learn
On Sunday, 13 August 2017 at 09:41:39 UTC, Johan Engelen wrote: On Sunday, 13 August 2017 at 09:08:14 UTC, Petar Kirov [ZombineDev] wrote: [...] [...] Execution of sum_subranges is already O(1), because the calculation of the sum is delayed: the return type of the function is not

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 13 August 2017 at 09:15:48 UTC, amfvcg wrote: Change the parameter for this array size to be taken from stdin and I assume that these optimizations will go away. This is paramount for all of the testing, examining, and comparisons that are discussed in this thread. Full

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 13 August 2017 at 09:08:14 UTC, Petar Kirov [ZombineDev] wrote: This instantiation: sum_subranges(std.range.iota!(int, int).iota(int, int).Result, uint) of the following function: auto sum_subranges(T)(T input, uint range) { import std.range : chunks, ElementType, array;

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread amfvcg via Digitalmars-d-learn
On Sunday, 13 August 2017 at 09:08:14 UTC, Petar Kirov [ZombineDev] wrote: There's one especially interesting result: This instantiation: sum_subranges(std.range.iota!(int, int).iota(int, int).Result, uint) of the following function: auto sum_subranges(T)(T input, uint range) { import

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread via Digitalmars-d-learn
On Sunday, 13 August 2017 at 08:43:29 UTC, amfvcg wrote: On Sunday, 13 August 2017 at 08:33:53 UTC, Petar Kirov [ZombineDev] wrote: With Daniel's latest version ( http://forum.dlang.org/post/mailman.5963.1502612885.31550.digitalmars-d-le...@puremagic.com ) $ ldc2 -O3 --release

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread amfvcg via Digitalmars-d-learn
On Sunday, 13 August 2017 at 08:33:53 UTC, Petar Kirov [ZombineDev] wrote: With Daniel's latest version ( http://forum.dlang.org/post/mailman.5963.1502612885.31550.digitalmars-d-le...@puremagic.com ) $ ldc2 -O3 --release sum_subranges2.d $ ./sum_subranges2 210 ms, 838 μs, and 8 hnsecs

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread ikod via Digitalmars-d-learn
On Sunday, 13 August 2017 at 08:32:50 UTC, amfvcg wrote: Gives me 5 μs and 2 hnsecs 5000 3 secs, 228 ms, 837 μs, and 4 hnsecs 5000 And you've compiled it with? Btw. clang for c++ version works worse than gcc (for this case [112ms vs 180ms]). DMD64 D Compiler v2.074.1

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Daniel Kozak via Digitalmars-d-learn
And this one is awesome :P http://ideone.com/muehUw On Sun, Aug 13, 2017 at 10:27 AM, Daniel Kozak wrote: > this one is even faster than c++: > http://ideone.com/TRDsOo > > On Sun, Aug 13, 2017 at 10:00 AM, Daniel Kozak wrote: > >> my second version on ldc

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread via Digitalmars-d-learn
On Sunday, 13 August 2017 at 08:29:30 UTC, Petar Kirov [ZombineDev] wrote: On Sunday, 13 August 2017 at 08:13:56 UTC, amfvcg wrote: On Sunday, 13 August 2017 at 08:00:53 UTC, Daniel Kozak wrote: my second version on ldc takes 380ms and c++ version on same compiler (clang), takes 350ms, so it

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread amfvcg via Digitalmars-d-learn
Gives me 5 μs and 2 hnsecs 5000 3 secs, 228 ms, 837 μs, and 4 hnsecs 5000 And you've compiled it with? Btw. clang for c++ version works worse than gcc (for this case [112ms vs 180ms]).

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread via Digitalmars-d-learn
On Sunday, 13 August 2017 at 08:13:56 UTC, amfvcg wrote: On Sunday, 13 August 2017 at 08:00:53 UTC, Daniel Kozak wrote: my second version on ldc takes 380ms and c++ version on same compiler (clang), takes 350ms, so it seems to be almost same Ok, on ideone (ldc 1.1.0) it timeouts, on dpaste

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread ikod via Digitalmars-d-learn
On Sunday, 13 August 2017 at 08:13:56 UTC, amfvcg wrote: On Sunday, 13 August 2017 at 08:00:53 UTC, Daniel Kozak wrote: my second version on ldc takes 380ms and c++ version on same compiler (clang), takes 350ms, so it seems to be almost same Ok, on ideone (ldc 1.1.0) it timeouts, on dpaste

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Daniel Kozak via Digitalmars-d-learn
this one is even faster than c++: http://ideone.com/TRDsOo On Sun, Aug 13, 2017 at 10:00 AM, Daniel Kozak wrote: > my second version on ldc takes 380ms and c++ version on same compiler > (clang), takes 350ms, so it seems to be almost same > > On Sun, Aug 13, 2017 at 9:51 AM,

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread amfvcg via Digitalmars-d-learn
On Sunday, 13 August 2017 at 08:00:53 UTC, Daniel Kozak wrote: my second version on ldc takes 380ms and c++ version on same compiler (clang), takes 350ms, so it seems to be almost same Ok, on ideone (ldc 1.1.0) it timeouts, on dpaste (ldc 0.12.0) it gets killed. What version are you using?

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Daniel Kozak via Digitalmars-d-learn
my second version on ldc takes 380ms and c++ version on same compiler (clang), takes 350ms, so it seems to be almost same On Sun, Aug 13, 2017 at 9:51 AM, amfvcg via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Sunday, 13 August 2017 at 07:30:32 UTC, Daniel Kozak wrote: >

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread amfvcg via Digitalmars-d-learn
On Sunday, 13 August 2017 at 07:30:32 UTC, Daniel Kozak wrote: Here is more D idiomatic way: import std.stdio : writeln; import std.algorithm.comparison: min; import std.algorithm.iteration: sum; import core.time: MonoTime, Duration; auto sum_subranges(T)(T input, uint range) { import

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Daniel Kozak via Digitalmars-d-learn
Here is more D idiomatic way: import std.stdio : writeln; import std.algorithm.comparison: min; import std.algorithm.iteration: sum; import core.time: MonoTime, Duration; auto sum_subranges(T)(T input, uint range) { import std.array : array; import std.range : chunks, ElementType;

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Daniel Kozak via Digitalmars-d-learn
this works ok for me with ldc compiler, gdc does not work on my arch machine so I can not do comparsion to your c++ versin (clang does not work with your c++ code) import std.stdio : writeln; import std.algorithm.comparison: min; import std.algorithm.iteration: sum; import core.time: MonoTime,

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Neia Neutuladh via Digitalmars-d-learn
On Sunday, 13 August 2017 at 06:09:39 UTC, amfvcg wrote: Hi all, I'm solving below task: Well, for one thing, you are preallocating in C++ code but not in D. On my machine, your version of the code completes in 3.175 seconds. Changing it a little reduces it to 0.420s: T[] result =

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Roman Hargrave via Digitalmars-d-learn
On Sunday, 13 August 2017 at 06:09:39 UTC, amfvcg wrote: Hi all, I'm solving below task: given container T and value R return sum of R-ranges over T. An example: input : T=[1,1,1] R=2 output : [2, 1] input : T=[1,2,3] R=1 output : [1,2,3] (see dlang unittests for more examples) Below c++

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread rikki cattermole via Digitalmars-d-learn
On 13/08/2017 7:09 AM, amfvcg wrote: Hi all, I'm solving below task: given container T and value R return sum of R-ranges over T. An example: input : T=[1,1,1] R=2 output : [2, 1] input : T=[1,2,3] R=1 output : [1,2,3] (see dlang unittests for more examples) Below c++ code compiled with

D outperformed by C++, what am I doing wrong?

2017-08-13 Thread amfvcg via Digitalmars-d-learn
Hi all, I'm solving below task: given container T and value R return sum of R-ranges over T. An example: input : T=[1,1,1] R=2 output : [2, 1] input : T=[1,2,3] R=1 output : [1,2,3] (see dlang unittests for more examples) Below c++ code compiled with g++-5.4.0 -O2 -std=c++14 runs on my

What am I doing wrong in this Pegged grammar? "Expected ' be ' but got 'groups'"

2015-09-27 Thread Enjoys Math via Digitalmars-d-learn
Here's a minimal example: http://pastebin.com/mJDwGDbb Is this a bug in Pegged? Nothing seems to fix it.

Re: What am I doing Wrong (OpenGL SDL)

2015-02-05 Thread Mike Parker via Digitalmars-d-learn
On 2/5/2015 4:53 PM, Entity325 wrote: On Thursday, 5 February 2015 at 07:23:15 UTC, drug wrote: Look at this https://github.com/drug007/geoviewer/blob/master/src/sdlapp.d I used here SDL and OpenGL and it worked. Ctor of SDLApp creates SDL window with OpenGL context, may be it helps. Tested

Re: What am I doing Wrong (OpenGL SDL)

2015-02-05 Thread drug via Digitalmars-d-learn
On 05.02.2015 10:53, Entity325 wrote: On Thursday, 5 February 2015 at 07:23:15 UTC, drug wrote: Look at this https://github.com/drug007/geoviewer/blob/master/src/sdlapp.d I used here SDL and OpenGL and it worked. Ctor of SDLApp creates SDL window with OpenGL context, may be it helps. Tested

Re: What am I doing Wrong (OpenGL SDL)

2015-02-05 Thread Entity325 via Digitalmars-d-learn
Aldacron and I have determined that I'm doing something weird with the imports between gl.d and gl3.d, the functions I'm trying to access are deprecated so the problem is less that they aren't loading and more that I can see them at all.

Re: What am I doing Wrong (OpenGL SDL)

2015-02-04 Thread Entity325 via Digitalmars-d-learn
I will see how much I can strip away and still reproduce the problem. If I find the cause before then, I'll be sure to report back here.

Re: What am I doing Wrong (OpenGL SDL)

2015-02-04 Thread Entity325 via Digitalmars-d-learn
I am having a problem which is similar in appearance to the OP's, but it does not seem to be similar in function. When I try to execute any of the Gl functions in the (protected) DerelictGL3.gl.loadSymbols function, I get an access violation. Checking for null reveals that the functions are

Re: What am I doing Wrong (OpenGL SDL)

2015-02-04 Thread Entity325 via Digitalmars-d-learn
On Thursday, 5 February 2015 at 06:07:34 UTC, Entity325 wrote: I will see how much I can strip away and still reproduce the problem. If I find the cause before then, I'll be sure to report back here. I don't know if this is relevant, but while stripping down my code, I discovered that

Re: What am I doing Wrong (OpenGL SDL)

2015-02-04 Thread drug via Digitalmars-d-learn
On 05.02.2015 09:57, Entity325 wrote: On Thursday, 5 February 2015 at 06:07:34 UTC, Entity325 wrote: I will see how much I can strip away and still reproduce the problem. If I find the cause before then, I'll be sure to report back here. I don't know if this is relevant, but while stripping

Re: What am I doing Wrong (OpenGL SDL)

2015-02-04 Thread Entity325 via Digitalmars-d-learn
On Thursday, 5 February 2015 at 07:23:15 UTC, drug wrote: Look at this https://github.com/drug007/geoviewer/blob/master/src/sdlapp.d I used here SDL and OpenGL and it worked. Ctor of SDLApp creates SDL window with OpenGL context, may be it helps. Tested your code. Symbols still not being

Re: What am I doing Wrong (OpenGL SDL)

2015-02-04 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 5 February 2015 at 01:51:05 UTC, Entity325 wrote: I am having a problem which is similar in appearance to the OP's, but it does not seem to be similar in function. When I try to execute any of the Gl functions in the (protected) DerelictGL3.gl.loadSymbols function, I get an access

What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Sean Campbell via Digitalmars-d-learn
I cannot figure out what is wrong with this code and why i keep getting object.error access violation. the code is simple tutorial code for SDL and OpenGL what am i doing wrong (the access violation seems to be with glGenBuffers) The Code import std.stdio; import derelict.opengl3.gl3; import

Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Misu via Digitalmars-d-learn
Can you try to add DerelictGL3.reload(); after SDL_GL_CreateContext ?

Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread bearophile via Digitalmars-d-learn
Sean Campbell: I cannot figure out what is wrong with this code and why i keep getting object.error access violation. the code is simple tutorial code for SDL and OpenGL what am i doing wrong (the access violation seems to be with glGenBuffers) I don't know where your problem is, but you

Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Sean Campbell via Digitalmars-d-learn
On Friday, 4 July 2014 at 08:02:59 UTC, Misu wrote: Can you try to add DerelictGL3.reload(); after SDL_GL_CreateContext ? yes this solved the problem. however why? is it a problem with the SDL binding?

Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread safety0ff via Digitalmars-d-learn
On Friday, 4 July 2014 at 09:39:49 UTC, Sean Campbell wrote: On Friday, 4 July 2014 at 08:02:59 UTC, Misu wrote: Can you try to add DerelictGL3.reload(); after SDL_GL_CreateContext ? yes this solved the problem. however why? is it a problem with the SDL binding? No.

Re: What am I doing Wrong (OpenGL SDL)

2014-07-04 Thread Mike Parker via Digitalmars-d-learn
On 7/4/2014 6:39 PM, Sean Campbell wrote: On Friday, 4 July 2014 at 08:02:59 UTC, Misu wrote: Can you try to add DerelictGL3.reload(); after SDL_GL_CreateContext ? yes this solved the problem. however why? is it a problem with the SDL binding? OpenGL on Windows requires a context be created

What am I doing wrong here?

2012-10-14 Thread Martin
Hey everyone, I'm new to D so bare with me please. I've been trying to figure out what's up with the strange forward refernce errors the compiler (DMD 2.060) is giving me. Here's a code snippet that's generating a forward reference error: public class AliasTestClass(alias func) {

Re: What am I doing wrong here?

2012-10-14 Thread Simen Kjaeraas
On 2012-10-14, 14:28, Martin wrote: Hey everyone, I'm new to D so bare with me please. I've been trying to figure out what's up with the strange forward refernce errors the compiler (DMD 2.060) is giving me. Here's a code snippet that's generating a forward reference error: public class

Re: What am I doing wrong here?

2012-10-14 Thread Martin
On Sunday, 14 October 2012 at 12:58:24 UTC, Simen Kjaeraas wrote: On 2012-10-14, 14:28, Martin wrote: Hey everyone, I'm new to D so bare with me please. I've been trying to figure out what's up with the strange forward refernce errors the compiler (DMD 2.060) is giving me. Here's a code

Re: What am I doing wrong ?

2012-04-26 Thread Marco Leise
): Range violation on the line with the arrow. What am I doing wrong ? You could also try: foreach_reverse(i, ref f; array) { f.x = i; } -- Marco

What am I doing wrong ?

2012-04-22 Thread SomeDude
. What am I doing wrong ?

Re: What am I doing wrong ?

2012-04-22 Thread Dmitry Olshansky
index is array.length-1. writeln(); foreach(Foo f; array) { write(f.x);} } throws core.exception.RangeError@bug(8): Range violation on the line with the arrow. What am I doing wrong ? -- Dmitry Olshansky

Re: What am I doing wrong ?

2012-04-22 Thread Mike Wey
1; i--) { array[i].x = i; } writeln(); foreach(Foo f; array) { write(f.x);} } throws core.exception.RangeError@bug(8): Range violation on the line with the arrow. What am I doing wrong ? You set i to the array length of 10 but the array index is zero based so the last item in the array

Re: What am I doing wrong ?

2012-04-22 Thread SomeDude
On Sunday, 22 April 2012 at 21:50:32 UTC, Dmitry Olshansky wrote: Omagad, thank you, too much Java is bd for your brains.