December 15, 2012
On 12/15/2012 08:57 PM, anonymous wrote:
> Note that here s1alpha and s2alpha are distinct types.

what about this: http://dpaste.dzfl.pl/95f7a74d

regards,
r_m_r

December 15, 2012
On 12/10/2012 01:24 AM, js.mdnq wrote:
> which will fail or not be what I want, since I want to generate the
> structs s1 and s1.

how about this: http://dpaste.dzfl.pl/c0325def

regards,
r_m_r
December 15, 2012
On Saturday, 15 December 2012 at 19:09:25 UTC, r_m_r wrote:
> On 12/10/2012 01:24 AM, js.mdnq wrote:
>> which will fail or not be what I want, since I want to generate the
>> structs s1 and s1.
>
> how about this: http://dpaste.dzfl.pl/c0325def
>
> regards,
> r_m_r

Cool, That looks like a  step in the right direction.

Now, the next step is to be able to "insert" code into the struct! ;)

If we can get the template as a string then it can be parsed and code can be inserted, and we can also then do away with the alias and just change the name directly.

Also, maybe declaring the template as static would be better?
December 15, 2012
On 12/16/2012 04:00 AM, js.mdnq wrote:
> Now, the next step is to be able to "insert" code into the struct! ;)

how about this: http://dpaste.dzfl.pl/8161d00a

regards,
r_m_r
December 16, 2012
On Saturday, 15 December 2012 at 23:04:37 UTC, r_m_r wrote:
> On 12/16/2012 04:00 AM, js.mdnq wrote:
>> Now, the next step is to be able to "insert" code into the struct! ;)
>
> how about this: http://dpaste.dzfl.pl/8161d00a
>
> regards,
> r_m_r

No, it's backwards! ;)

Or, sort of what one wants to do is:

template MasterStruct_A(alias f, string c = "")
{
	enum F = f;
	
	struct S
	{
		int X;
		int Y;
		
		this(int x, int y) { X = x; Y= y; }
		
		mixin (c);
	}
}

template UserStruct(alias f)
{
	enum F = f;
	
	struct S
	{
		int A;
		int B;	
	}
}

and mixin the UserStruct.S with the MasterStruct_A

something like

mixin (genStruct!(MasterStruct_A, UserStruct, "s3");

which is equivalent of to the following

	struct S
	{
		int X;
		int Y;
		
		this(int x, int y) { X = x; Y= y; }
		
                int A;
                int B;
	}

S s3;

This, then basically adds the ability to do partial structs(or classes) relatively easily(although not as easy if the compiler did it automatically).
December 16, 2012
On 12/16/2012 05:30 AM, js.mdnq wrote:
> and mixin the UserStruct.S with the MasterStruct_A

this is the closest I can get: http://dpaste.dzfl.pl/9d11d060

regards,
r_m_r

December 16, 2012
On 12/16/2012 06:36 AM, r_m_r wrote:
> this is the closest I can get: http://dpaste.dzfl.pl/9d11d060

Cleaned up a bit: http://dpaste.dzfl.pl/d9f001db

regards,
r_m_r
December 16, 2012
On Saturday, 15 December 2012 at 16:32:27 UTC, r_m_r wrote:
> On 12/15/2012 08:57 PM, anonymous wrote:
>> Note that here s1alpha and s2alpha are distinct types.
>
> what about this: http://dpaste.dzfl.pl/95f7a74d

Consider

struct Foo {mixin (genStruct!("s1"));}
struct Bar {mixin (genStruct!("s1"));}

Foo.s1alpha and Bar.s1alpha are the same type. In my version they are not.
December 16, 2012
On 12/16/2012 12:08 PM, anonymous wrote:
> Foo.s1alpha and Bar.s1alpha are the same type. In my version they are not.

OK. Fair Enough :-)
December 16, 2012
On Sunday, 16 December 2012 at 01:32:44 UTC, r_m_r wrote:
> On 12/16/2012 06:36 AM, r_m_r wrote:
>> this is the closest I can get: http://dpaste.dzfl.pl/9d11d060
>
> Cleaned up a bit: http://dpaste.dzfl.pl/d9f001db
>
> regards,
> r_m_r

That looks like it might be pretty close. I was also thinking that one could just use mixin templates of trying to do it with structs directly.

I think it is the right approach but the code as is will not work with additional type parameters from MasterStruct and UserStruct. I ran into the same issues in my nested struct code:

http://dpaste.dzfl.pl/64025e0a

Where I had to pass the types as strings and then append the hidden parameter.

Possibly you could try to figure out how to solve this problem? Maybe there is a better way then doing it with strings. (it would be real nice if I there was a compile time construct for this. like "me" or something that would return type info inside the current scope.

class A(T) { this() { writeln(me.typeinfo.name); }

would print "A(T)".

(of course me is probably a bad name but just an example :)

I'll be using your code soon once it works with multiple template parameters. (I'll make the changes if you don't)

Thanks.