| 1 |
Earlier, in section ref(FREEBOUND) the construction of free operators of |
| 2 |
nested classes of template classes was covered. There the nested classes |
| 3 |
defined typenames which were thereupon used to select the appropriate free |
| 4 |
operators by defining template parameters of the typenames that were defined |
| 5 |
by the nested classes. |
| 6 |
|
| 7 |
Concepts provide yet another way to define free operators, bound to the types of |
| 8 |
the nested classes' template types. When using concepts the class |
| 9 |
templates and their nested classes can be defined in their most basic form, as |
| 10 |
in: |
| 11 |
verbinclude(-s4 //string examples/bounditer/main.cc) |
| 12 |
|
| 13 |
Once the class interface (tt(struct String)) has been specified the concept |
| 14 |
can be formulated. It simply requires that the arguments of the free operators |
| 15 |
are tt(String<Data>::iterator) objects: |
| 16 |
verbinclude(-s4 //concept examples/bounditer/main.cc) |
| 17 |
|
| 18 |
The free operator(s) can now be defined as a function template using the |
| 19 |
abbreviated tt(StringIterator auto) type specification: |
| 20 |
verbinclude(-s4 //operator examples/bounditer/main.cc) |
| 21 |
|
| 22 |
By using concepts when defining free operators of nested classes of class |
| 23 |
templates we achieve that those operators are bound to the template types of |
| 24 |
those class templates, and that the free operators perfectly match those |
| 25 |
(nested) classes. Furthermore, when designing the class templates the software |
| 26 |
engineer can concentrate on the class's essential characteristics without |
| 27 |
having to consider special type-definitions, which are required when using the |
| 28 |
em(sfinae) approach covered in section ref(FREEBOUND). |