Dynamic Ctors ?

Voitech via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 8 00:58:41 PST 2016


On Monday, 8 February 2016 at 07:08:58 UTC, Voitech wrote:
> On Saturday, 6 February 2016 at 23:35:17 UTC, Ali Çehreli wrote:
>> On 02/06/2016 10:05 AM, Voitech wrote:
>>
>> > [...]
>>
>> You can use string mixins (makeCtor and makeCtors):
>>
>> string makeCtor(T)() {
>>     import std.string : format;
>>
>> [...]
>
> Thank you very much for answering.
> Cheers

Unfortunately this doesn't work as I'am trying to assign value 
from ctor to member something like:

this(%s value){
     this.value=value;
}

it gives me
Error: memcpy cannot be interpreted at compile time, because it 
has no available source code.
Probably this is caused by declaration of member which is also 
parametrized with T...
Member is:
Algebraic!(T) value;

So declaration of this mixin constructors are done before 
variable value is declared (compilation)?

Is there any field in class that would contain ctors ? Something 
like __ctors ?
i could try to init this(T... value) constructors in static 
constructor using delegates/functions. Something like:

template Outer(T...){
class Inner{
		Algebraic!(T) value;

		alias ctor(Type) =Inner delegate (Type value);
		static this(){
			foreach(Type;T){
				ctor!(Type) c={
					this.value=value;
				};
                         __ctors~=c; // ?????
			}

		}

}









More information about the Digitalmars-d-learn mailing list