What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference counted implementation like here).namespace immutable{    template<typename T>    class stack: public std::enable_shared_from_this<stack<T>>    {        public:            typedef std::shared_ptr<T> headPtr;            typedef std::shared_ptr<stack<T>> StackPtr;            template <typename T> friend struct stackBuilder;            static StackPtr empty()            {                return std::make_shared<stackBuilder<T>>(nullptr, nullptr);            }            static StackPtr Create()            {                return empty();            }            StackPtr push(const T& head)            {                return std::make_shared<stackBuilder<T>>(std::make_shared<T>(head), shared_from_this());            }            StackPtr pop()            {        return this->tail;    }    headPtr peek()    {                return this->head;            }            bool isEmpty()            {                return (this->head == nullptr);            }        private:            stack(headPtr head, StackPtr tail): head(head), tail(tail)            {            }            stack<T>& operator= (const stack<T>& other);        private:    headPtr head;    StackPtr tail;    };    template <typename T>    struct stackBuilder: public stack<T>    {        stackBuilder(headPtr head, StackPtr tail): stack(head, tail){}    };}Usage:auto empty = stack<int>::empty();auto newStack = empty->push(1);auto stack = newStack;while(!stack->isEmpty()){    std::cout << *stack->peek() << \n;    stack = stack->pop();}
Immutable C++ stack - thoughts and performance
c++;performance;functional programming;stack;immutability