Boost logo

Boost Users :

Subject: Re: [Boost-users] Fwd: Boost.Range: 'Use of deleted function' GCC error when using lambdas
From: Daniel Hofmann (daniel_at_[hidden])
Date: 2016-09-05 04:59:49


On 09/01/2016 05:48 PM, Remko Tronçon wrote:
> Hi,
>
> I have the following piece of code:
>
> std::vector<std::string> list1;
> std::vector<std::string> list2;
> push_back(list2, list1
> | transformed([](const auto& w) { return w; })
> | sliced(0, 1));
>
> This compiles fine with CLang, but with GCC I get the error:
>
> /usr/include/boost/optional/optional.hpp:546:64: error: use of
> deleted function 'main(int, const char**)::<lambda(const auto:1&)>&
> main(int, const char**)::<lambda(const auto:1&)>::operator=(const
> main(int, const char**)::<lambda(const auto:1&)>&)'
> void assign_value ( rval_reference_type val ) { get_impl() =
> static_cast<rval_reference_type>(val); }
>
>
> ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> main.cpp:46:19: note: a lambda closure type has a deleted copy
> assignment operator
> | transformed([](const auto& w) { return w; })
>
>
> When I replace the lambda by a regular function, the code compiles; when
> I don't use 'sliced' (but pipe it to e.g. 'transformed' instead), the
> code also compiles.
>
> Is there a way to make this code compile with a lambda?

You can work around that using the unary plus in order to explicitely
trigger the implicit convertion from your capture-less lambda to a
function pointer.

  list1
    | transformed(+[](const std::string& w) { return w; })
    | sliced(0, 1);

This is a workaround, though. I still think your original problem is an
issue in the Boost.Range library and should be properly fixed there.

> thanks!
> Remko
>
> PS: I'm using GCC 6.2.0 with Boost 1.61.
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net