| 1 |
We've already encountered various examples of em(simple requirements): they |
| 2 |
specify the operations that must be supported by the variable(s) declared in |
| 3 |
the parameter lists of tt(requires) specifications. When the requirements |
| 4 |
refer to single variables single tt(Type) parameters suffice; when |
| 5 |
requirements involve different types then the concept's template head declares |
| 6 |
those different types and the tt(requires) parameter list will usually define |
| 7 |
variables of those different types. The tt(concept BasicMath) specifies two |
| 8 |
types, and uses four simple requirements to specify the four basic arithmetic |
| 9 |
operations: |
| 10 |
verbinsert(-as4 examples/basicmath.cc) |
| 11 |
|
| 12 |
Specifying constraints does not necessarily mean that the constraints as |
| 13 |
specified literally apply to run-time situations. To require the existence of |
| 14 |
the index operator the following simple requirement can be used: |
| 15 |
verbinsert(-s4 //index examples/simple.cc) |
| 16 |
|
| 17 |
Here the em(stand-in argument) 0 is used to specify the index operator's |
| 18 |
argument. The argument value used in the simple requirement really is a |
| 19 |
stand-in. The following code fragment compiles, as tt(string) supports the |
| 20 |
index operator. Although argument 0 is used in the simple requirement |
| 21 |
specification the argument 5 is in fact being used: |
| 22 |
verb( string str; |
| 23 |
idx(str, 5);) |
| 24 |
|
| 25 |
Other than tt(int) index types can be specified analogously. Here is an |
| 26 |
example showing how to define and use a concept tt(HasStrIndex) requiring the |
| 27 |
availability of tt(std::string) arguments of index operators: |
| 28 |
verbinsert(-s4 //stridx examples/stridx.cc) |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|