Iros
 
Loading...
Searching...
No Matches
inline_vtable.h
Go to the documentation of this file.
1#pragma once
2
7#include "di/util/get.h"
9
10namespace di::any {
12 template<typename Interface>
13 class Invoke;
14
15 template<typename... Methods>
17 class Invoke<meta::List<Methods...>> {
18 static_assert(sizeof...(Methods) > 0, "Cannot create an InlineVTable with 0 methods.");
19
20 private:
22
23 public:
24 template<typename Storage, concepts::AnyStorable<Storage> T>
25 constexpr static auto create_for() -> Invoke {
26 return Invoke(make_tuple(detail::ErasedCallImpl<meta::Type<Methods>, Storage, T>::call...));
27 }
28
29 constexpr Invoke() { reset(); }
30
31 constexpr auto empty() const -> bool { return util::get<0>(m_storage) == nullptr; }
32 constexpr void reset() { util::get<0>(m_storage) = nullptr; }
33
34 template<concepts::OneOf<meta::Type<Methods>...> Method>
35 constexpr auto operator[](Method) const {
36 constexpr auto index = meta::Lookup<Method, meta::List<meta::Type<Methods>...>>;
37 return util::get<index>(m_storage);
38 }
39
40 private:
41 constexpr Invoke(Storage storage) : m_storage(di::move(storage)) {}
42
43 Storage m_storage;
44 };
45};
46}
Definition inline_vtable.h:13
constexpr Invoke()
Definition inline_vtable.h:29
static constexpr auto create_for() -> Invoke
Definition inline_vtable.h:25
constexpr auto empty() const -> bool
Definition inline_vtable.h:31
constexpr auto operator[](Method) const
Definition inline_vtable.h:35
constexpr void reset()
Definition inline_vtable.h:32
Definition tuple_forward_declaration.h:5
Definition method.h:8
Definition any.h:18
Definition merge_interfaces.h:6
T::Type Type
Definition core.h:26
constexpr auto get(T &&value) -> decltype(auto)
Definition get.h:8
Definition zstring_parser.h:9
constexpr auto make_tuple(Args &&... args)
Definition make_tuple.h:9
Definition inline_vtable.h:11
Definition erased_call.h:15
Definition method.h:7