Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct client return values in place #32

Open
ryanofsky opened this issue Mar 20, 2020 · 0 comments
Open

Construct client return values in place #32

ryanofsky opened this issue Mar 20, 2020 · 0 comments

Comments

@ryanofsky
Copy link
Collaborator

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;
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@ryanofsky and others