pointee.rst

来自「Boost provides free peer-reviewed portab」· RST 代码 · 共 89 行

RST
89
字号
.. Distributed under the Boost.. Software License, Version 1.0. (See accompanying.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)++++++++++++++++++++++++++++++++++++++++ ``pointee`` and ``indirect_reference`` ++++++++++++++++++++++++++++++++++++++++:Author: David Abrahams:Contact: dave@boost-consulting.com:organization: `Boost Consulting`_:date: $Date: 2008-03-22 17:45:55 -0400 (Sat, 22 Mar 2008) $:copyright: Copyright David Abrahams 2004. .. _`Boost Consulting`: http://www.boost-consulting.com:abstract: Provides the capability to deduce the referent types of  pointers, smart pointers and iterators in generic code.Overview========Have you ever wanted to write a generic function that can operateon any kind of dereferenceable object?  If you have, you'veprobably run into the problem of how to determine the type that theobject "points at":.. parsed-literal::   template <class Dereferenceable>   void f(Dereferenceable p)   {       *what-goes-here?* value = \*p;       ...   }``pointee``-----------It turns out to be impossible to come up with a fully-generalalgorithm to do determine *what-goes-here* directly, but it ispossible to require that ``pointee<Dereferenceable>::type`` iscorrect. Naturally, ``pointee`` has the same difficulty: it can'tdetermine the appropriate ``::type`` reliably for all``Dereferenceable``\ s, but it makes very good guesses (it worksfor all pointers, standard and boost smart pointers, anditerators), and when it guesses wrongly, it can be specialized asnecessary::  namespace boost  {    template <class T>    struct pointee<third_party_lib::smart_pointer<T> >    {        typedef T type;    };  }``indirect_reference``----------------------``indirect_reference<T>::type`` is rather more specialized than``pointee``, and is meant to be used to forward the result ofdereferencing an object of its argument type.  Most dereferenceabletypes just return a reference to their pointee, but some returnproxy references or return the pointee by value.  When thatinformation is needed, call on ``indirect_reference``.Both of these templates are essential to the correct functioning of|indirect_iterator|_... |indirect_iterator| replace:: ``indirect_iterator``.. _indirect_iterator: indirect_iterator.htmlReference=========``pointee``-----------.. include:: pointee_ref.rst``indirect_reference``----------------------.. include:: indirect_reference_ref.rst

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?