@safe(bool)
Guillaume Boucher via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 19 11:22:58 PDT 2017
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:
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);
});
}
More information about the Digitalmars-d
mailing list