On Saturday, 19 August 2017 at 18:22:58 UTC, Guillaume Boucher
wrote:
On Thursday, 17 August 2017 at 16:32:20 UTC, bitwise wrote:
In a high-performance context though, the performance hit may
be unacceptable.
Well in those super rare situations, there's always the
workaround with mixins:
Those situations are not rare.
mixin template funcWithAttr(string decl, string attributes,
string code) {
pragma(msg, "<<<" ~ code ~ ">>>");
mixin(decl ~ attributes ~ "{" ~ code ~" }");
}
struct Container(T, bool safetyOn = true)
{
static if(safe)
RefCounted!(T[]) data;
else
T[] data;
mixin funcWithAttr!("auto opSlice()", safetyOn ? "@safe" : "",
q{
return Range(data, 0, data.length);
});
}
Really?