utilities.qbk

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

QBK
224
字号
[section:utilities Iterator Utilities][section:utilities_traits Traits][h2 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":   template <class Dereferenceable>   void f(Dereferenceable p)   {       *what-goes-here?* value = \*p;       ...   }[h2 `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;    };  }[h2 `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[link indirecct `indirect_iterator`].[h2 Reference][h3 `pointeee`]  template <class Dereferenceable>  struct pointee  {      typedef /* see below */ type;  };[*Requires:] For an object `x` of type `Dereferenceable`, `*x`  is well-formed.  If `++x` is ill-formed it shall neither be  ambiguous nor shall it violate access control, and  `Dereferenceable::element_type` shall be an accessible type.  Otherwise `iterator_traits<Dereferenceable>::value_type` shall  be well formed. \[Note: These requirements need not apply to  explicit or partial specializations of `pointee`\]`type` is determined according to the following algorithm, where`x` is an object of type `Dereferenceable`:  if ( ++x is ill-formed )  {      return `Dereferenceable::element_type`  }  else if (`*x` is a mutable reference to           std::iterator_traits<Dereferenceable>::value_type)  {      return iterator_traits<Dereferenceable>::value_type  }  else  {      return iterator_traits<Dereferenceable>::value_type const  }[h3 `indirect_reference`]  template <class Dereferenceable>  struct indirect_reference  {      typedef /* see below */ type;  };[*Requires:] For an object `x` of type `Dereferenceable`, `*x`  is well-formed.  If `++x` is ill-formed it shall neither be  ambiguous nor shall it violate access control, and  `pointee<Dereferenceable>::type&` shall be well-formed.  Otherwise `iterator_traits<Dereferenceable>::reference` shall  be well formed.  \[Note: These requirements need not apply to  explicit or partial specializations of `indirect_reference`\]`type` is determined according to the following algorithm, where`x` is an object of type `Dereferenceable`:  if ( ++x is ill-formed )      return `pointee<Dereferenceable>::type&`  else      std::iterator_traits<Dereferenceable>::reference[endsect][section:utilities_testing Testing and Concept Checking]The iterator concept checking classes provide a mechanism for atemplate to report better error messages when a user instantiatesthe template with a type that does not meet the requirements of thetemplate.For an introduction to using concept checking classes, seethe documentation for the [@../../concept_check/index.html `boost::concept_check`] library.[h2 Reference][h3 Iterator Access Concepts]* |Readable|_ * |Writable|_ * |Swappable|_ * |Lvalue|_ [/ .. |Readable| replace:: *Readable Iterator* ][/ .. _Readable: ReadableIterator.html            ][/                                                ][/ .. |Writable| replace:: *Writable Iterator*    ][/ .. _Writable: WritableIterator.html            ][/                                                ][/ .. |Swappable| replace:: *Swappable Iterator*  ][/ .. _Swappable: SwappableIterator.html          ][/                                                ][/ .. |Lvalue| replace:: *Lvalue Iterator*        ][/ .. _Lvalue: LvalueIterator.html                ]Iterator Traversal Concepts...........................* |Incrementable|_* |SinglePass|_* |Forward|_* |Bidir|_* |Random|_[/ .. |Incrementable| replace:: *Incrementable Iterator* ][/ .. _Incrementable: IncrementableIterator.html         ][/                                                       ][/ .. |SinglePass| replace:: *Single Pass Iterator*      ][/ .. _SinglePass: SinglePassIterator.html               ][/                                                       ][/ .. |Forward| replace:: *Forward Traversal*            ][/ .. _Forward: ForwardTraversal.html                    ][/                                                       ][/ .. |Bidir| replace:: *Bidirectional Traversal*        ][/ .. _Bidir: BidirectionalTraversal.html                ][/                                                       ][/ .. |Random| replace:: *Random Access Traversal*       ][/ .. _Random: RandomAccessTraversal.html                ][h3 `iterator_concepts.hpp` Synopsis]    namespace boost_concepts {        // Iterator Access Concepts        template <typename Iterator>        class ReadableIteratorConcept;        template <            typename Iterator          , typename ValueType = std::iterator_traits<Iterator>::value_type        >        class WritableIteratorConcept;        template <typename Iterator>        class SwappableIteratorConcept;        template <typename Iterator>        class LvalueIteratorConcept;        // Iterator Traversal Concepts        template <typename Iterator>        class IncrementableIteratorConcept;        template <typename Iterator>        class SinglePassIteratorConcept;        template <typename Iterator>        class ForwardTraversalConcept;        template <typename Iterator>        class BidirectionalTraversalConcept;        template <typename Iterator>        class RandomAccessTraversalConcept;        // Interoperability        template <typename Iterator, typename ConstIterator>        class InteroperableIteratorConcept;    }[endsect][endsect]

⌨️ 快捷键说明

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