Hi Nicolas,

I second your opinion. I think CMake is a bit ambiguous in this sense.
List indices are zero-based, which clearly shows a C++ implementation
background. On the other hand, range intervals are closed both at the
beginning and the end, which is not like C++, nor like, e.g., Python,
but more like one-based languages like Fortran and Pascal.

In cases like this I revert to something like this:

LIST(LENGTH mylist count)
WHILE(index LESS count)
  LIST(GET ${mylist} ${index} item)
  MATH(EXPR index "${index}+1")
WHILE(index LESS count)

Cumbersome, but it works.

Best regards,
Marcel Loose.

-----Original Message-----
From: Nicolas Desprès <[email protected]>
To: Hendrik Sattler <[email protected]>
Cc: [email protected]
Subject: Re: [CMake] doing simple math in cmake or useless
foreach( RANGE )
Date: Tue, 19 May 2009 23:38:05 -0300

On Tue, May 19, 2009 at 6:29 PM, Hendrik Sattler
<[email protected]> wrote:

>
> If that's not present, I do not understand how
> LIST( LENGTH MYLIST COUNT )
> FOREACH ( index RANGE ${COUNT} )
> list ( GET MYLIST ${index} entry )
> ....
>
> will address non-present indexes in the list. I would the above statement
> cover the range from 0 to COUNT-1 but it also cover COUNT itself like said in
> the documentation. Does that actually make sense as the variable in the
> documentation is called "total" but the loop count is "total+1"?
>

I also experienced this problem and I don't like this behavior. I'm
more use to the traditional

for (i = 0; i < n; ++i)

instead of <=



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to