www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - template this parameters for constructors

reply Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
--0015175cfd7e7c1c1b04d628e668
Content-Type: text/plain; charset=UTF-8

Template this parameters (
http://dlang.org/template.html#TemplateThisParameter) are extremely useful
for writing generic methods in base classes or interfaces that need to know
the static type of the object they're called on.

class Base
{
    string label;

    this(string label_)
    {
        label = label_;
    }

    string toString(this This_)()
    {
        return This_.stringof ~ "(`" ~ label ~ "`)";
    }
}

class Derived: Base
{
    this()
    {
        super("Hello, world!");
    }
}

unittest
{
    Derived d = new Derived();
    assert(d.toString() == "Derived(`Hello, world!`)");
}

Of course, this wouldn't work if the toString() was called from a Base
reference, instead of Derived.

After I tested this, immediately thought of the constructor. The
constructor of the base class is guaranteed to be called when constructing
a derived class, right? Even if the call is implicit, it still happens and
at the call site the concrete type being constructed is known, so in
theory, a template this parameter on the base class's constructor should
allow the base class to know the static type of the object being
constructed (which is immensely useful for implementing dynamic dispatch
classes).

class Base
{
    this(this This_)()
    {
        // Build a dispatch table using __traits(allMethods, This_)
    }

    void opCall(Payload_)(Payload_ payload_)
    {
        // Dynamically dispatch payload_ using the previously built
dispatch table.
    }
}

class Derived: Base
{
    // implicitly generated constructor will call the Base.this() and
implicitly give it the static type of Derived.
}

unittest
{
    Base b = new Derived;
    b(); // 100% transparent dynamic dispatch
}

Unfortunately, this is what DMD had to say about this:

C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: found 'This_' when
expecting ')'
C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: semicolon expected
following function declaration
C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: Declaration expected, not
')'

It looks like DMD thinks I was gonna write a postblit constructor and I
guess the functionality is already there, but can't be reached due to a
parsing error.

Is there any change of this being fixed any time soon?

-- 
Bye,
Gor Gyolchanyan.

--0015175cfd7e7c1c1b04d628e668
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Template this parameters (<a href=3D"http://dlang.org=
/template.html#TemplateThisParameter">http://dlang.org/template.html#Templa=
teThisParameter</a>) are extremely useful for writing generic methods in ba=
se classes or interfaces that need to know the static type of the object th=
ey&#39;re called on.</div>
<div><br></div><div>class Base</div><div>{</div><div>=C2=A0 =C2=A0 string l=
abel;</div><div><br></div><div>=C2=A0 =C2=A0 this(string label_)</div><div>=
=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 label =3D label_;</di=
v><div>=C2=A0 =C2=A0 }</div><div><br></div><div>=C2=A0 =C2=A0 string toStri=
ng(this This_)()</div>
<div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return This_.str=
ingof ~ &quot;(`&quot; ~ label ~ &quot;`)&quot;;</div><div>=C2=A0 =C2=A0 }<=
/div><div>}</div><div><br></div><div>class Derived: Base</div><div>{</div><=
div>=C2=A0 =C2=A0 this()</div><div>=C2=A0 =C2=A0 {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 super(&quot;Hello, world!&quot;);</div><di=
v>=C2=A0 =C2=A0 }</div><div>}</div><div><br></div><div>unittest</div><div>{=
</div><div>=C2=A0 =C2=A0 Derived d =3D new Derived();</div><div>=C2=A0 =C2=
=A0 assert(d.toString() =3D=3D &quot;Derived(`Hello, world!`)&quot;);</div>
<div>}</div><div><br></div><div>Of course, this wouldn&#39;t work if the to=
String() was called from a Base reference, instead of Derived.</div><div><b=
r></div><div>After I tested this, immediately thought of the constructor. T=
he constructor of the base class is guaranteed to be called when constructi=
ng a derived class, right? Even if the call is implicit, it still happens a=
nd at the call site the concrete type being constructed is known, so in the=
ory, a template this parameter on the base class&#39;s constructor should a=
llow the base class to know the static type of the object being constructed=
 (which is immensely useful for implementing dynamic dispatch classes).</di=
