how to manage the list of immutable objects

2015-07-14 Thread aki via Digitalmars-d-learn
I like to create immutable object which is identified by name as it's key. And also need get() to look up named object which is already created. class Foo { static immutable(Foo)[string] map; string name; // and other attributes here... this(string name)

Re: how to manage the list of immutable objects

2015-07-14 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 10:09:56 UTC, aki wrote: I like to create immutable object which is identified by name as it's key. And also need get() to look up named object which is already created. class Foo { static immutable(Foo)[string] map; string name; // and other

Re: Align object to vector using Dgame framework

2015-07-14 Thread via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 00:31:56 UTC, codenstuff wrote: On Monday, 13 July 2015 at 19:07:55 UTC, Márcio Martins wrote: On Monday, 13 July 2015 at 16:11:03 UTC, codenstuff wrote: [...] This is not really a game development forum but here you go: auto rads = atan2(object.velocity.y,

Re: Wrapping a C-style Array (Pointer + Length) in a Range Interface

2015-07-14 Thread Nordlöw
On Wednesday, 8 July 2015 at 05:14:48 UTC, ketmar wrote: so while there is nothing wrong in creating slices from pointers, programmer should be aware of some potential pitfalls. I believe there's a DIP (involving the scope keyword) related to this problem, right?

Re: Wrapping a C-style Array (Pointer + Length) in a Range Interface

2015-07-14 Thread ketmar via Digitalmars-d-learn
On Tue, 14 Jul 2015 08:33:56 +, Nordlöw wrote: On Wednesday, 8 July 2015 at 05:14:48 UTC, ketmar wrote: so while there is nothing wrong in creating slices from pointers, programmer should be aware of some potential pitfalls. I believe there's a DIP (involving the scope keyword) related

Re: how to manage the list of immutable objects

2015-07-14 Thread aki via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 10:46:42 UTC, Andrea Fontana wrote: Trying on http://dpaste.dzfl.pl/ I don't see that error. Maybe you mean const and not immutable ? Andrea I used: DMD32 D Compiler v2.067.1 on Windows8 I believe there are no typo because it is copy-pasted. I noticed I can use

Re: Linked variables

2015-07-14 Thread Baz via Digitalmars-d-learn
On Monday, 13 July 2015 at 22:07:11 UTC, Tanel Tagaväli wrote: Does the standard library have a way to create a forward link between two variables of the same type? One variable is the source and the other is the sink. When the source variable is changed, the sink variable is too. Changing the

Re: how to manage the list of immutable objects

2015-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/15 7:12 AM, aki wrote: On Tuesday, 14 July 2015 at 10:46:42 UTC, Andrea Fontana wrote: Trying on http://dpaste.dzfl.pl/ I don't see that error. Maybe you mean const and not immutable ? Wow, that needs updating. Latest version is 2.065 from February 2014, and the git version is from

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 01:05:21 UTC, jmh530 wrote: Note: some of the above seemed to only work when I kept the std.math.cos, std.math.sin text in there. When I take it out, I get warnings about recursive aliases. Yeah, you can't do `alias cos = givemeabettername!cos;`. That would define

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 12:12:41 UTC, anonymous wrote: Works for me. Please show the complete code and the error message you get. Here's what works for me: Thanks for posting that. I figured out the issue. Before you had recommended that I use alias cos = std.math.cos; I had kept

Profile Ouput

2015-07-14 Thread Mike Parker via Digitalmars-d-learn
Perhaps my googlefu has failed me, but I can find anything describing the output of DMD's -profile switch. I get that trace.def is a list of all functions called and I understand the table at the bottom of trace.log. What I'm not sure about is everything above the table in trace.log, stuff

Re: Covariant callback functions, or assigning base class members through a subclass reference

2015-07-14 Thread Kagamin via Digitalmars-d-learn
Template Base on Derived: class Derived : Base!Derived { }

Re: Covariant callback functions, or assigning base class members through a subclass reference

2015-07-14 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 15:35:04 UTC, Kagamin wrote: Template Base on Derived: class Derived : Base!Derived { } Sure, but that would make Base!Derived and Base!AnotherSubClass different types. What I'd like to end up with is a Base[], being able to call foo() on the array members.

Covariant callback functions, or assigning base class members through a subclass reference

2015-07-14 Thread Rene Zwanenburg via Digitalmars-d-learn
Given the following code: class Base { alias CallbackType = void delegate(Base); CallbackType callback; void foo() { callback(this); } } class Derived : Base { } void main() { auto d = new Derived();

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 17:24:41 UTC, anonymous wrote: This fails with Error: None of the overloads of 'cos' are callable using argument types (int[]). The problem is that template mixins cannot add to existing overload sets. The spec says: If the name of a declaration in a mixin is

Re: how to manage the list of immutable objects

2015-07-14 Thread aki via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 11:44:34 UTC, Steven Schveighoffer wrote: static Rebindable!(immutable(Foo))[string] map -Steve It all works. And I learned something from the source code of Rebindable. Thank you. Aki.

Re: Covariant callback functions, or assigning base class members through a subclass reference

2015-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/15 11:28 AM, Rene Zwanenburg wrote: Given the following code: class Base { alias CallbackType = void delegate(Base); CallbackType callback; void foo() { callback(this); } } class Derived : Base { } void main() { auto d = new Derived();

Re: Covariant callback functions, or assigning base class members through a subclass reference

2015-07-14 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 17:26:32 UTC, Steven Schveighoffer wrote: On 7/14/15 11:28 AM, Rene Zwanenburg wrote: Given the following code: class Base { alias CallbackType = void delegate(Base); CallbackType callback; void foo() { callback(this); } } class

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 14:02:46 UTC, jmh530 wrote: Thanks for posting that. I figured out the issue. Before you had recommended that I use alias cos = std.math.cos; I had kept that text in. When I removed it, everything worked just fine. I'm still not sure I grasp the subtleties of alias