20 template<
typename E,
typename S,
typename Interface>
25 template<
typename E,
typename S,
typename Interface>
28 template<
typename E,
typename S,
typename Tag,
typename R, concepts::RemoveCVRefSameAs<This> Self,
29 typename... BArgs,
typename... Rest>
30 struct MethodImplT<E, S,
meta::List<Method<Tag, R(Self, BArgs...)>, Rest...>> {
31 struct Type : MethodImpl<E, S, meta::List<Rest...>> {
32 constexpr static auto vtable(
auto&& self) ->
decltype(
auto) {
return (self.m_vtable); }
33 constexpr static auto storage(E& self) -> S& {
return self; }
34 constexpr static auto storage(E
const& self) -> S
const& {
return self; }
38 constexpr friend auto tag_invoke(
Tag, X&& self_in, BArgs... bargs) -> R {
40 auto const& vtable = Type::vtable(self);
41 auto* storage =
util::voidify(util::addressof(Type::storage(self)));
43 auto erased_fp = vtable[
Method<
Tag, R(Self, BArgs...)> {}];
44 return erased_fp(storage, util::forward<BArgs>(bargs)...);
50template<
typename UserInterface,
typename Storage,
typename VTablePolicy>
53 :
private detail::MethodImpl<Type, Storage, meta::MergeInterfaces<UserInterface, typename Storage::Interface>>
55 template<
typename,
typename,
typename>
56 friend struct detail::MethodImplT;
65 "VTablePolicy policy returned an invalid VTable for the provided interface.");
67 constexpr static auto storage_category = Storage::storage_category();
72 constexpr static bool is_trivially_moveable = is_trivially_copyable;
81 template<
typename U,
typename VU = RemoveConstructQualifiers<U>>
84 constexpr static auto create(U&& value) {
91 result->m_vtable = VTable::template create_for<Storage, VU>();
93 return R(util::move(result));
108 result->m_vtable = VTable::template create_for<Storage, VT>();
126 result->m_vtable = VTable::template create_for<Storage, VT>();
135 requires(!is_reference)
139 requires(is_trivially_copyable)
143 requires(is_copyable)
144 : Storage(), m_vtable(other.m_vtable) {
145 Storage::copy_construct(other.m_vtable,
this, util::addressof(other));
149 requires(is_trivially_moveable)
153 requires(is_moveable)
154 : m_vtable(
di::move(other.m_vtable)) {
155 Storage::move_construct(other.m_vtable,
this, util::addressof(other));
158 template<
typename U,
typename VU = RemoveConstructQualifiers<U>>
180 requires(is_trivially_destructible)
184 requires(!is_trivially_destructible)
186 Storage::destroy(m_vtable,
this);
190 requires(is_trivially_copyable)
194 requires(is_trivially_moveable)
198 requires(is_copyable)
200 if (
this != di::addressof(other)) {
201 Storage::copy_assign(m_vtable,
this, other.m_vtable, util::addressof(other));
207 requires(is_moveable)
209 if (
this != di::addressof(other)) {
210 Storage::move_assign(m_vtable,
this, other.m_vtable, util::addressof(other));
215 template<
typename U, concepts::Impl<Interface> VU = RemoveConstructQualifiers<U>>
219 constexpr auto operator=(U&& value) ->
Type& {
220 if constexpr (!is_trivially_destructible) {
221 Storage::destroy(m_vtable,
this);
223 m_vtable = VTable::template create_for<Storage, VU>();
229 requires(!is_reference)
231 return !m_vtable.empty();
234 template<
typename U, concepts::Impl<Interface> VU = RemoveConstructQualifiers<U>>
238 if constexpr (!is_reference) {
243 m_vtable = VTable::template create_for<Storage, VU>();
247 m_vtable = VTable::template create_for<Storage, VU>();
254 if constexpr (!is_reference) {
258 return Storage::init(
this,
in_place_type<VT>, util::forward<Args>(args)...) % [&] {
259 m_vtable = VTable::template create_for<Storage, VT>();
263 m_vtable = VTable::template create_for<Storage, VT>();
271 if constexpr (!is_reference) {
275 return Storage::init(
this,
in_place_type<VT>, list, util::forward<Args>(args)...) % [&] {
276 m_vtable = VTable::template create_for<Storage, VT>();
280 m_vtable = VTable::template create_for<Storage, VT>();
285 requires(!is_reference)
287 if constexpr (!is_trivially_destructible) {
289 Storage::destroy(m_vtable,
this);
300template<concepts::Interface UserInterface, concepts::AnyStorage Storage = Hybr
idStorage<>,
301 typename VTablePolicy = MaybeInlineVTable<3>>
constexpr Type(Type const &other)
Definition any.h:142
constexpr void reset()
Definition any.h:284
constexpr Type(Type &&other)
Definition any.h:152
constexpr auto emplace(U &&value)
Definition any.h:237
constexpr ~Type()
Definition any.h:183
constexpr Type(InPlaceType< T >, std::initializer_list< U > list, Args &&... args)
Definition any.h:175
meta::MergeInterfaces< UserInterface, typename Storage::Interface > Interface
Definition any.h:60
meta::Invoke< VTablePolicy, Interface > VTable
Definition any.h:61
auto operator=(Type &&) -> Type &requires(is_trivially_moveable)=default
constexpr auto operator=(Type &&other) -> Type &requires(is_moveable)
Definition any.h:206
constexpr auto operator=(Type const &other) -> Type &requires(is_copyable)
Definition any.h:197
Storage AnyStorage
Definition any.h:59
static constexpr auto create(InPlaceType< T >, Args &&... args)
Definition any.h:101
constexpr auto has_value() const -> bool requires(!is_reference)
Definition any.h:228
auto operator=(Type const &) -> Type &requires(is_trivially_copyable)=default
static constexpr auto create(InPlaceType< T >, std::initializer_list< U > list, Args &&... args)
Definition any.h:119
constexpr Type(InPlaceType< T >, Args &&... args)
Definition any.h:168
constexpr auto emplace(InPlaceType< T >, Args &&... args)
Definition any.h:253
constexpr auto emplace(InPlaceType< T >, std::initializer_list< U > list, Args &&... args)
Definition any.h:270
Type(Type const &)=default
static constexpr auto create(U &&value)
Definition any.h:84
constexpr Type(U &&value)
Definition any.h:162
Definition any_storable_infallibly.h:11
Definition any_storable.h:11
Definition operations.h:11
Definition operations.h:114
Definition vtable_for.h:17
@ Immovable
Definition storage_category.h:8
@ Reference
Definition storage_category.h:5
@ Trivial
Definition storage_category.h:6
@ Copyable
Definition storage_category.h:10
meta::Type< AnyT< UserInterface, Storage, VTablePolicy > > Any
Definition any.h:302
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
constexpr auto voidify
Definition voidify.h:13
Definition any_storable.h:9
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
constexpr auto in_place_type
Definition in_place_type.h:12
Definition in_place_type.h:5