Is there a way to mixin function names (or for the matter any kind of member names) other than mixin strings?
I'm currently doing it like this:
mixin template PacketValue(T, string name, PacketMode mode, size_t offset) {
import std.string : format;
static if (mode == PacketMode.both || mode == PacketMode.write) {
enum writePacketFormat = "void %s(T value) { write!T(value, offset); }";
mixin(format(writePacketFormat, name));
}
static if (mode == PacketMode.both || mode == PacketMode.read) {
enum readPacketFormat = "auto %s() { return read!T(offset); }";
mixin(format(readPacketFormat, name));
}
}
And it's used ex. like this:
class WritePacket : Packet!(PacketMode.write) {
public:
this(ushort size) {
super(cast(ushort)1001, cast(ushort)(4 + size));
}
@property {
mixin PacketValue!(uint, "value1", PacketMode.write, 4);
mixin PacketValue!(uint, "value2", PacketMode.write, 8);
mixin PacketValue!(ushort, "value3", PacketMode.write, 12);
}
}
Where "value1", "value2" and "value3" will be the function names. In this case property functions.
I was just curious whether there's a better way to achieve this or not.