全部博文(174)
分类: C/C++
2009-03-08 00:21:44
|
The Bidirectional Iterator concept is very similar to the Input Iterator concept: it simply imposes some additional requirements. The types that are models of Bidirectional Iterator are a subset of the types that are models of Input Iterator: every type that is a model of Bidirectional Iterator is also a model of Input Iterator. Int*, for example, is both a model of Bidirectional Iterator and a model of Input Iterator, but , is only a model of Input Iterator: it does not conform to the more stringent Bidirectional Iterator requirements.
如果一个Concept在另一个Concept的要求之外还有其他的要求,那么我们说这个Concept是对原来的refinement,它是其中一个子集。类似在C++里的继承,但是继承是针对类型来说,在C++里并没有Concept和Model的术语,它是范式编程的术语。要理解下面这句话:
如果一种类型是某一个Concept的Model,而这个Concept是另一个Concept的Refinement,那么这种类型也是原来的Concept的一个Model。
Other parts of the STL
First, the STL includes several utilities: very basic concepts and
functions that are used in many different parts of the library. The concept
, for example, describes types that
have assignment operators and copy constructors; almost all STL classes are
models of Assignable, and almost all STL algorithms require their
arguments to be models of Assignable.
Second, the STL includes some low-level mechanisms for allocating and
deallocating memory. are very
specialized, and you can safely ignore them for almost all purposes.
Finally, the STL includes a large collection of , also known as functors.
Just as iterators are a generalization of pointers, function objects are a
generalization of functions: a function object is anything that you can call
using the ordinary function call syntax. There are several different concepts
relating to function objects, including (a function object that takes a single argument, i.e.
one that is called as f(x)) and (a function object that takes two arguments, i.e. one
that is called as f(x, y)). Function objects are an important part of
generic programming because they allow abstraction not only over the types of
objects, but also over the operations that are being performed.