Re: Error instantiating std.container.Array

2015-03-02 Thread Francesco Cattoglio via Digitalmars-d-learn
On Monday, 2 March 2015 at 15:01:55 UTC, Tobias Pankrath wrote: I'm really clueless... :P Something is wrong with your Material class, but you'll need to show us a reduced example. After a really long time I finally found what was wrong. http://dpaste.dzfl.pl/16d202b7124d Wow, I honestly c

Re: Error instantiating std.container.Array

2015-03-02 Thread Francesco Cattoglio via Digitalmars-d-learn
On Monday, 2 March 2015 at 14:46:31 UTC, ketmar wrote: On Mon, 02 Mar 2015 14:40:50 +, Francesco Cattoglio wrote: did you tried to dustmite[1] it? [1] https://github.com/CyberShadow/DustMite/wiki I tried to "dub dustmite", but it failed with a "object.Exception@DustMite

Re: Error instantiating std.container.Array

2015-03-02 Thread Francesco Cattoglio via Digitalmars-d-learn
On Monday, 2 March 2015 at 14:14:19 UTC, Tobias Pankrath wrote: Try to reduce your Material class for a small failing example. It's probably your constructors or opAssign or something like that. Anyway, it's a bug if template errors from the implementation bubble up, so please file a report. I

Error instantiating std.container.Array

2015-03-02 Thread Francesco Cattoglio via Digitalmars-d-learn
I'm trying to instantiate a std.container.Array of a given class (named Material), by a simple Array!Material _myStuff; I get two compile errors stating the following: C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(85): Error: template std.algorithm.initializeAll cannot deduce fun

Re: A naive attempt at a refcounted class proxy

2015-01-15 Thread Francesco Cattoglio via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 18:52:25 UTC, ketmar via Digitalmars-d-learn wrote: On Tue, 13 Jan 2015 18:36:15 + aldanor via Digitalmars-d-learn wrote: On Tuesday, 13 January 2015 at 18:19:42 UTC, ketmar via Digitalmars-d-learn wrote: > and then you can go with structures in the first p

-inline switch changes code behaviour

2014-08-23 Thread francesco cattoglio via Digitalmars-d-learn
Today I just realized that in DMD optimize flag does not imply inlining, therefore I promptly added the "inline" to my dub build settings and recompiler, expecting to see speedups in my code execution. To my surprise, I could not see anything at all: all that I get now is a blank screen. The

Get the default hash function.

2014-07-31 Thread francesco cattoglio via Digitalmars-d-learn
Really simple question: how do I get the compiler-generated hash function for a given type? For example: Struct S { int i; } can be used in an associative array. That means the compiler generates a "toHash" function. Is there any simple way to call it directly?

Re: Type deduction on templated constructor.

2014-07-24 Thread francesco cattoglio via Digitalmars-d-learn
On Thursday, 24 July 2014 at 09:38:14 UTC, bearophile wrote: francesco cattoglio: should this code compile? I understand that the literal "1" is "int" therefore it can screw type deduction, but I wonder if the compiler should be smart enough to deduce it correctly. To ke

Type deduction on templated constructor.

