Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: CPP related question on double code (B/W)

Author: Sven Reichard

Date: 06:24:58 11/24/03

Go up one level in this thread


On November 24, 2003 at 08:58:44, Reinhard Scharnagl wrote:

>Hi Daniel,
>
>On November 24, 2003 at 08:52:13, Daniel Clausen wrote:
>
>[...]
>
>>The formal parameter of a template can either be a type parameter (like int,
>>float, class XY, etc) or a constant expression. The example below illustrates
>>the 2nd case:
>>
>>
>>#include <iostream>
>>
>>template <int colour> void print(void)
>>{
>>   std::cout << colour << std::endl;
>>}
>>
>>int main(void)
>>{
>>   print<0>();
>>   print<1>();
>>
>>   return 0;
>>}
>
>>Maybe that could help?
>
>This seems to lead into the right direction! So I will try to
>solve my problem with this special type of template.
>
>Thank you, Reinhard.

Hallo Reinhard,

maybe I still don't understand exactly what you want to avoid. The solution
above leads to a multiplication of code, since for each color a different
procedure is generated by the compiler. If you pass the color as a parameter
(and not as a template parameter), only one function is generated, unless you
declare it as inline, when no function is generated.

In both cases, there is no duplication in the source code, which of course
should be avoided. However, I think you also want to avoid duplication in the
generated code, which implies passing the color as a usual parameter.

Maybe you could reformulate your requirements?

Sven.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.