Method template optimization that works in C++, but not very well D

Vladimir v.s.zverev at gmail.com
Wed Feb 19 22:18:31 PST 2014


> I would like to understand the request first. Neither 
> ProccessRow() nor OptimizedProcessTable() take isUseField as 
> template parameters. Besides, isUseField is generated at 
> runtime. No, I don't understand. :)

Yes, isUseField is generated at runtime. For example, user can 
select the column that he want to sort. And he chose the first 
column. This means that isUseField[0] = true; isUseField[1] = 
false. The function getIndex must return 1. And want to call 
compile-time generated function

proccessRow_1 (..)
{
   //do something only with the field1 without additional checks.
}

instead of full version proccessRow. I admit that too much 
simplified example.


> Can you show the C++ code perhaps on a simpler task? I would 
> expect D's compile-time features to be superior to C++'s in all 
> cases. (And I would like to be educated if it is not so. :) )

My example is a simplification of this 
https://github.com/AlexeyAB/cpp_find_order/blob/06a80340ff403c4693bfe0ff8b80584f029c71a3/main.cpp.
I gave a link to the most simple implementation of the three 
versions of the program. Code looked slightly horrible for me at 
first:)

> > Or may be, this optimization is meaningless in D...?
>
> I doubt it.
>
I also doubt it.

>Full version my very simplified example such task:  
>https://gist.github.com/Vladimir-Z/1a1755ce91cb0e7636b5


More information about the Digitalmars-d-learn mailing list