2014-07-24 Thread francesco cattoglio via Digitalmars-d-learn
So, I have this code (also on http://dpaste.dzfl.pl/3f767b17e83c) This Vector(T) struct is taken from gfm.math.vector. struct Vector(T) { T x, y, z; this(X : T, Y : T, Z : T)(X x_, Y y_, Z z_) { x = x_; y = y_; z = z_; } } void main() { Ve

Re: core.exception.InvalidMemoryOperationError

2014-07-11 Thread francesco cattoglio via Digitalmars-d-learn
On Friday, 11 July 2014 at 11:43:44 UTC, Joakim wrote: On Thursday, 10 July 2014 at 15:36:53 UTC, francesco cattoglio wrote: A code I'm working on stops working and starts printing an infinite loop of core.exception.InvalidMemoryOperationError to the command line output. The code is

core.exception.InvalidMemoryOperationError

2014-07-10 Thread francesco cattoglio via Digitalmars-d-learn
A code I'm working on stops working and starts printing an infinite loop of core.exception.InvalidMemoryOperationError to the command line output. The code is quite complex and the bug seems to present itself almost in random situation so I would like to try to understand the issue better befor

Re: What exactly module in D means?

2014-07-05 Thread Francesco Cattoglio via Digitalmars-d-learn
On Saturday, 5 July 2014 at 17:08:01 UTC, Olivier Pisano wrote: No, import is different from include. It does not stupidly copy and paste its content but tells the compiler to take the module into account for name resolution. The result may seem similar, but is much more efficient. In fact, try

Re: how to correctly 'typedef' handle types

2014-06-20 Thread francesco cattoglio via Digitalmars-d-learn
http://dlang.org/phobos/std_typecons.html#Typedef Take a look at it. Docs is scarce (pretty sure you will need to take a look around to find something) but it should just do what you need.

Re: Differences between "const Type function()" and "const(Type) function()"

2014-05-30 Thread francesco cattoglio via Digitalmars-d-learn
On Friday, 30 May 2014 at 12:57:52 UTC, anonymous wrote: And why is "const(Foo) getQ" so much different? (e.g: this is an explicit cast, right? Is there anything that might go wrong?) It's not a cast. It's the unambiguous notation for a qualified type. Often you can omit the parentheses. With

Differences between "const Type function()" and "const(Type) function()"

2014-05-30 Thread francesco cattoglio via Digitalmars-d-learn
Today I got the following compile error: "Cannot implicitly convert expression () of type const() to " and this is a reduced example ( also on http://dpaste.dzfl.pl/f2f3bd921989): module test; import std.stdio; class Foo { int i = 42; } class MyClass { private { Foo _Q;

Re: Programming a Game in D? :D

2014-05-28 Thread Francesco Cattoglio via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 17:46:23 UTC, David wrote: Ok, now I just wonder wich Engine. (I know everybody hates the discussion about the "best" engine.) CryEngine, UDK, Unity or a less known Engine? I'll be honest, perhaps I risk being misunderstood, but the questions you are asking denote

Re: Programming a Game in D? :D

2014-05-22 Thread Francesco Cattoglio via Digitalmars-d-learn
On Thursday, 22 May 2014 at 15:48:50 UTC, John Colvin wrote: On Thursday, 22 May 2014 at 15:39:36 UTC, David wrote: Hey, I'm really new to D, and pretty new to programming overall too, But I want to make a 3d Game, (just sth. small). I really like D and want to do it in D, but in the Internet t

Re: Scalar + array operations

2014-05-21 Thread Francesco Cattoglio via Digitalmars-d-learn
On Wednesday, 21 May 2014 at 13:52:47 UTC, John Colvin wrote: On Wednesday, 21 May 2014 at 11:45:57 UTC, Stefan Frijters wrote: I would have expected the last case to work as well, but I get testarr.d(20): Error: incompatible types for ((dfoo) * (ibar[])): 'double' and 'int[]' Is this by des

Re: Templating everything? One module per function/struct/class/etc, grouped by package?

2014-05-12 Thread Francesco Cattoglio via Digitalmars-d-learn
On Monday, 12 May 2014 at 08:37:43 UTC, JR wrote: What am I missing? Error messages! If your code is not compiled, you can't know whether it is valid or not. I must say that since we have unittests, this is somewhat less relevant, but still... One nice thing would be stripping the executab

Re: D alternative for C/C++ -Dfoo=42

2014-02-25 Thread Francesco Cattoglio
On Tuesday, 25 February 2014 at 14:30:23 UTC, Francesco Cattoglio wrote: On Tuesday, 25 February 2014 at 14:26:13 UTC, Tobias Pankrath wrote: Something like "static if(fileExists!"config.d") mixin(import("config.d")) else ...". Thoughts? Regards - Cherry

Re: D alternative for C/C++ -Dfoo=42

2014-02-25 Thread Francesco Cattoglio
On Tuesday, 25 February 2014 at 14:26:13 UTC, Tobias Pankrath wrote: Something like "static if(fileExists!"config.d") mixin(import("config.d")) else ...". Thoughts? Regards - Cherry -- static if(__traits(compiles, import("config.d"))) { // import/parse/mixin } else { // default here } -- May

Re: Non-Initialized Dynamic Arrays Construction

2014-02-24 Thread Francesco Cattoglio
On Monday, 24 February 2014 at 12:08:31 UTC, Nordlöw wrote: On Monday, 24 February 2014 at 11:29:39 UTC, bearophile wrote: TheFlyingFiddle: http://dlang.org/phobos/std_array.html#.uninitializedArray is what you want. Wouldn't it be nice to have some kind of syntactic sugar for this similar

Re: hiding a class property behind a method

2014-02-22 Thread francesco cattoglio
On Saturday, 22 February 2014 at 22:42:24 UTC, simendsjo wrote: The problem isn't about optional parenthesis or properties. It's the fact that you can redefine a symbol to be something entierly different, and that this difference will only be seen if you are looking at the symbol through the "

Re: hiding a class property behind a method

2014-02-22 Thread Francesco Cattoglio
On Saturday, 22 February 2014 at 17:21:50 UTC, luka8088 wrote: It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: [snip] Nice find. I guess we could add this to the list of "ugly code cau

Re: foreach/iota countdown

2014-02-17 Thread Francesco Cattoglio
On Monday, 17 February 2014 at 20:21:30 UTC, simendsjo wrote: I wouldn't call it randomly. In that case you should call it randomly that it suddenly doesn't run once you try to step downward. I didn't had time to work more on the iota. Perhaps after 2.065 is out I can resume working on that,

Re: Optimize my code =)

2014-02-16 Thread Francesco Cattoglio
On Sunday, 16 February 2014 at 09:53:08 UTC, bearophile wrote: Be instead amazed of the sometimes near-C++ performance levels they have pushed Java to :-) Sorry, but I fail to be amazed by what huge piles of money thrown to a project for 10+ years can achieve. Those kind of achievements are bor

Re: Optimize my code =)

