Problem: Cannot create class out of nothing using witchcraft

Artur Skawina art.08.09 at gmail.com
Tue Oct 15 06:37:58 PDT 2013


On 10/15/13 10:03, DoctorCaptain wrote:
> If what I am asking is unclear, I will be more than happy to
> explain in a different way. I tried to be simultaneously as
> succinct and as comprehensive as possible with what the issue is.
 
I'm not sure what exactly you're trying to do, but...

The issue is just that you are trying to access types that are
not available inside the GrabBagT template. With /built-in/ types
this of course works, as 'int' etc are always known.
One way to deal with that would be:

   template GrabBagT(string className, T...)
        if (allSatisfy!(isChildOrBaseClass, T))
   {
        mixin(genClassStr!(T.length)(className));
   }

   string genClassStr(size_t TL)(string className)
   {
        string classStr = "";
        classStr ~= `static class ` ~ className ~ ` : BaseClass`;
        classStr ~= `{`;
        // Demonstrate that the template itself is not the problem
        classStr ~= `    ChildT!("BestChild").BestChild t1000;`;
        // Add arbitrary data members
        foreach (i; 0..TL)
            classStr ~= "T["~ to!(string)(i) ~ `] t` ~ to!(string)(i) ~ `;`;
        classStr ~= `    void printAttempts() {`;
        foreach (i; 0..TL)
            classStr ~= `    writeln(` ~ to!string(i) ~ `);`;
        classStr ~= `    }`;
        classStr ~= `}`;
        return classStr;
   }

artur


More information about the Digitalmars-d-learn mailing list