I am misunderstanding something about using mixins for boilerplate code.

I've got a set of functions all of which do the same thing:

public static int fctn1() { return other.place.fctn1; }

I can't use a string mixin to generate the code:

template Function(string name)
{
  const char[] Function =
"public static int " ~ name ~ "() { return other.place." ~ name ~"; }";
}

struct S {
mixin (Function!("fctn1"));
}

Error: "cannot use a template to add field to aggregate S".

I can't use a template mixin:

mixin template Function(string name)
{
  const char[] Function =
"public static int " ~ name ~ "() { return other.module." ~ name ~"; }";
}

Error: mixin templates are not regular templates.

Is there a way to duplicate fctn1 with a different name each time?

Paul

Reply via email to