Boost logo

Boost :

Subject: Re: [boost] Case study: Boost.Local versus Boost.Phoenix
From: Artyom (artyomtnk_at_[hidden])
Date: 2011-02-04 07:35:53

> From: Gregory Crosswhite <gcross_at_[hidden]>
> Hey everyone,
> This e-mail is going to be a case study of my personal experience in
>converting code
> using Boost.Local to use Boost.Phoenix instead in order to get insight into
> similarities and differences in what the libraries have to offer.
> [snip]
> (void) (checkSolution)(
> (const StandardFormParameters&)(parameters)
> (const OperatorSpace&)(space)
> )
> ) {
> checkRegion(Z,space.getOMatrix().slice(
> parameters.z_bit_diagonal_size
> ,space.number_of_qubits
> ,0u
> ,space.number_of_operators
> ));
> forEachStandardFormSolution(
> number_of_qubits
> ,number_of_operators
> ,list_of(EveryColumnHasZ)
> ,checkSolution
> );

I'm sorry is it only me or it would be much more readable
and maintainable to write:

namespace {
   struct my_lambda {
       foo_type &foo;
       bar_type &bar
       my_lambda(foo_type &local_foo,bar_type &local_bar) :

       void operator()(a_type a) const
             /// Your body goes there

void my_function()
    foo_type foo;
    bar_type bar;

    my_lambda lambda(foo,bar);
    // or something else

I understand that Pheonix and boost::lambda are very useful
in certain situations but am I only person who thinks
that if you need some little bit more complicated lambda
function you just create a small class with operator()
which would be

1. Much More readable
2. Clear for source code maintainers who not familiar with some boost toolkits
3. Easier to debug and see compiler's error messages
4. Be friendlier to less experienced C++ programmers who would
   have to maintain this horrible code?

Am I the only person there who thinks that such constructions
are "write-only" and don't provide real benifit?

I do like and use boost::bind, boost::lambda and some other simple
construction that can be written in a single like and what is
most important improve programmer's productivity but I really
fail to see it in this case.

I think that for complex cases it is much better to write a class
with operator() (till we have C++0x) and make:

- compiler happy and handle it fast
- maintainer happy to be able to actually understand what
  does the code do without reading Boost.Pheonix or Boost.Local
  manuals for 5 hours.



Boost list run by bdawes at, gregod at, cpdaniel at, john at