 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
André Kempe Guest
|
Posted: Sat Aug 27, 2005 7:29 pm Post subject: Template Parameter Issue |
|
|
Hi,
I have the following problem with template-parameters under Visual
Studio 6.0.
I have to add an incrementing value to a range of elements, that means I
have an iterator it , it in ]begin;begin+size], and want to add to each
and every element of that range *it += distance(begin,it)*value.
I wrote a simple template function for that, the size is provided as a
template-parameter, since the application is somewhat short of runtime .
template< unsigned size , class InputIt , class T >
void
incrementing_add( InputIt begin , T value );
I use it for arrays of varying size, and I had a bunch of problems with
that function, since it never worked the way I expected. When I finally
had a look at the assembler-code the compiler produced, I discovered
that when I use 2 for size, and in a later call 3 ( other
template-paramters remain the same ), it produces code that *always*
compares against size 2!
I use I this way, i.e.:
incrementing_add< 3 >( int* , 512 );
Is there something I am missing about explicit template-parameters? Or
have i met just another microsoft-speciality??
Greetings & TIA
André
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kaufmann@cs.uni-potsdam.d Guest
|
Posted: Sun Aug 28, 2005 1:36 pm Post subject: Re: Template Parameter Issue |
|
|
| Quote: | I have the following problem with template-parameters under Visual
Studio 6.0.
I have to add an incrementing value to a range of elements, that means I
have an iterator it , it in ]begin;begin+size], and want to add to each
and every element of that range *it += distance(begin,it)*value.
I wrote a simple template function for that, the size is provided as a
template-parameter, since the application is somewhat short of runtime .
template< unsigned size , class InputIt , class T
void
incrementing_add( InputIt begin , T value );
I use it for arrays of varying size, and I had a bunch of problems with
that function, since it never worked the way I expected. When I finally
had a look at the assembler-code the compiler produced, I discovered
that when I use 2 for size, and in a later call 3 ( other
template-paramters remain the same ), it produces code that *always*
compares against size 2!
I use I this way, i.e.:
incrementing_add< 3 >( int* , 512 );
Is there something I am missing about explicit template-parameters? Or
have i met just another microsoft-speciality??
|
That is a bug in the MSVC 6.0
See: http://support.microsoft.com/kb/240871/EN-US/
To workaround this problem you can add a default-parameter to the
function that depends on the non-type parameter size.
E.g.
template <int size>
struct Workaround {};
template< unsigned size , class InputIt , class T >
void
incrementing_add( InputIt begin , T value, Workaround<size>* = 0);
That should do the trick.
Regards,
- Ben
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|