C++标准库中有纯虚函数吗?
Is there a pure virtual function in the C++ Standard Library?
在 Nicola Gigante's lecture in 2015 中,他提到(在开头)标准库中没有纯虚函数(或者他不知道)。我相信 Alex Stepanov 反对这种语言功能,但自从最初的 STL 设计以来,是否有任何纯虚拟化进入标准库?
FWIW(如果我错了请纠正我)唯一指针中的删除器最终在大多数实现中使用虚拟调度,但这些不是纯虚拟。
[syserr.errcat.overview] 有 std::error_category
class error_category {
virtual const char* name() const noexcept = 0;
virtual string message(int ev) const = 0;
};
C++14 中没有其他的。
C++17 添加 std::pmr::memory_resource
in [mem.res.class] to the one in C++14,具有以下 private
纯虚函数:
class memory_resource {
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
};
在 Nicola Gigante's lecture in 2015 中,他提到(在开头)标准库中没有纯虚函数(或者他不知道)。我相信 Alex Stepanov 反对这种语言功能,但自从最初的 STL 设计以来,是否有任何纯虚拟化进入标准库?
FWIW(如果我错了请纠正我)唯一指针中的删除器最终在大多数实现中使用虚拟调度,但这些不是纯虚拟。
[syserr.errcat.overview] 有 std::error_category
class error_category {
virtual const char* name() const noexcept = 0;
virtual string message(int ev) const = 0;
};
C++14 中没有其他的。
C++17 添加 std::pmr::memory_resource
in [mem.res.class] to the one in C++14,具有以下 private
纯虚函数:
class memory_resource {
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
};