Re: Define methods using templates

2015-01-08 Thread Claude via Digitalmars-d-learn
I just saw this post, which is essentially the same question as Basile Burg's. I hope that a college (in France?) is teaching D and that this is a homework assignment. Cool stuff! :) Maybe using templates to create properties is a bit overkill in this example. But I could not solve what I thou

Re: Define methods using templates

2014-12-30 Thread Ali Çehreli via Digitalmars-d-learn
On 12/30/2014 05:17 AM, Claude wrote: > use templates to define several methods (property > setters) within a class to avoid some code duplication. I just saw this post, which is essentially the same question as Basile Burg's. I hope that a college (in France?) is teaching D and that this is a

Re: Define methods using templates

2014-12-30 Thread Claude via Digitalmars-d-learn
Thanks Steven and Daniel for your explanations. mixin template opAssign(alias Field) { void opAssign(Tin)(auto ref Tin param) @property pure @safe { Field = param; m_matrixCalculated = false; } } mixin opAssign!(m_pos) pos; I tes

Re: Define methods using templates

2014-12-30 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 30 Dec 2014 13:17:08 + Claude via Digitalmars-d-learn napsáno: > Hello, I'm trying to use templates to define several methods > (property setters) within a class to avoid some code duplication. > Here is an attempt: > > class Camera > { > private: > Vector4 m_pos; > float m

Re: Define methods using templates

2014-12-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/30/14 8:48 AM, Steven Schveighoffer wrote: I think it has to do with the fact that when you are defining the aliases, m_pos for example, is an *instance* member so requires an instance to get an alias. What you are probably better off doing is: void SetProperty(Tin, string Field)(ref Tin

Re: Define methods using templates

2014-12-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/30/14 8:17 AM, Claude wrote: Hello, I'm trying to use templates to define several methods (property setters) within a class to avoid some code duplication. Here is an attempt: class Camera { private: Vector4 m_pos; float m_fov, m_ratio, m_near, m_far; bool m_matrixCalculated

Define methods using templates

2014-12-30 Thread Claude via Digitalmars-d-learn
Hello, I'm trying to use templates to define several methods (property setters) within a class to avoid some code duplication. Here is an attempt: class Camera { private: Vector4 m_pos; float m_fov, m_ratio, m_near, m_far; bool m_matrixCalculated; public: void SetProperty(Tin, a