From 6707989cd529be0e1441b0fcdd6863f9817103bb Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 14 Jun 2024 00:15:48 +0300 Subject: [PATCH] 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. --- BAN/include/BAN/Function.h | 2 +- BAN/include/BAN/Traits.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/BAN/include/BAN/Function.h b/BAN/include/BAN/Function.h index 94e083d73d..b2ed0c9aae 100644 --- a/BAN/include/BAN/Function.h +++ b/BAN/include/BAN/Function.h @@ -32,7 +32,7 @@ namespace BAN new (m_storage) CallableMemberConst(function, owner); } template - Function(Lambda lambda) + Function(Lambda lambda) requires requires(Lambda lamda, Args... args) { { lambda(args...) } -> BAN::same_as; } { static_assert(sizeof(CallableLambda) <= m_size); new (m_storage) CallableLambda(lambda); diff --git a/BAN/include/BAN/Traits.h b/BAN/include/BAN/Traits.h index 646e5af0e3..976cf8b339 100644 --- a/BAN/include/BAN/Traits.h +++ b/BAN/include/BAN/Traits.h @@ -42,6 +42,7 @@ namespace BAN template struct is_same : false_type {}; template struct is_same : true_type {}; template inline constexpr bool is_same_v = is_same::value; + template concept same_as = BAN::is_same_v; template struct is_lvalue_reference : false_type {}; template struct is_lvalue_reference : true_type {};