Iros
 
Loading...
Searching...
No Matches
erased_call.h
Go to the documentation of this file.
1#pragma once
2
8#include "di/meta/algorithm.h"
9#include "di/meta/language.h"
10#include "di/meta/util.h"
12
13namespace di::any::detail {
14template<typename Method, typename Storage, typename T>
16
17template<typename Tag, typename Storage, typename R, concepts::RemoveCVRefSameAs<This> Self, typename... BArgs,
18 typename T>
19struct ErasedCallImpl<Method<Tag, R(Self, BArgs...)>, Storage, T> {
20 constexpr static auto call(void* storage, BArgs... bargs) -> R {
21 using M = Method<Tag, R(Self, BArgs...)>;
22
24 "Cannot create a vtable function for T not storable in Storage.");
26 "Cannot create a vtable function because the Method is not callable for T.");
27
28 auto const tag = Tag {};
29
30 using QualifiedStorage = meta::MaybeConst<concepts::Const<meta::RemoveReference<This>>, Storage>;
31 auto* typed_storage = static_cast<QualifiedStorage*>(storage);
32 auto* object = typed_storage->template down_cast<meta::RemoveReference<T>>();
33
35 if constexpr (concepts::LanguageVoid<R>) {
36 (void) tag_invoke(tag, M {}, util::forward_like<Self>(*object), util::forward<BArgs>(bargs)...);
37 } else {
38 return tag_invoke(tag, M {}, util::forward_like<Self>(*object), util::forward<BArgs>(bargs)...);
39 }
40 } else {
41 return function::invoke_r<R>(tag, util::forward_like<Self>(*object), util::forward<BArgs>(bargs)...);
42 }
43 }
44};
45}
Definition any_storable.h:11
Definition core.h:128
Definition method_callable_with.h:23
Definition tag_invoke.h:45
Definition any.h:19
constexpr auto invoke_r
Definition invoke.h:103
Conditional< is_const, T const, T > MaybeConst
Definition util.h:9
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
constexpr auto forward_like(U &&value) -> decltype(auto)
Definition forward_like.h:8
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
Definition erased_call.h:15
static constexpr auto call(void *storage, BArgs... bargs) -> R
Definition erased_call.h:20
Definition method.h:7