Afficher un message
Vieux 17/01/2008, 06h16   #8
Dennis Jones
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no-fail swap for char []'s


"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:CYKdnYVVzecMQxPanZ2dnUVZ_uyinZ2d@comcast.com. ..

> Make it a template, something like
>
> template<unsigned s> void strswap(char (&a1)[s], char (&a2)[s])
> {
> for (unsigned i = s; i-- > 0; )
> std::swap(a1[i], a2[i]);
> }


You know Victor, I was wondering if there was a nice way to do it with a
template. Okay, so let's say I use your template and do this:

class Test
{
char str[10];
void swap( Test &rhs )
{
strswap( str, rhs.str );
}
};

I am not very familiar with that syntax. You are using 's' as a value,
rather than a type. But since the size of the array is known at
compile-time, I presume then that the compiler is able to interpret the
value of 's' based on the argument(s) passed to it? If so, that's pretty
cool!

- Dennis


  Réponse avec citation
 
Page generated in 0,05041 seconds with 9 queries