Quantcast

for_each_point and lambda with reference-captures in MSVC10

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

for_each_point and lambda with reference-captures in MSVC10

Volker Schöch
Hi again,

Thank you for your quick and helpful comments on the other issues! boost::geometry::for_each_point does not work with lamda expressions that have a reference capture. For illustration, see the code and error message below.

This may be a peculiarity of MSVC10; at least boost::for_each seems to have some special code in place that seems to work around this very issue. I have no idea what you are going to do with this information... Maybe you can fix it for the compiler, or otherwise we have one more reason to look forward to MSVC11. Probably at least you want to make sure that this is in fact a compiler-specific problem.

Regards
   Volker


#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/mpl/int.hpp>
using namespace boost::geometry;

void Test_Compiles() {
        model::multi_polygon< model::polygon< model::point<int, 2, cs::cartesian> > > mp;
        for_each_point( mp, []( model::point<int, 2, cs::cartesian> p ) { set<0>(p, 1); } );
}

void Test_Compiles2() {
        int n;
        model::multi_polygon< model::polygon< model::point<int, 2, cs::cartesian> > > mp;
        for_each_point( mp, [n]( model::point<int, 2, cs::cartesian> p ) { set<0>(p, n); } );
}

void Test_Does_Not_Compile() {
        int n;
        model::multi_polygon< model::polygon< model::point<int, 2, cs::cartesian> > > mp;
        for_each_point( mp, [&n]( model::point<int, 2, cs::cartesian> p ) { set<0>(p, n); } );
}

Error 1 error C2582: 'operator =' function is unavailable in '`anonymous-namespace'::<lambda0>' c:\program files (x86)\microsoft visual studio 10.0\vc\boost_1_48_0\boost\geometry\multi\algorithms\for_each.hpp 54

--
Volker Schöch | [hidden email]
Senior Software Engineer

think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany
http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091

Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: for_each_point and lambda with reference-captures in MSVC10

Barend
Hi Volker,

On 9-2-2012 14:42, Volker Schöch wrote:
> Thank you for your quick and helpful comments on the other issues! boost::geometry::for_each_point does not work with lamda expressions that have a reference capture. For illustration, see the code and error message below.
>
> This may be a peculiarity of MSVC10; at least boost::for_each seems to have some special code in place that seems to work around this very issue. I have no idea what you are going to do with this information...

Include the parts that are compiling in the docs? It nicely illustrates
how it can be used.

To be honest I've never tried what you are doing now, and I'm glad to
see that it is basically working. The things which are not working can
be fixed later but we're not yet at that stage. Unless you're providing
a fix of course ;-)

One more thing, I did try to compile your input (which succeeds if I
comment the non-compiling stuff) and adapted it. It compiles and runs
but... the lambda does not have any effect. I.e. the geometry is
unaffected. So there are some additional problems.

Regards, Barend

_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: for_each_point and lambda with reference-captures in MSVC10

Barend
Hi Volker,

About my message a minute ago:

On 9-2-2012 19:41, Barend Gehrels wrote:
>
> One more thing, I did try to compile your input (which succeeds if I
> comment the non-compiling stuff) and adapted it. It compiles and runs
> but... the lambda does not have any effect. I.e. the geometry is
> unaffected. So there are some additional problems.

A bit sent to early - this was a tiny little problem with a missing
reference in your sample.

So now it compiles, runs and has the expected results. Attached my
version (also changed polygon to point but that is a minor detail).

For those who are curious: these are the results.
MULTIPOINT((1 1),(1 2),(1 3))
MULTIPOINT((5 1),(5 2),(5 3))

Nice sample, thanks.

Barend


_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry

volkers_lambda_sample.cpp (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: for_each_point and lambda with reference-captures in MSVC10

Volker Schöch
Barend,

Thanks for your nice reply, as always. You got me there: I quickly made up those simple illustrative examples and was careless about the effects. Just wanted to use the captured variable n somehow within the lambda. Sorry for setting you on the wrong track, will be more careful in the future.

Regards
   Volker

--
Volker Schöch | [hidden email]
Senior Software Engineer

think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany
http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091

Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Loading...