Skip to content

Commit a616312

Browse files
committed
Avoid using boost::optional in PassField()
Refactor PassField() to an equivalent one that does not use boost::optional.
1 parent abb3ae9 commit a616312

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

include/mp/proxy-types.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -955,22 +955,26 @@ void CustomBuildField(TypeList<LocalType> local_type,
955955
template <typename Accessor, typename LocalType, typename ServerContext, typename Fn, typename... Args>
956956
void PassField(TypeList<LocalType*>, ServerContext& server_context, const Fn& fn, Args&&... args)
957957
{
958-
InvokeContext& invoke_context = server_context;
959-
boost::optional<Decay<LocalType>> param;
960958
const auto& params = server_context.call_context.getParams();
961959
const auto& input = Make<StructField, Accessor>(params);
962-
bool want = input.want();
963-
if (want) {
964-
MaybeReadField(std::integral_constant<bool, Accessor::in>(), TypeList<LocalType>(), invoke_context, input,
965-
Emplace<decltype(param)>(param));
966-
if (!param) param.emplace();
960+
961+
if (!input.want()) {
962+
fn.invoke(server_context, std::forward<Args>(args)..., nullptr);
963+
server_context.call_context.getResults();
964+
return;
967965
}
968-
fn.invoke(server_context, std::forward<Args>(args)..., param ? &*param : nullptr);
966+
967+
InvokeContext& invoke_context = server_context;
968+
Decay<LocalType> param;
969+
970+
MaybeReadField(std::integral_constant<bool, Accessor::in>(), TypeList<LocalType>(), invoke_context, input,
971+
Emplace<decltype(param)>(param));
972+
973+
fn.invoke(server_context, std::forward<Args>(args)..., &param);
974+
969975
auto&& results = server_context.call_context.getResults();
970-
if (want) {
971-
MaybeBuildField(std::integral_constant<bool, Accessor::out>(), TypeList<LocalType>(), invoke_context,
972-
Make<StructField, Accessor>(results), *param);
973-
}
976+
MaybeBuildField(std::integral_constant<bool, Accessor::out>(), TypeList<LocalType>(), invoke_context,
977+
Make<StructField, Accessor>(results), param);
974978
}
975979

976980
template <typename Accessor, typename LocalType, typename ServerContext, typename Fn, typename... Args>

0 commit comments

Comments
 (0)