💥 Redo all higher order template functions

This does what we did for a few functions in the last few commits for
every function. We now use either the `std::invocable` concept or our
own `invocable_returning` concept wherever possible to make sure we pass
function types to these template functions, since constraint errors are
a lot more readable than template deduction errors. And instead of
having to specify the return type as a template argument, we now just
use `std::invoke_result_t<F>` instead. The VST3 message handling
functions are still using the good old `typename F` since those are
overloaded polymorphic functions. This was also a good moment to modify
`AdHocSocketHandler::send()` to allow functions returning void (this got
rid of an old fixme where we had to return some dummy value from a
function instead of just not returning anything).
This commit is contained in:
Robbert van der Helm
2021-05-20 00:53:48 +02:00
parent 6c58f4e305
commit e4ca520b64
11 changed files with 91 additions and 93 deletions
+11 -12
View File
@@ -138,15 +138,10 @@ class Vst3MessageHandler : public AdHocSocketHandler<Thread> {
// messages from arriving out of order. `AdHocSocketHandler::send()`
// will either use a long-living primary socket, or if that's currently
// in use it will spawn a new socket for us.
this->template send<std::monostate>(
[&](boost::asio::local::stream_protocol::socket& socket) {
write_object(socket, Request(object), buffer);
read_object<TResponse>(socket, response_object, buffer);
// FIXME: We have to return something here, and ML was not yet
// invented when they came up with C++ so void is not
// valid here
return std::monostate{};
});
this->send([&](boost::asio::local::stream_protocol::socket& socket) {
write_object(socket, Request(object), buffer);
read_object<TResponse>(socket, response_object, buffer);
});
if (should_log_response) {
auto [logger, is_host_vst] = *logging;
@@ -205,7 +200,7 @@ class Vst3MessageHandler : public AdHocSocketHandler<Thread> {
*/
template <bool persistent_buffers = false, typename F>
void receive_messages(std::optional<std::pair<Vst3Logger&, bool>> logging,
F callback) {
F&& callback) {
// Reading, processing, and writing back the response for the requests
// we receive works in the same way regardless of which socket we're
// using
@@ -377,12 +372,15 @@ class Vst3Sockets : public Sockets {
* Wine plugin host is even listening on it.
* @param cb An overloaded function that can take every type `T` in the
* `AudioProcessorRequest` variant and then returns `T::Response`.
*
* @tparam F A function type in the form of `T::Response(T)` for every `T`
* in `AudioProcessorRequest::Payload`.
*/
template <typename F>
void add_audio_processor_and_listen(
size_t instance_id,
std::promise<void>& socket_listening_latch,
F&& cb) {
F&& callback) {
{
std::lock_guard lock(audio_processor_sockets_mutex);
audio_processor_sockets.try_emplace(
@@ -400,7 +398,8 @@ class Vst3Sockets : public Sockets {
// receiving buffers for all calls. This slightly reduces the amount of
// allocations in the audio processing loop.
audio_processor_sockets.at(instance_id)
.template receive_messages<true>(std::nullopt, std::forward<F>(cb));
.template receive_messages<true>(std::nullopt,
std::forward<F>(callback));
}
/**