| 1 |
Sometimes templates must use sub-types of template types. Examples are |
| 2 |
templates assuming the existence of tt(iterator) (like |
| 3 |
tt(vector<int>::iterator)) or tt(value_type) which is used when calling |
| 4 |
tt(std::push_back). |
| 5 |
|
| 6 |
To specify that a sub-type must be available the concept's tt(requires) |
| 7 |
specification needs no parameters, but can directly refer to the subtype. It's |
| 8 |
also possible to combine type requirements with requirements that em(do) |
| 9 |
define a non-empty parameter list, and so the tt(requires's) parameter list |
| 10 |
does not em(have) to be empty. Here is a concept that specifies a plain type |
| 11 |
requirement: |
| 12 |
verb( template <typename Type> |
| 13 |
concept HasValueType = |
| 14 |
requires() |
| 15 |
{ |
| 16 |
typename Type::value_type; |
| 17 |
};) |
| 18 |
and here's a concept that combines a simple requirement with a type |
| 19 |
requirement: |
| 20 |
verbinsert(-s4 //type examples/type.cc) |
| 21 |
Calling tt(iter) with a tt(string) argument succeeds, calling it with a |
| 22 |
tt(queue) argument results in two error notes: no tt(Type::iterator) and no |
| 23 |
tt(tp.begin()). |
| 24 |
|
| 25 |
Types specified in type requirements don't necessarily have to refer to |
| 26 |
em(types). They may also specify be the names of nested classes or |
| 27 |
enumerations defined by tt(Type). When specifying enumerations they do not |
| 28 |
have to be strongly typed. |