Skip to content

Commit

Permalink
stl: fix make_shared creating the type twice
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Aug 7, 2023
1 parent b6aa11a commit 2ff6ee2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions stl/pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class SharedPtr {
struct ControlBlock : STL_NS_IMPL::BaseControlBlock {
Type value;

ControlBlock(Type value) : value(value) {}
template <class... Args>
ControlBlock(Args&&... args) : value(forward<Args>(args)...) {}

void* get_value() const override { return const_cast<Type*>(&value); }
};
Expand Down Expand Up @@ -104,7 +105,8 @@ class SharedPtr {

template <class Type, class... Args>
SharedPtr<Type> make_shared(Args&&... args) {
return SharedPtr<Type>(new typename SharedPtr<Type>::ControlBlock(Type(forward<Args>(args)...)));
using Block = typename SharedPtr<Type>::ControlBlock;
return SharedPtr<Type>(new Block(forward<Args>(args)...));
}

}

0 comments on commit 2ff6ee2

Please sign in to comment.