Static Foreach
Philippe Sigaud
philippe.sigaud at gmail.com
Sun Nov 24 11:42:11 PST 2013
On Sun, Nov 24, 2013 at 6:40 PM, Shammah Chancellor
<anonymous at coward.com> wrote:
> However, for non-string templates. They have to be written in a recursive
> form, which can be particularly difficult in some cases.
>
> template FooTemplate() //This code is totally made up and not meant
> to do anything useful, or necessarily be valid.
> {
> auto FooTemplate = TypeTuple!()
> static foreach(member, __traits( allMembers, someClass)
> {
> FooTemplate = TypeTuple!(FooTemplate,
> __traits(getMember, someClass, member));
> }
> }
>
> What's the consensis on something like this?
The consensus might well be 'use recursion' :) That's what I'd do in
your case. CT computation on types is a lot like functional
programming: recursion and immutability.
Another solution would be to construct you type as a string, and then mix it in.
More information about the Digitalmars-d
mailing list