-
ProblemI want to create callable object with const cv qualifier and call it with some value. Code exampleusing namespace caf;
using inc_actor_t = typed_actor<replies_to<int>::with<int>>;
void b_impl(event_based_actor* self, const inc_actor_t &a) {
const auto increment = make_function_view(a);
increment(1);
}
Expected behaviorSuccessful compilation. Current behaviorCompilation error:
Possible solutions1. In my opinion best solution, but maybe implicitly changing current codeAdd to current call operator overload template <class... Ts>
auto operator()(Ts&&... xs) { const qualifier template <class... Ts>
auto operator()(Ts&&... xs) const { And fix compilation errors by addition of const or static to functions flatten: template <class T>
static T&& flatten(T& x) {
return std::move(x);
}
template <class T>
static T&& flatten(std::tuple<T>& x) {
return std::move(get<0>(x));
} 2. At least, not affecting curent codeAdd to class template <class Actor>
class function_view; operator() overload with const and separate implementation. Why it matters
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The function view isn't
Now, technically the function view could get away with |
Beta Was this translation helpful? Give feedback.
-
I see... So it would be like - calling the same const object twice with the same values, but getting different results, yea that would be confusing. |
Beta Was this translation helpful? Give feedback.
The function view isn't
const
, because:Now, technically the function view could get away with
const
since it wraps an actor handle. Semantically, the "function" changes its state whenever you call it. We decided to not make the function call operator const to make it clear that there are state changes whenever you call it. It's still message passing underneath.