19 Base *(*get_impl)(
const void *buffer);
24 static_assert(std::is_base_of_v<Base, StorageT> ||
29 if constexpr (std::is_base_of_v<Base, StorageT>) {
30 return {[](
const void *buffer) {
31 return static_cast<Base *
>(
const_cast<StorageT *
>(
static_cast<const StorageT *
>(buffer)));
34 else if constexpr (std::is_same_v<StorageT, Base *>) {
35 return {[](
const void *buffer) {
36 return *
const_cast<StorageT *
>(
static_cast<const StorageT *
>(buffer));
39 else if constexpr (std::is_same_v<StorageT, std::shared_ptr<Base>>) {
40 return {[](
const void *buffer) {
41 return (
const_cast<StorageT *
>(
static_cast<const StorageT *
>(buffer)))->get();
70template<
typename Base,
int64_t InlineBufferCapacity = 24>
struct AnyDerived {
75 Base *impl_ =
nullptr;
96 other.storage_.reset();
97 other.impl_ =
nullptr;
108 storage_ = std::move(impl);
114 if (
this == &other) {
117 storage_ = other.storage_;
124 if (
this == &other) {
127 storage_ = std::move(other.storage_);
129 other.storage_.reset();
130 other.impl_ =
nullptr;
134 template<
typename ImplT,
typename... Args>
135 requires std::is_base_of_v<Base, ImplT>
138 if constexpr (std::is_copy_constructible_v<ImplT> && Storage::template is_inline_v<ImplT>) {
141 impl_ = &storage_.template
emplace<ImplT>(std::forward<Args>(args)...);
146 std::shared_ptr<Base> ptr = std::make_shared<ImplT>(std::forward<Args>(args)...);
148 storage_ = std::move(ptr);
152 operator bool()
const
154 return impl_ !=
nullptr;
175 if (!storage_.has_value()) {
178 return storage_.extra_info().get_impl(storage_.get());
#define BLI_assert_unreachable()
constexpr bool is_same_any_v
AnyDerived(AnyDerived &&other) noexcept
AnyDerived(std::shared_ptr< Base > impl)
AnyDerived & operator=(const AnyDerived &other)
Base * operator->() const
AnyDerived & operator=(AnyDerived &&other) noexcept
Base * impl_from_storage() const
void emplace(Args &&...args)
AnyDerived(const AnyDerived &other)