Boost.TypeErasure: подвижный функтор

поскольку std::function требует семантики копирования и захваченная лямбда не может быть преобразована в std::functionЯ пытаюсь определить подвижную функцию, используя boost.TypeErasure. Все в порядке, пока не потребуется оператор присваивания перемещения.

#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/constructible.hpp>
#include <boost/type_erasure/callable.hpp>
#include <boost/type_erasure/builtin.hpp>
#include <boost/mpl/vector.hpp>

namespace bte = boost::type_erasure;
namespace bm = boost::mpl;

using Foo = bte::any<
bm::vector<
bte::constructible<bte::_self(bte::_self&&)>,
bte::assignable<bte::_self, bte::_self&&>,
bte::destructible<>,
bte::callable<void()>
>
>;

int main()
{
Foo{[&]{}};
}

С gcc ошибка компиляции:

In file included from /usr/local/include/boost/type_erasure/detail/normalize.hpp:34,

from /usr/local/include/boost/type_erasure/any.hpp:36,

from main.cpp:1:

/usr/local/include/boost/type_erasure/builtin.hpp: In instantiation of 'static void boost::type_erasure::assignable<T, U>::apply(T&, const U&) [with T = main()::<lambda()>; U = main()::<lambda()>&&]':

/usr/local/include/boost/type_erasure/detail/instantiate.hpp:91:9:   required from 'static void boost::type_erasure::detail::instantiate_concept4::apply(Concept*, Map*) [with Concept = boost::mpl::vector<boost::type_erasure::constructible<boost::type_erasure::_self(boost::type_erasure::_self&&)>, boost::type_erasure::assignable<boost::type_erasure::_self, boost::type_erasure::_self&&>, boost::type_erasure::destructible<>, boost::type_erasure::callable<void()> >; Map = boost::mpl::map1<boost::mpl::pair<boost::type_erasure::_self, main()::<lambda()> > >]'

/usr/local/include/boost/type_erasure/any.hpp:225:13:   required from 'boost::type_erasure::any<Concept, T>::any(U&&) [with U = main()::<lambda()>; Concept = boost::mpl::vector<boost::type_erasure::constructible<boost::type_erasure::_self(boost::type_erasure::_self&&)>, boost::type_erasure::assignable<boost::type_erasure::_self, boost::type_erasure::_self&&>, boost::type_erasure::destructible<>, boost::type_erasure::callable<void()> >; T = boost::type_erasure::_self]'

main.cpp:21:14:   required from here

/usr/local/include/boost/type_erasure/builtin.hpp:73:51: error: use of deleted function 'main()::<lambda()>& main()::<lambda()>::operator=(const main()::<lambda()>&)'

static void apply(T& dst, const U& src) { dst = src; }

~~~~^~~~~

main.cpp:21:11: note: a lambda closure type has a deleted copy assignment operator

Foo{[&]{}};

^

Я не понимаю почему applyаргумент const, И как правильно?

Coliru ссылка

Обновить:

Я думал, что лямбда назначается на движение. Тем не менее, это кажется неправильным.

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …