[PPL-devel] [GIT] ppl/ppl(master): Fixed some warnings.

Anthony Foiani anthony.foiani at gmail.com
Mon Jun 6 21:06:44 CEST 2011

Abramo, greetings again!

On Mon, Jun 6, 2011 at 8:35 AM, Abramo Bagnara <abramo.bagnara at gmail.com> wrote:
> Fixed some warnings.

> diff --git a/src/Grid_public.cc b/src/Grid_public.cc
> index 47b8437..82e64a3 100644
> --- a/src/Grid_public.cc
> +++ b/src/Grid_public.cc
> @@ -2735,7 +2735,7 @@ PPL::Grid::wrap_assign(const Variables_Set& vars,
>     for (Variables_Set::const_iterator i = vars.begin(),
> -           vars_end = vars.end(); i != vars.end(); ++i) {
> +           vars_end = vars.end(); i != vars_end; ++i) {
>       const Variable x = Variable(*i);
>       // Find the frequency and a value for `x' in `gr'.
>       if (!gr.frequency_no_check(x, f_n, f_d, v_n, v_d))

Have you considered using BOOST_FOREACH or something similar here? It
should allow you to replace that loop header with something as simple

  BOOST_FOREACH( Variables_Set::const_iterator i, vars ) { ...

It even allows for iterating using references, which would remove the
initial assignment in that loop:

  BOOST_FOREACH( const Variable & x, vars ) { ...

The author of BOOST_FOREACH goes into excruciating detail in this article:


I don't know if you want to drag in BOOST_FOREACH in particular,
though; I believe it relies on Boost.Range, and there may or may not
be issues with shipping Boost-licensed code within the GPL'd PPL.

It's easy enough to cook one up to match the first usage; it's not
perfect (evaluates collection argument twice) but might be worth
looking into:

    for ( TYPE ITER       = COLLECTION.begin(), \
               ITER##_end = COLLECTION.end();   \
          ITER != ITER##_end;                   \
          ++ITER )

And, of course, this will all go away when C++0x is fully supported.  :-/

(Having said that, g++ should support the new "for" syntax as of 4.6,
so perhaps using the FOREACH macro and conditionalizing it on the
basis of g++ version or other indicator of C++0x support might
actually be a reasonable thing to do...)

Hope you find this interesting.

Thanks once again for the great work on the library!

Best regards,
Anthony Foiani

More information about the PPL-devel mailing list