- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
C++17 标准说:
polymorphic_allocator(memory_resource* r);
Requires:
r
is non-null.Effects: Sets
memory_rsrc
tor
.Throws: Nothing.
[ Note: This constructor provides an implicit conversion from
memory_resource*
. — end note ]
接受 memory_resource*
有什么意义?而不是 memory_resource&
如果 “需要” 子句提到 r
必须是非空的?
Bloomberg¹ 风格指南鼓励接受将被指针而不是引用改变的参数,以便调用方的 & 符号成为改变的视觉标记。但是,标准中没有这样的先例。
是什么原因r
被当作指针而不是引用?
¹ pmr
由于该公司使用多态分配器模型,因此在彭博社的大力参与下实现了标准化。
最佳答案
N3916 :
Note that the memory-resource library is designed so that the
ShoppingList
constructor accepts a pointer to amemory_resource
rather than a reference to amemory_resource
. It was noted that one common practice is to use references rather than pointers in situations where a null pointer is out of contract. However, there is a more compelling practice of avoiding constructors that take objects by reference and store their addresses. We also want to avoid passing non-const references, as that, too, is usually considered bad practice (except in overloaded operators).
关于c++ - 为什么 `polymorphic_allocator` 采用 `memory_resource` 指针而不是引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56013463/
我有一个 vector>并希望从 memory_resource 中获取整个内存(即外部和内部 vector 的内存) .这是一个精简的例子,首先是无聊的部分: #include #include
来自 http://en.cppreference.com/w/cpp/memory/polymorphic_allocator : polymorphic_allocator does not pr
C++17 标准说: [mem.poly.allocator.ctor] polymorphic_allocator(memory_resource* r); Requires: r is non-n
我是一名优秀的程序员,十分优秀!