小编Ste*_*lph的帖子

我可以在C++ Actor Framework中使用C++ 11智能指针作为消息返回类型吗?

当我使用unique_ptr作为返回类型时,我收到编译器错误C2280:

'caf::detail::tuple_vals<std::unique_ptr<A,std::default_delete<_Ty>>>::tuple_vals(const caf::detail::tuple_vals<std::unique_ptr<_Ty,std::default_delete<_Ty>>> &)': attempting to reference a deleted function  include\caf\detail\tuple_vals.hpp   102
Run Code Online (Sandbox Code Playgroud)

下面是一些示例代码,用于说明问题(从C++ Actor Framework示例中修改):

#include <iostream>
#include "caf/all.hpp"

using namespace caf;
using namespace std;

class A
{
public:
    int a;

    A(int a)
    {
        this->a = a;
    }
};

using a_type = typed_actor<replies_to<int>::with<unique_ptr<A>>>;

a_type::behavior_type a_behavior(a_type::pointer self)
{
    return
    {
        [self](const int& a) -> unique_ptr<A>
        {
            return make_unique<A>(5);
        }
    };
}

void tester(event_based_actor* self, const a_type& testee)
{
    self->link_to(testee);
    // will be invoked if we receive an unexpected response message
    self->on_sync_failure( …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ c++11 c++-actor-framework

5
推荐指数
1
解决办法
394
查看次数

在C++ Actors Framework中在类型化actor之间转发消息的最佳实践?

我正试图将一些作品从一个打字的演员交给另一个演员.CAF用户手册表明可以使用该forward_to方法完成此操作.该方法看起来只适用于明确属于该event_based_actor类型的actor .但是,forward_to似乎是方法的一个薄包装器forward_current_message,它是为该local_actor类型的所有actor定义的.因此,我认为forward_current_message直接打电话是可以的吗?

此外,为了使消息转发与类型的actor一起工作,我仍然必须返回来自中间actor的响应.那个演员的反应似乎被忽略了,这很好,但我做错了吗?或者是否真的有必要支付构建不会被使用的响应的(通常是最小的)成本?

这是一些工作示例代码,演示了我尝试使用类型化actor进行消息转发:

#include <iostream>
#include "caf/all.hpp"

using namespace caf;
using namespace std;

using a_type = typed_actor<replies_to<int>::with<bool>>;
using b_type = typed_actor<replies_to<int>::with<bool>>;

actor worker()
{
    return spawn(
        [](event_based_actor *self) -> behavior
        {
            return
            {
                [self](int index)
                {
                    aout(self) << "Worker: " << index << endl;
                    return index;
                }
            };
        });
}

b_type::behavior_type bBehavior(b_type::pointer self)
{
    return
    {
        [self](int value)
        {
            // Create blocking actor
            scoped_actor blockingActor;

            // Spawn …
Run Code Online (Sandbox Code Playgroud)

c++ c++-actor-framework

5
推荐指数
1
解决办法
330
查看次数

标签 统计

c++ ×2

c++-actor-framework ×2

c++11 ×1

visual-c++ ×1