templates
Philippe Sigaud
philippe.sigaud at gmail.com
Mon Apr 19 11:38:46 PDT 2010
On Mon, Apr 19, 2010 at 20:16, Ellery Newcomer
<ellery-newcomer at utulsa.edu>wrote:
> Hello.
>
> Say I have a [struct] template T, which takes a param S.
>
> Any T!(S) satisfies a certain template constraint W, so I can use any T!(S)
> the same way. I want to be able to store heterogeneous T!(S) in a single
> list. Is there any good way to express the type for this?
>
So, you have
struct S(T) {}
and W!(S!T)) is true, whatever T is. Right?
S!T is a type by itself, different from S!U, S!V, ... So I'm afraid there is
no direct way to store them in an array. S by itself is not a type nor a
struct, it's code waiting to be instantiated.
Maybe you could use Variant to hide the inner type away, and do an array of
S!Variant. But then, there is no easy way to get back the type inside the
variant.
Another solution is to use a TypeTuple or a Tuple:
import std.traits;
struct SList(Ss...) if (allSatisfy!(W, Ss))
{
Ss theList;
}
I'm using W as a predicate here.
Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100419/4c778002/attachment.html>
More information about the Digitalmars-d-learn
mailing list