[英]How does a fancy pointer look like?
The C++ reference mentions a concept called fancy pointers . C++ 参考文献提到了一个叫做花式指针的概念。 I learned about their existence from a recent heavily downvoted and afterwards deleted question.
我从最近一个被严重否决且随后被删除的问题中了解到它们的存在。
The definition is rather vague:定义比较模糊:
When the member type pointer is not a raw pointer type, it is commonly referred to as a "fancy pointer".
当成员类型指针不是原始指针类型时,通常称为“花式指针”。
Their use case example is:他们的用例示例是:
An example of a fancy pointer is the mapping address-independent pointer boost::interprocess::offset_ptr, which makes it possible to allocate node-based data structures such as std::set in shared memory and memory mapped files mapped in different addresses in every process.
花哨指针的一个例子是映射地址无关指针 boost::interprocess::offset_ptr,它可以在共享内存中分配基于节点的数据结构,例如 std::set 和映射到不同地址的内存映射文件每一个过程。 Fancy pointers can be used independently of the allocator that provided them, through the class template std::pointer_traits.
花式指针可以通过类模板 std::pointer_traits 独立于提供它们的分配器使用。
I don't understand that explanation.我不明白那个解释。 What is the syntax for creating a fancy pointer and why can't I use a regular pointer in this case?
创建精美指针的语法是什么,为什么在这种情况下我不能使用常规指针?
A fancy pointer is just a term for something that acts like a pointer but is not.花哨的指针只是一个类似于指针但不是指针的东西的术语。 Take, for example, an iterator.
以迭代器为例。 Pretty much all iterators are custom class types, but they behave just like a pointer (sometimes there are restrictions and you cannot do all the operations supported by a pointer as they do not provide random access but that is part of the fanciness.)
几乎所有迭代器都是自定义类类型,但它们的行为就像一个指针(有时存在限制,你不能执行指针支持的所有操作,因为它们不提供随机访问,但这是幻想的一部分。)
To put it another way: An abstraction that acts like a pointer is a fancy pointer .换句话说:一个像指针一样的抽象是一个花哨的指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.