In the following snippet I try to convert a lambda to my own function object, constraining it with a concept based on the invocable_r type trait. Yet gcc rejects it.
#include <concepts>
#include <cstdio>
template <typename Fn, typename R, typename... Args>
concept invocable_r = std::is_invocable_r<R, Fn, Args...>::value;
template <typename R, typename... Args>
class function
{
template <invocable_r<R, Args...> Cb>
function(Cb fn) {
printf("Converting constructor invoked!\n");
}
};
int main()
{
function<void()> hello = [](){};
}
Error:
error: conversion from 'main()::<lambda()>' to non-scalar type 'function<void()>' requested
I can't seem to find the issue. What's wrong?