firegurafiku
firegurafiku

Reputation: 3116

Cannot declare template typed actor in C++ Actor Framework

I'm trying to declare a strongly-typed actor in C++ actor framework (CAF), but my code doesn't compile for some reason. Could you tell me what's wrong with it?

#include "caf/all.hpp"

template <typename TNum>
class DiscoverRequest {};

template <typename TNum>
class DiscoverResponse {};

template <typename TNum>
class DataRequest {};

template <typename TNum>
class DataResponse {};

template <typename TNum>
using BlockActor = caf::typed_actor<
    /* ERROR NEXT LINE */
    caf::replies_to<DiscoverRequest<TNum>>::with<DiscoverResponse<TNum>>,
    caf::replies_to<DataRequest<TNum>>    ::with<DataResponse<TNum>> >;

The error message:

Block.hh:13:71: error: type/value mismatch at argument 1 in template
parameter list for 'template<class ... Sigs> class caf::typed_actor'

caf::replies_to<DiscoverRequest<TNum>>::with<DiscoverResponse<TNum>>,
                                                                  ^
Block.hh:13:71: error: expected a type, got   
'(caf::replies_to<DiscoverRequest<TNum> >::with < <expression error>)'

But if I replace DiscoverRequest<TNum> and DiscoverResponse<TNum> with specific instantiations, like, for example, DiscoverRequest<float>, it does compile nicely. So, I think something in CAF internals forbids using such a construct.

My compiler is GCC G++ 4.9.2 (with -std=c++11, of course), running on Fedora 21. The CAF is the latest revision of its master branch, linked to the project as a Git submodule.

Upvotes: 4

Views: 287

Answers (2)

neverlord
neverlord

Reputation: 1000

The answer of Jarod42 is correct to get this to compile. However, I wonder why you don't follow the more idiomatic way for defining interfaces with atom constants:

using discover_request_atom = atom_constant<atom("DiscoverRq")>;

using discover_response_atom = atom_constant<atom("DiscoverRs")>;

using data_request_atom = atom_constant<atom("DataRq")>;

using data_response_atom = atom_constant<atom("DataRs")>;

template <class TNum>
using BlockActor = caf::typed_actor<
    replies_to<discover_request_atom, TNum>::with<discover_response_atom, TNum>,
    replies_to<data_request_atom, TNum>    ::with<data_response_atom, TNum>>;

This safes you a lot of headache later on, as it safes you from announcing each and every one of your template instances.

Upvotes: 2

Jarod42
Jarod42

Reputation: 217085

template keyword is missing.

It should be

template <typename TNum>
using BlockActor = caf::typed_actor<
    typename caf::replies_to<DiscoverRequest<TNum>>::template with<DiscoverResponse<TNum>>,
    typename caf::replies_to<DataRequest<TNum>>    ::template with<DataResponse<TNum>> >;

Upvotes: 2

Related Questions