chaincodelabs / libmultiprocess

C++ library and code generator making it easy to call functions and reference objects in different processes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Construct client return values in place

ryanofsky opened this issue · comments

Currently IPC method return types have to be default constructible, and can be copied or moved unnecessarily when ReadField is called. It would be better to construct return values in place to stop requiring default constructors, simplify code generation, and stop creating temporary copies unnecessarily.

Way to do this would be to change clientInvoke function to return an actual value instead of void, so generated client method code would change from:

typename M1::Result result;
clientInvoke(..., MakeClientParam(result));
return result;

to:

return clientInvoke(..., MakeClientReturn<M1::Result>());

This should work with the existing CustomReadField functions but ReadField will have to be updated to not return void:

template <typename... LocalTypes, typename... Args>
decltype(auto) ReadField(TypeList<LocalTypes...>, Args&&... args)
{
    return CustomReadField(TypeList<RemoveCvRef<LocalTypes>...>(), std::forward<Args>(args)...);
}

And a new ReadDest helper type will be required to pass into ReadField:

template<typename Type>
struct ReadDestReturn
{
    template <typename... Args>
    auto& construct(Args&&... args)
    {
        return Type(std::forward<Args>(args)...);
    }

    template <typename UpdateFn>
    Type update(UpdateFn&& update_fn)
    {
        Type ret;
        update_fn(ret);
        return ret;
    }
};