0 cost template instantiation
jfondren
julian.fondren at gmail.com
Thu Sep 30 02:22:35 UTC 2021
On Thursday, 30 September 2021 at 01:44:57 UTC, jfondren wrote:
> On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote:
>> I have a template function that all it does is given a symbol,
>> it loads a dll for its type + its name:
>>
>> ```
>> void loadSymbol(alias s, string symName = "")()
>> {
>> static if(symName == "")
>> s = cast(typeof(s))_loadSymbol(_dll, (s.stringof~"\0").ptr);
>> else
>> s = cast(typeof(s))_loadSymbol(_dll, (symName~"\0").ptr);
>> }
>> ```
>
> If symName is always a string literal, then you don't need to
> append a "\0"; string literals always have a trailing NUL after
> them, and they autoconvert to const(char)[] so you don't need
> the .ptr either.
Playing around with this, with a mock-up of your code, doesn't
change object size at all.
Is the actual source available, that you're seeing this with?
More information about the Digitalmars-d-learn
mailing list