v>
<div><br></div><div>class Base</div><div>{</div><div>=C2=A0 =C2=A0 this(thi=
s This_)()</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
// Build a dispatch table using __traits(allMethods, This_)</div><div>=C2=
=A0 =C2=A0 }</div><div><br></div><div>=C2=A0 =C2=A0 void opCall(Payload_)(P=
ayload_ payload_)</div>
<div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Dynamically d=
ispatch payload_ using the previously built dispatch table.</div><div>=C2=
=A0 =C2=A0 }</div><div>}</div><div><br></div><div>class Derived: Base</div>=
<div>{</div><div>=C2=A0 =C2=A0 // implicitly generated constructor will cal=
l the Base.this() and implicitly give it the static type of Derived.</div>
<div>}</div><div><br></div><div>unittest</div><div>{</div><div>=C2=A0 =C2=
=A0 Base b =3D new Derived;</div><div>=C2=A0 =C2=A0 b(); // 100% transparen=
t dynamic dispatch</div><div>}</div><div><br></div><div style>Unfortunately=
, this is what DMD had to say about this:</div>
<div><br></div><div>C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: found =
&#39;This_&#39; when expecting &#39;)&#39;</div><div>C:\Users\g.gyolchanyan=
\Desktop\test.d(3): Error: semicolon expected following function declaratio=
n</div>
<div>C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: Declaration expected,=
 not &#39;)&#39;</div><div><br></div><div style>It looks like DMD thinks I =
was gonna write a postblit constructor and I guess the functionality is alr=
eady there, but can&#39;t be reached due to a parsing error.</div>
<div style><br></div><div style>Is there any change of this being fixed any=
 time soon?</div><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.
</div>

--0015175cfd7e7c1c1b04d628e668--
Feb 20 2013
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2013-02-20 15:37, Gor Gyolchanyan wrote:

 After I tested this, immediately thought of the constructor. The
 constructor of the base class is guaranteed to be called when
 constructing a derived class, right? Even if the call is implicit, it
 still happens and at the call site the concrete type being constructed
 is known, so in theory, a template this parameter on the base class's
 constructor should allow the base class to know the static type of the
 object being constructed (which is immensely useful for implementing
 dynamic dispatch classes).

 class Base
 {
      this(this This_)()
      {
          // Build a dispatch table using __traits(allMethods, This_)
      }

      void opCall(Payload_)(Payload_ payload_)
      {
          // Dynamically dispatch payload_ using the previously built
 dispatch table.
      }
 }

 class Derived: Base
 {
      // implicitly generated constructor will call the Base.this() and
 implicitly give it the static type of Derived.
 }

 unittest
 {
      Base b = new Derived;
      b(); // 100% transparent dynamic dispatch
 }

 Unfortunately, this is what DMD had to say about this:

 C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: found 'This_' when
 expecting ')'
 C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: semicolon expected
 following function declaration
 C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: Declaration expected,
 not ')'

 It looks like DMD thinks I was gonna write a postblit constructor and I
 guess the functionality is already there, but can't be reached due to a
 parsing error.

I haven't even thought about this use case. It would be so cool. -- /Jacob Carlborg
Feb 20 2013
prev sibling next sibling parent Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
--0015175886109aaa4604d62937f8
Content-Type: text/plain; charset=UTF-8

On Wed, Feb 20, 2013 at 6:42 PM, Jacob Carlborg <doob me.com> wrote:

 On 2013-02-20 15:37, Gor Gyolchanyan wrote:

  After I tested this, immediately thought of the constructor. The
 constructor of the base class is guaranteed to be called when
 constructing a derived class, right? Even if the call is implicit, it
 still happens and at the call site the concrete type being constructed
 is known, so in theory, a template this parameter on the base class's
 constructor should allow the base class to know the static type of the
 object being constructed (which is immensely useful for implementing
 dynamic dispatch classes).

 class Base
 {
      this(this This_)()
      {
          // Build a dispatch table using __traits(allMethods, This_)
      }

      void opCall(Payload_)(Payload_ payload_)
      {
          // Dynamically dispatch payload_ using the previously built
 dispatch table.
      }
 }

 class Derived: Base
 {
      // implicitly generated constructor will call the Base.this() and
 implicitly give it the static type of Derived.
 }

 unittest
 {
      Base b = new Derived;
      b(); // 100% transparent dynamic dispatch
 }

 Unfortunately, this is what DMD had to say about this:

 C:\Users\g.gyolchanyan\**Desktop\test.d(3): Error: found 'This_' when
 expecting ')'
 C:\Users\g.gyolchanyan\**Desktop\test.d(3): Error: semicolon expected
 following function declaration
 C:\Users\g.gyolchanyan\**Desktop\test.d(3): Error: Declaration expected,
 not ')'

 It looks like DMD thinks I was gonna write a postblit constructor and I
 guess the functionality is already there, but can't be reached due to a
 parsing error.

