Fix build against C++03 stdlib; merge upstream