BAN: Implement same_as and add requires for BAN::Function with lambda

BAN::Function(lambda) now requires that the object is callable and
returns the correct type. This allows overloads with different
callback formats.
This commit is contained in:
Bananymous 2024-06-14 00:15:48 +03:00
parent 766439db6d
commit 6707989cd5
2 changed files with 2 additions and 1 deletions

View File

@ -32,7 +32,7 @@ namespace BAN
new (m_storage) CallableMemberConst<Own>(function, owner);
}
template<typename Lambda>
Function(Lambda lambda)
Function(Lambda lambda) requires requires(Lambda lamda, Args... args) { { lambda(args...) } -> BAN::same_as<Ret>; }
{
static_assert(sizeof(CallableLambda<Lambda>) <= m_size);
new (m_storage) CallableLambda<Lambda>(lambda);

View File

@ -42,6 +42,7 @@ namespace BAN
template<typename T, typename S> struct is_same : false_type {};
template<typename T> struct is_same<T, T> : true_type {};
template<typename T, typename S> inline constexpr bool is_same_v = is_same<T, S>::value;
template<typename T, typename S> concept same_as = BAN::is_same_v<T, S>;
template<typename T> struct is_lvalue_reference : false_type {};
template<typename T> struct is_lvalue_reference<T&> : true_type {};