POV-Ray : Newsgroups : povray.off-topic : You lose some... : Re: You lose some... Server Time
10 Oct 2024 03:08:28 EDT (-0400)
  Re: You lose some...  
From: Fredrik Eriksson
Date: 5 Oct 2008 07:49:31
Message: <op.uiju4thu7bxctx@e6600>
On Sun, 05 Oct 2008 06:42:07 +0200, Chris Cason  
<del### [at] deletethistoopovrayorg> wrote:
>
> If he wants brevity he could also code it like this:
>
>   for (int i = 0; i < c.size(); i++)
>     out.append(c[i] ? "1" : "0");
>
> which is just as valid and avoids running the if/else together.

The compiler would likely warn about the signed/unsigned comparison in the  
loop condition. The proper type for the index is Codeword::size_type.

He could also skip the conditional in the loop body entirely:


typedef std::vector<bool> Codeword;

std::string codeword( Codeword const& c )
{
	std::string out;

	for( Codeword::size_type i = 0; i < c.size(); ++i )
		out += ( '0' + int(c[i]) );

	return out;
}



-- 
FE


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.