No constructor for a templated class?

Philippe Sigaud philippe.sigaud at gmail.com
Sun Jul 25 15:46:32 PDT 2010


On Mon, Jul 26, 2010 at 00:00, Mafi <mafi at example.org> wrote:

> Am 25.07.2010 14:55, schrieb Philippe Sigaud:
>
>  OK, I must be tired, I don't know.
>> While switching from a template struct to a templated class, I got the
>> following problem:
>>
>> class A(T)
>> {
>>     T _t;
>>     this(U)(U u) if (is(U == T))
>>     {
>>         _t = u;
>>     }
>> }
>>
>
> Probably this case is reduced, but anyways:
> Having a template(U) where U must be == T (another template parameter) is
> complettly useless. Maybe I'm missing something but isn't this equivalent to
> the above:
>
> class A(T)
>  {
>      T _t;
>      this(T u)
>      {
>          _t = u;
>      }
>  }
>
>
Yes, to original case is much more complicated. In fact, it may well be the
most complicated template constraint I've ever build. It's five lines long
and invoke somthing like four other templates.

It worked for struct A. That's switching to class A that killed everything
:-(

I've a templated Graph struct, templated on Node and Edge (which may very
well be templated types themselves, as the user wish). A very handy
constructor, invoked by a factory function,  is one taking any number of
nodes and edges, checking their compatibility, deducing common properties at
compile-time and then constructing the graph.

Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100726/c2db5e92/attachment.html>


More information about the Digitalmars-d-learn mailing list