instantiate each of a tuple of templates (Take 2)
John Colvin
john.loughran.colvin at gmail.com
Thu Aug 1 08:13:13 PDT 2013
On Thursday, 1 August 2013 at 15:06:50 UTC, Artur Skawina wrote:
> On 08/01/13 14:50, John Colvin wrote:
>> template a(T ...)
>> {
>> void a(R r)
>> {
>> //want to get a tuple of
>> //the members of T, each
>> //instantiated with R.
>>
>> //do some RT stuff
>> }
>> }
>>
>> Is this possible?
>>
>> Whatever I try, I keep running in to "cannot use local as
>> parameter to non-global template" errors, which I understand
>> is to do with context pointers
>> However, this is all compile-time work based entirely on
>> types, there should be no need for any context pointers.
>>
>
> Always post real and complete (even if not working) code, as
> figuring out
> what the problem is can be harder than giving the solution...
>
>
> template RealTuple(A...) { alias RealTuple = A; }
> template a(T ...)
> {
> auto a(R)(R r)
> {
> //want to get a tuple of
> //the members of T, each
> //instantiated with R.
>
> mixin({
> string m;
> foreach (I, _; T)
> m ~= "alias UGH"~I.stringof~" =
> T["~I.stringof~"];\n";
> m ~= "alias TupleofTsBangR = RealTuple!(";
> foreach (I, _; T)
> m ~= (I?", ":"") ~ "UGH"~I.stringof~"!R";
> return m ~ ");";
> }());
>
> // do some RT stuff
>
> TupleofTsBangR x;
> foreach (I, _; typeof(x))
> x[I] = r;
>
> // etc
>
> import std.typecons;
> return tuple(x);
> }
> }
>
> (If this is what you were actually looking for then I hope
> somebody
> else has another solution; this approach is just too ugly...)
>
> artur
sorry yeah I didnt think the question through before asking. I'm
normally the one nagging for better example code when people ask
questions!
I did consider wading through everything with string mixins etc.
but it seemed like a lot of effort for what (on the surface) is a
simple problem.
Anyhow, please see my response to monarch_dodra as I've revised
my question somewhat
More information about the Digitalmars-d-learn
mailing list