Skip to content

Commit

Permalink
Avoid using boost::optional in PassField()
Browse files Browse the repository at this point in the history
Refactor PassField() to an equivalent one that does not use
boost::optional.
  • Loading branch information
vasild committed Jan 15, 2020
1 parent abb3ae9 commit a616312
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions include/mp/proxy-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,22 +955,26 @@ void CustomBuildField(TypeList<LocalType> local_type,
template <typename Accessor, typename LocalType, typename ServerContext, typename Fn, typename... Args>
void PassField(TypeList<LocalType*>, ServerContext& server_context, const Fn& fn, Args&&... args)
{
InvokeContext& invoke_context = server_context;
boost::optional<Decay<LocalType>> param;
const auto& params = server_context.call_context.getParams();
const auto& input = Make<StructField, Accessor>(params);
bool want = input.want();
if (want) {
MaybeReadField(std::integral_constant<bool, Accessor::in>(), TypeList<LocalType>(), invoke_context, input,
Emplace<decltype(param)>(param));
if (!param) param.emplace();

if (!input.want()) {
fn.invoke(server_context, std::forward<Args>(args)..., nullptr);
server_context.call_context.getResults();
return;
}
fn.invoke(server_context, std::forward<Args>(args)..., param ? &*param : nullptr);

InvokeContext& invoke_context = server_context;
Decay<LocalType> param;

MaybeReadField(std::integral_constant<bool, Accessor::in>(), TypeList<LocalType>(), invoke_context, input,
Emplace<decltype(param)>(param));

fn.invoke(server_context, std::forward<Args>(args)..., &param);

auto&& results = server_context.call_context.getResults();
if (want) {
MaybeBuildField(std::integral_constant<bool, Accessor::out>(), TypeList<LocalType>(), invoke_context,
Make<StructField, Accessor>(results), *param);
}
MaybeBuildField(std::integral_constant<bool, Accessor::out>(), TypeList<LocalType>(), invoke_context,
Make<StructField, Accessor>(results), param);
}

template <typename Accessor, typename LocalType, typename ServerContext, typename Fn, typename... Args>
Expand Down

0 comments on commit a616312

Please sign in to comment.