LNK2019 error from using a function pointer to core.bitop functions?

Matthew Gamble via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 17 11:57:28 PDT 2015


On Friday, 17 July 2015 at 15:49:46 UTC, Roland Hadinger wrote:
> On Friday, 17 July 2015 at 15:47:39 UTC, Roland Hadinger wrote:
>> Otherwise, I'd use templates and an alias. Maybe this will 
>> result in faster code:
>>
>>     bool opIndexAssign(bool value, size_t[2] inds)
>>     {
>>         void impl(bool b)(size_t[2] inds)
>>         {
>>             static if(b)
>>                 alias btx = bts;
>>             else
>>                 alias btx = btr;
>>
>>             // code from opIndexAssign goes here...
>>             // for (size_t i = startBitInd; ...
>>         }
>>
>>         if( value )
>>             impl!true(inds);
>>         else
>>             impl!false(inds);
>
>           return value; // oops
>>     }

Roland, both of your solutions work perfectly. Thank you.

You brought up the issue of performance. Performance may be an 
issue for certain use-cases when the function is called many 
times and the values of inds[1] - inds[0] is small (e.g less than 
257). In these cases at least half the work in the function will 
be done with bts/btr. However, for larger ranges there is an 
optimization (not shown) that eliminates the need to call bts/btr 
in the middle region of the range.

Why do you think the second solution would be faster than the 
first? And do you also think that the rolled out version 
replicating the code in the "if" and "else" blocks replacing bts 
with btr would be even faster since it eliminates the need for 
any additional function call? I guess I'll have to profile all 
three versions when my program matures enough be used with a 
"big" data example.

Sorry for all the questions. I really appreciate your help.

Best, Matt


More information about the Digitalmars-d-learn mailing list