I haven't even thought about this use case. It would be so cool. -- /Jacob Carlborg

This would mean, that D can flawlessly mix together static and dynamic typing to achieve maximum flexibility (using dynamic typing like this) and maximum performance (using static typing when this isn't required). No statically-typed and no dynamically-typed language can combine flexibility and performance right now. Combined with the upcoming revamp of D's compile-time and (built on top of it) run-time reflection, this will make D the ultimate modeling tool for building systems of arbitrary dynamicity and maximum performance. By the way, what's up with the new reflection thing that Andrei once wrote about? -- Bye, Gor Gyolchanyan. --0015175886109aaa4604d62937f8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">On Wed, Feb 20, 2013 at 6:42 PM, Jacob Carlborg <span dir= =3D"ltr">&lt;<a href=3D"mailto:doob me.com" target=3D"_blank">doob me.com</= a>&gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quot= e"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bord= er-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:soli= d;padding-left:1ex"> <div class=3D""><div class=3D"h5">On 2013-02-20 15:37, Gor Gyolchanyan wrot= e:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex"> After I tested this, immediately thought of the constructor. The<br> constructor of the base class is guaranteed to be called when<br> constructing a derived class, right? Even if the call is implicit, it<br> still happens and at the call site the concrete type being constructed<br> is known, so in theory, a template this parameter on the base class&#39;s<b= r> constructor should allow the base class to know the static type of the<br> object being constructed (which is immensely useful for implementing<br> dynamic dispatch classes).<br> <br> class Base<br> {<br> =C2=A0 =C2=A0 =C2=A0this(this This_)()<br> =C2=A0 =C2=A0 =C2=A0{<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0// Build a dispatch table using __traits(= allMethods, This_)<br> =C2=A0 =C2=A0 =C2=A0}<br> <br> =C2=A0 =C2=A0 =C2=A0void opCall(Payload_)(Payload_ payload_)<br> =C2=A0 =C2=A0 =C2=A0{<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0// Dynamically dispatch payload_ using th= e previously built<br> dispatch table.<br> =C2=A0 =C2=A0 =C2=A0}<br> }<br> <br> class Derived: Base<br> {<br> =C2=A0 =C2=A0 =C2=A0// implicitly generated constructor will call the Base.= this() and<br> implicitly give it the static type of Derived.<br> }<br> <br> unittest<br> {<br> =C2=A0 =C2=A0 =C2=A0Base b =3D new Derived;<br> =C2=A0 =C2=A0 =C2=A0b(); // 100% transparent dynamic dispatch<br> }<br> <br> Unfortunately, this is what DMD had to say about this:<br> <br> C:\Users\g.gyolchanyan\<u></u>Desktop\test.d(3): Error: found &#39;This_&#3= 9; when<br> expecting &#39;)&#39;<br> C:\Users\g.gyolchanyan\<u></u>Desktop\test.d(3): Error: semicolon expected<= br> following function declaration<br> C:\Users\g.gyolchanyan\<u></u>Desktop\test.d(3): Error: Declaration expecte= d,<br> not &#39;)&#39;<br> <br> It looks like DMD thinks I was gonna write a postblit constructor and I<br> guess the functionality is already there, but can&#39;t be reached due to a= <br> parsing error.<br> </blockquote> <br></div></div> I haven&#39;t even thought about this use case. It would be so cool.<span c= lass=3D""><font color=3D"#888888"><br> <br> -- <br> /Jacob Carlborg<br> </font></span></blockquote></div><br>This would mean, that D can flawlessly= mix together static and dynamic typing to achieve maximum flexibility (usi= ng dynamic typing like this) and maximum performance (using static typing w= hen this isn&#39;t required).</div> <div class=3D"gmail_extra"><div style>No statically-typed and no dynamicall= y-typed language can combine flexibility and performance right now.</div><d= iv style>Combined with the upcoming revamp of D&#39;s compile-time and (bui= lt on top of it) run-time reflection, this will make D the ultimate modelin= g tool for building systems of arbitrary dynamicity and maximum performance= .</div> <div style><br></div><div style>By the way, what&#39;s up with the new refl= ection thing that Andrei once wrote about?</div><div style><br></div>-- <br=
Bye,<br>Gor Gyolchanyan.

--0015175886109aaa4604d62937f8--
Feb 20 2013
prev sibling next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 02/20/2013 03:37 PM, Gor Gyolchanyan wrote:
 ...

 Is there any change of this being fixed any time soon?
 ...

According to the online documentation it seems like it should work: http://dlang.org/template.html#TemplateThisParameter states: "TemplateThisParameters are used in member function templates to pick up the type of the this reference." http://dlang.org/class.html states: Classes consist of: ... * member functions ... * Constructors I guess just post it to bugzilla.
Feb 20 2013
parent reply Jacob Carlborg <doob me.com> writes:
On 2013-02-20 16:38, Gor Gyolchanyan wrote:

 http://d.puremagic.com/issues/show_bug.cgi?id=9551

 I really really hope this gets fixed soon, because my project is stuck
 because of this.

You can't pass the static type to the base class, just as a workaround? class Base (T) { } class Sub : Base!(Sub) { } -- /Jacob Carlborg
Feb 20 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-02-20 16:56, Gor Gyolchanyan wrote:
 This adds boilerplate, that I can't afford. I need to transparently add
 dynamic dispatch to classes and I can't modify all of them. Besides, I
 have had experience with this previously and it causes a ton of
 problems, because there's no way of making sure the static type is
 passed and its' the right one.

The compiler will make sure the a type is passed. You could add some constraints on the template type but it wouldn't be 100% bulletproof. class Base (T : Base) { } class Sub : Base!(Sub) { } -- /Jacob Carlborg
Feb 20 2013
prev sibling next sibling parent Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
--0015175cfd7ef6ed6204d629c0f5
Content-Type: text/plain; charset=UTF-8

On Wed, Feb 20, 2013 at 7:29 PM, Timon Gehr <timon.gehr gmx.ch> wrote:

 On 02/20/2013 03:37 PM, Gor Gyolchanyan wrote:

 ...


 Is there any change of this being fixed any time soon?
 ...

According to the online documentation it seems like it should work: http://dlang.org/template.**html#TemplateThisParameter<http://dlang.org/template.html#TemplateThisParameter>states: "TemplateThisParameters are used in member function templates to pick up the type of the this reference." http://dlang.org/class.html states: Classes consist of: ... * member functions ... * Constructors I guess just post it to bugzilla.

http://d.puremagic.com/issues/show_bug.cgi?id=9551 I really really hope this gets fixed soon, because my project is stuck because of this. -- Bye, Gor Gyolchanyan. --0015175cfd7ef6ed6204d629c0f5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">On Wed, Feb 20, 2013 at 7:29 PM, Timon Gehr <span dir=3D"l= tr">&lt;<a href=3D"mailto:timon.gehr gmx.ch" target=3D"_blank">timon.gehr g= mx.ch</a>&gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gma= il_quote"> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex">On 02/20/2013 03:37 PM, Gor Gyolchanyan wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex"> ...<div class=3D"im"><br> <br> Is there any change of this being fixed any time soon?<br></div> ...<br> </blockquote> <br> According to the online documentation it seems like it should work:<br> <br> <a href=3D"http://dlang.org/template.html#TemplateThisParameter" target=3D"= _blank">http://dlang.org/template.<u></u>html#TemplateThisParameter</a> sta= tes:<br> <br> &quot;TemplateThisParameters are used in member function templates to pick = up the type of the this reference.&quot;<br> <br> <a href=3D"http://dlang.org/class.html" target=3D"_blank">http://dlang.org/= class.html</a> states:<br> <br> Classes consist of:<br> =C2=A0 =C2=A0 ...<br> =C2=A0 =C2=A0 * member functions<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ...<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 * Constructors<br> <br> I guess just post it to bugzilla.<br> </blockquote></div><br><a href=3D"http://d.puremagic.com/issues/show_bug.cg= i?id=3D9551">http://d.puremagic.com/issues/show_bug.cgi?id=3D9551</a><br cl= ear=3D"all"><div><br></div><div style>I really really hope this gets fixed = soon, because my project is stuck because of this.</div> <div><br></div>-- <br>Bye,<br>Gor Gyolchanyan. </div></div> --0015175cfd7ef6ed6204d629c0f5--
Feb 20 2013
prev sibling next sibling parent Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
--0015174c1caa8cdec304d62a01d5
Content-Type: text/plain; charset=UTF-8

This adds boilerplate, that I can't afford. I need to transparently add
dynamic dispatch to classes and I can't modify all of them. Besides, I have
had experience with this previously and it causes a ton of problems,
because there's no way of making sure the static type is passed and its'
the right one.


On Wed, Feb 20, 2013 at 7:46 PM, Jacob Carlborg <doob me.com> wrote:

 On 2013-02-20 16:38, Gor Gyolchanyan wrote:

  http://d.puremagic.com/issues/**show_bug.cgi?id=9551<http://d.puremagic.com/issues/show_bug.cgi?id=9551>
 I really really hope this gets fixed soon, because my project is stuck
 because of this.

You can't pass the static type to the base class, just as a workaround? class Base (T) { } class Sub : Base!(Sub) { } -- /Jacob Carlborg

-- Bye, Gor Gyolchanyan. --0015174c1caa8cdec304d62a01d5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">This adds boilerplate, that I can&#39;t afford. I need to = transparently add dynamic dispatch to classes and I can&#39;t modify all of= them. Besides, I have had experience with this previously and it causes a = ton of problems, because there&#39;s no way of making sure the static type = is passed and its&#39; the right one.</div> <div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On Wed, Feb 2= 0, 2013 at 7:46 PM, Jacob Carlborg <span dir=3D"ltr">&lt;<a href=3D"mailto:= doob me.com" target=3D"_blank">doob me.com</a>&gt;</span> wrote:<br><blockq= uote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc = solid;padding-left:1ex"> <div class=3D"im">On 2013-02-20 16:38, Gor Gyolchanyan wrote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> <a href=3D"http://d.puremagic.com/issues/show_bug.cgi?id=3D9551" target=3D"= _blank">http://d.puremagic.com/issues/<u></u>show_bug.cgi?id=3D9551</a><br> <br> I really really hope this gets fixed soon, because my project is stuck<br> because of this.<br> </blockquote> <br></div> You can&#39;t pass the static type to the base class, just as a workaround?= <br> <br> class Base (T) { }<br> <br> class Sub : Base!(Sub) { }<span class=3D"HOEnZb"><font color=3D"#888888"><b= r> <br> -- <br> /Jacob Carlborg<br> </font></span></blockquote></div><br><br clear=3D"all"><div><br></div>-- <b= r>Bye,<br>Gor Gyolchanyan. </div> --0015174c1caa8cdec304d62a01d5--
Feb 20 2013
prev sibling next sibling parent kenji hara <k.hara.pg gmail.com> writes:
--f46d0434bea674c92a04d62a6180
Content-Type: text/plain; charset=UTF-8

Constructor should check its qualifier as a switch to select construction
strategy. It is described in TDPL, but it has not been yet implemented.

The combination of constructor and TemplateThisParameter would affect to
that not-implemented feature. As a conclusion, its semantics is YET NOT
DEFINED.

(Similar thing exists with "inout constructor". It is not also yet defined.)

Kenji Hara

2013/2/21 Gor Gyolchanyan <gor.f.gyolchanyan gmail.com>

 On Wed, Feb 20, 2013 at 7:29 PM, Timon Gehr <timon.gehr gmx.ch> wrote:

 On 02/20/2013 03:37 PM, Gor Gyolchanyan wrote:

 ...


 Is there any change of this being fixed any time soon?
 ...

According to the online documentation it seems like it should work: http://dlang.org/template.**html#TemplateThisParameter<http://dlang.org/template.html#TemplateThisParameter>states: "TemplateThisParameters are used in member function templates to pick up the type of the this reference." http://dlang.org/class.html states: Classes consist of: ... * member functions ... * Constructors I guess just post it to bugzilla.

http://d.puremagic.com/issues/show_bug.cgi?id=9551 I really really hope this gets fixed soon, because my project is stuck because of this. -- Bye, Gor Gyolchanyan.

--f46d0434bea674c92a04d62a6180 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra">Constructor should check its qu= alifier as a switch to select construction strategy. It is described in TDP= L, but it has not been yet implemented.</div><div class=3D"gmail_extra"><br=
</div>

arameter would affect to that not-implemented feature. As a conclusion, its= semantics is YET NOT DEFINED.</div><div class=3D"gmail_extra"><br></div><d= iv class=3D"gmail_extra" style> (Similar thing exists with &quot;inout constructor&quot;. It is not also ye= t defined.)</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_e= xtra">Kenji Hara<br><br><div class=3D"gmail_quote">2013/2/21 Gor Gyolchanya= n <span dir=3D"ltr">&lt;<a href=3D"mailto:gor.f.gyolchanyan gmail.com" targ= et=3D"_blank">gor.f.gyolchanyan gmail.com</a>&gt;</span><br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex"><div dir=3D"ltr"><div><div class=3D"h5">On Wed, Feb 20, 20= 13 at 7:29 PM, Timon Gehr <span dir=3D"ltr">&lt;<a href=3D"mailto:timon.geh= r gmx.ch" target=3D"_blank">timon.gehr gmx.ch</a>&gt;</span> wrote:<br> </div></div><div class=3D"gmail_extra"><div><div class=3D"h5"><div class=3D= "gmail_quote"> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex">On 02/20/2013 03:37 PM, Gor Gyolchanyan wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p= adding-left:1ex"> ...<div><br> <br> Is there any change of this being fixed any time soon?<br></div> ...<br> </blockquote> <br> According to the online documentation it seems like it should work:<br> <br> <a href=3D"http://dlang.org/template.html#TemplateThisParameter" target=3D"= _blank">http://dlang.org/template.<u></u>html#TemplateThisParameter</a> sta= tes:<br> <br> &quot;TemplateThisParameters are used in member function templates to pick = up the type of the this reference.&quot;<br> <br> <a href=3D"http://dlang.org/class.html" target=3D"_blank">http://dlang.org/= class.html</a> states:<br> <br> Classes consist of:<br> =C2=A0 =C2=A0 ...<br> =C2=A0 =C2=A0 * member functions<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ...<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 * Constructors<br> <br> I guess just post it to bugzilla.<br> </blockquote></div><br></div></div><a href=3D"http://d.puremagic.com/issues= /show_bug.cgi?id=3D9551" target=3D"_blank">http://d.puremagic.com/issues/sh= ow_bug.cgi?id=3D9551</a><br clear=3D"all"><div><br></div><div>I really real= ly hope this gets fixed soon, because my project is stuck because of this.<= /div> <span class=3D""><font color=3D"#888888"> <div><br></div>-- <br>Bye,<br>Gor Gyolchanyan. </font></span></div></div> </blockquote></div><br></div></div> --f46d0434bea674c92a04d62a6180--
Feb 20 2013
prev sibling parent "Igor Stepanov" <wazar.leollone yahoo.com> writes:
What about template this for compile-time constructing of structs 
(classes?)?
e.g.
struct BigDecimal
{
   this(string arg)
   {
     *this = str2Dec(arg);
   }
   template this(string arg)
   {
     enum this = str2Dec(arg);
   }

   static BigDecimal str2Dec(string arg) //can be evaluated at 
compile time
   {
     //...
   }
}

void main()
{
   string str = "42.24";
   BigDecimal num1 = str;//Calling constructor BigDecimal.this
   BigDecimal num2 = "3,1415926535 8979323846 2643383279 
5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 
3421170679 8214808651 3282306647 0938446095 5058223172 5359408128 
4811174502 8410270193 8521105559 6446229489 5493038196 4428810975 
6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 
4543266482 1339360726 0249141273 7245870066 0631558817 4881520920 
9628292540 9171536436 7892590360 0113305305 4882046652 1384146951 
9415116094 3305727036 5759591953 0921861173 8193261179"; 
//Calling template this at compile time.
}
Feb 20 2013