Add a concept for invocables with a return type

Because for some reason this is not part of the standard library.
This commit is contained in:
Robbert van der Helm
2021-05-19 23:08:36 +02:00
parent 57d7141681
commit 35cc47d021
2 changed files with 12 additions and 1 deletions
+11
View File
@@ -45,6 +45,17 @@ constexpr char product_name_override[] = "Get yabridge'd";
*/
constexpr char vendor_name_override[] = "yabridge";
/**
* The same as the `std::invocable` concept, but also specifying the result
* type.
*/
template <typename F, typename Result, typename... Args>
concept invocable_returning = requires(F&& f, Result&& result, Args&&... args) {
{
std::invoke(std::forward<F>(f), std::forward<Args>(args)...)
} -> std::convertible_to<Result>;
};
// The cannonical overloading template for `std::visitor`, not sure why this
// isn't part of the standard library
template <class... Ts>
+1 -1
View File
@@ -277,7 +277,7 @@ class MainContext {
* that will cause them to stall indefinitely in this situation, but who
* knows which other plugins exert similar behaviour.
*/
template <typename F, typename P>
template <std::invocable F, invocable_returning<bool> P>
void async_handle_events(F handler, P predicate) {
// Try to keep a steady framerate, but add in delays to let other events
// get handled if the GUI message handling somehow takes very long.