File tree 1 file changed +7
-1
lines changed
1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -375,16 +375,22 @@ namespace xxx {
375
375
376
376
struct EmptyHolder final : public IHolder
377
377
{
378
+ // Not used - is required so that sizeof(Holder<void>) == sizeof(EmptyHolder)
379
+ std::shared_ptr<void > my_ptr;
380
+
378
381
EmptyHolder () = default ;
379
382
380
383
bool has_value () const noexcept { return false ; }
381
384
const std::type_info& type () const noexcept { return typeid (void ); }
382
385
bool unique () const noexcept final { return false ; }
383
386
const IHolder * clone (void * const inplaceMemory) const noexcept final { return ::new (inplaceMemory) EmptyHolder (); }
384
387
void throw_held_pointer () const final {}
385
- std::shared_ptr<void > make_shared_ptr_alias (void * ) const noexcept final { return std::shared_ptr< void >() ; }
388
+ std::shared_ptr<void > make_shared_ptr_alias (void * ) const noexcept final { return my_ptr ; }
386
389
};
387
390
391
+ static_assert (sizeof (Holder<void >) == sizeof (EmptyHolder), " It's not essential but sizeof(Holder<void>) == sizeof(EmptyHolder)"
392
+ " is better so that all bytes in my_inplace_storage are initialized" );
393
+
388
394
using storage_t = typename std::aligned_storage<sizeof (Holder<void >), std::alignment_of<Holder<void >>::value>::type;
389
395
390
396
// Inplace storage to hold Holder<T>
You can’t perform that action at this time.
0 commit comments