2014-02-16 Thread francesco cattoglio
On Sunday, 16 February 2014 at 01:25:13 UTC, bearophile wrote: Many of the things you say and write are still wrong or confused. Usually the hard optimization of code is one the last things you learn about a language Well, actually, sometimes squeezing as much performance as you can from a te

Re: 3d vector struct

2014-02-04 Thread Francesco Cattoglio
On Monday, 3 February 2014 at 20:10:59 UTC, Brenton wrote: 6) Any other comments or suggestions? I know that the "I'm learning the language" factor plays a huge role, but after you are done studying your vector implementation, I think you could forget about it and use the ones provided by ot

Re: std.array.array broken?

2014-02-01 Thread Francesco Cattoglio
On Saturday, 1 February 2014 at 22:52:24 UTC, Andrej Mitrovic wrote: On Saturday, 1 February 2014 at 22:47:54 UTC, deed wrote: Docs also say: /** Note: Each $(D front) will not persist after $(D popFront) is called, so the caller must copy its contents (e.g. by calling $(D to!string)) if rete

Re: Creating an array of C structs

2014-01-27 Thread Francesco Cattoglio
On Monday, 27 January 2014 at 13:08:28 UTC, Colin Grogan wrote: In my defense, I believe C initializes arrays with the curly brackets Can I keep making excuses? Yes you can... And don't worry, I mess up initialization too. Lots of time. Especially when I tried initializing an array of st

Re: Creating an array of C structs

2014-01-27 Thread Francesco Cattoglio
On Monday, 27 January 2014 at 10:13:08 UTC, Colin Grogan wrote: On Monday, 27 January 2014 at 09:34:04 UTC, Namespace wrote: Arrays are enclosed in [] ;) I'm an idiot. Can I delete this thread to save further embarrassment? :) HA-HA! (read it with Nelson voice, ofc)

Re: "Best" way of handling a receive()d message with a class instance.

2014-01-23 Thread Francesco Cattoglio
Sorry, MY BAD! You can just write auto handler = new Handler; receive(&handler.MyFunc); Somehow when I tried this before it failed to compile, and I thought I had to go through loops for achieving this.

"Best" way of handling a receive()d message with a class instance.

2014-01-23 Thread Francesco Cattoglio
Suppose that I receive a message, but instead of defining a function inside the receive() block, I want to call a member of a class instance. (This is useful to me for several reasons). Right now my code looks like: class Handler { auto handle() { return (string msg) { writeln("rec

Automatic translation of opUnary!"++" into opOpAssign!"+"

2013-12-28 Thread Francesco Cattoglio
So, while I was studying the apropriate template constraints for my shiny new iota implementation, I found out this funny thing: import std.stdio; class Test{ int x = 41; Test opOpAssign(string op)(int rhs) if (op == "+") { x += rhs; return this; } } void main() {

Re: Template constraints: opCmp and opUnary!"++"

2013-12-20 Thread Francesco Cattoglio
On Friday, 20 December 2013 at 17:18:01 UTC, Timon Gehr wrote: On 12/20/2013 05:40 PM, monarch_dodra wrote: That's normal, because "T.init" is not an lvalue. If you need an lvalue, we have `std.traits.lvalueOf!T` which you can use. is(typeof((T v){ /+ use v +/ })) I think this is a lot cl

Re: Template constraints: opCmp and opUnary!"++"

2013-12-20 Thread Francesco Cattoglio
On Friday, 20 December 2013 at 16:40:23 UTC, monarch_dodra wrote: Everything works as it should, but according to "D Templates: A Tutorial" book, you should not use arguments in constraints. That's news to me. It seems strange to me too, but: page 69 on the PDF: "Do not use argument in your co

Template constraints: opCmp and opUnary!"++"

2013-12-20 Thread Francesco Cattoglio
I'm trying to experiment a bit around the iota function. If I try to impose the following constraits: auto my_iota(B, E)(B begin, E end) if (is (typeof(++begin)) && is (typeof(begin < end))) {} Everything works as it should, but according to "D Templates: A Tutorial" book, you should not use ar