Boost logo

Boost :

Subject: Re: [boost] [local] Help for the Alternatives section
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2011-03-27 11:20:59


On Sunday, March 27, 2011 05:38:23 PM Lorenzo Caminiti wrote:
> On Sun, Mar 27, 2011 at 10:04 AM, Thomas Heller
> <thom.heller_at_[hidden]> wrote:
> > On Saturday, March 26, 2011 11:19:46 PM Lorenzo Caminiti wrote:
> >> Hello all,
> >>
> >> I am updating Boost.Local docs and I could use a some help in getting
> >> the Alternatives section right
> >>
> >
http://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/boost_local/Alternatives.html
> >
> > I would really like to see the first row removed ...
> > All alternatives you describe are using C++ syntax ... I know what you mean.
But
> > all the examples use regular C++ syntax.
>
> I don't think think that Boost.Lambda and Boost.Phoenix use the usual
> C++ syntax to program the "function" body.

Usual is just a point of view.

> If you suggest a text different than "Program body using C++ syntax" I am
> happy to consider changing the title of the row but I think the row itself
> should remain there.
>
> This row indicates if the "function" body is programmed using the C++
> syntax that programmers normally use to program C++ function bodies
> (and not other C++ constructs).

Well, still misleading. It doesn't make it invalid or "unusual" C++ syntax.

We had this discussion before ... It is valid and legal C++. Both in syntax and
semantic.
The difference is that you need some extra function calls, pay attention to some
oddities etc. with phoenix and lambda. But it stays valid C++ syntax.

> This also has an effect on the type of compiler error messages that
> programmers will receive about their "function" body. For example, with
> Boost.Local programmers will receive the usual compiler error messages they
> receive when they miss-program a function body but with Boost.Lambda and
> Boost.Phoenix they will receive different compiler errors which they might be
> unfamiliar with.

> > Another thing what i really wonder is: You write that local classes can not
be
> > passed as a template parameter.
> > I don't really get the difference between the local class and Boost.Local.
> > What about this:
> >
> > int main() {
> > double sum = 0.0;
> > int factor = 10;
> >
> > struct add_impl {
> > double & sum;
> > int const& factor;
> > add_impl(double sum, int factor) : sum(sum), factor(factor) {}
> >
> > void operator()(double num) const
> > {
> > sum += factor * num;
> > std::clog << "Summed: " << sum << std::endl;
> > }
> > };
> >
> > boost::function<void(double)> add = add_impl(sum, factor);
>
> Your example compiles on MSVC but it does not compile on GCC. As far
> as I understand it, this is not standard ISO C++ because you cannot
> pass the local class as a template parameter (in this case to
> boost::function).
>
> $ g++ -Wall -Werror -I../../.. 01.cpp
> 01.cpp: In function ‘int main()’:
> 01.cpp:22: error: conversion from ‘main()::add_impl’ to non-scalar
> type ‘boost::function<void ()(double)>’ requested
>
> Can your example be made to compile on GCC and standard ISO C++?
>
> >
> > double nums[3] = {1, 2, 3};
> > std::for_each(nums, nums + 3, add);
>
> (A semicolumn was missing at the end of the for_each.)
>
> > return 0;
> > }

Doesn't seem to work ... anyway, what i wanted to know was how your
implementation is different from that, I understand that the code is invalid
cause function uses templates in the constructor ...

> > I would be happy if you sched some light on to why this isn't possible but
why
> > its possible with using your macros.
>
> Boost.Local uses this trick to pass local functions as template
> parameters: http://lists.boost.org/Archives/boost/2010/09/170888.php
> You can see how this trick is actually implemented by the library
> macros at:
http://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/boost_local/Implementation.html#boost_local.Implementation.local_functions

... doesn't really tell me anything, too verbose. And scattered with
implementations details. A small English prose like text would help here ...
probably.

So it works because add has some pure virtual base class as static type! Aha ...

> Thank you very much for your comments.
>
> --
> Lorenzo
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk