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>
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 {
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>
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);
194 if (
this != di::addressof(other)) {
195 Storage::copy_assign(m_vtable,
this, other.m_vtable, util::addressof(other));
201 if (
this != di::addressof(other)) {
202 Storage::move_assign(m_vtable,
this, other.m_vtable, util::addressof(other));
207 template<
typename U, concepts::Impl<Interface> VU = RemoveConstructQualifiers<U>>
211 constexpr auto operator=(U&& value) ->
Type& {
212 if constexpr (!is_trivially_destructible) {
213 Storage::destroy(m_vtable,
this);
215 m_vtable = VTable::template create_for<Storage, VU>();
221 requires(!is_reference)
223 return !m_vtable.empty();
226 template<
typename U, concepts::Impl<Interface> VU = RemoveConstructQualifiers<U>>
230 if constexpr (!is_reference) {
235 m_vtable = VTable::template create_for<Storage, VU>();
239 m_vtable = VTable::template create_for<Storage, VU>();
246 if constexpr (!is_reference) {
250 return Storage::init(
this,
in_place_type<VT>, util::forward<Args>(args)...) % [&] {
251 m_vtable = VTable::template create_for<Storage, VT>();
255 m_vtable = VTable::template create_for<Storage, VT>();
263 if constexpr (!is_reference) {
267 return Storage::init(
this,
in_place_type<VT>, list, util::forward<Args>(args)...) % [&] {
268 m_vtable = VTable::template create_for<Storage, VT>();
272 m_vtable = VTable::template create_for<Storage, VT>();
277 requires(!is_reference)
279 if constexpr (!is_trivially_destructible) {
281 Storage::destroy(m_vtable,
this);
292template<concepts::Interface UserInterface, concepts::AnyStorage Storage = Hybr
idStorage<>,
293 typename VTablePolicy = MaybeInlineVTable<3>>
constexpr Type(Type const &other)
Definition any.h:142
constexpr void reset()
Definition any.h:276
constexpr Type(Type &&other)
Definition any.h:152
constexpr auto emplace(U &&value)
Definition any.h:229
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:200
constexpr auto operator=(Type const &other) -> Type &requires(is_copyable)
Definition any.h:193
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:220
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:245
constexpr auto emplace(InPlaceType< T >, std::initializer_list< U > list, Args &&... args)
Definition any.h:262
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
meta::Type< MethodImplT< E, S, Interface > > MethodImpl
Definition any.h:26
@ 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:294
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
constexpr auto voidify
Definition voidify.h:13
Definition zstring_parser.h:9
constexpr auto in_place_type
Definition in_place_type.h:12
constexpr friend auto tag_invoke(Tag, X &&self_in, BArgs... bargs) -> R
Definition any.h:38
static constexpr auto storage(E const &self) -> S const &
Definition any.h:34
static constexpr auto storage(E &self) -> S &
Definition any.h:33
static constexpr auto vtable(auto &&self) -> decltype(auto)
Definition any.h:32
Definition in_place_type.h:5