Convert mixin to function call

IntegratedDimensions IntegratedDimensions at gmail.com
Sun May 20 20:22:14 UTC 2018


https://dpaste.dzfl.pl/fb49bf834cff

import std.stdio;

auto Q(string A)()
{
	auto foo()
	{
		auto d = mixin(Z!(A)());
		return d;
	}
	return foo()();
}

auto X(string A, string N)()
{
	return N~" = (() { int y = 4;  return "~A~" + y + 5; })();";
}

auto Z(string A)()
{
	return "() { int y = 4;  return "~A~" + y + 5; }";
}


void main()
{
	int x = 3;
	double y = 0;
	pragma(msg, (X!("x", "y")()));
	mixin(X!("x", "y")());
	y = Q!("x")();
	
	writeln(y);
}

using Q is more ideomatic but foo does not have access to x which 
is required(since Q should behave like a string mixin as far as 
scope is concerned).



More information about the Digitalmars-d-learn mailing list