Add missing <algorithm> header and fix optional_ptr copy constructor