File: boundfriends.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (28 lines) | stat: -rw-r--r-- 1,565 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Earlier, in section ref(FREEBOUND) the construction of free operators of
nested classes of template classes was covered. There the nested classes
defined typenames which were thereupon used to select the appropriate free
operators by defining template parameters of the typenames that were defined
by the nested classes.

Concepts provide yet another way to define free operators, bound to the types of
the nested classes' template types. When using concepts the class
templates and their nested classes can be defined in their most basic form, as
in: 
    verbinclude(-s4 //string examples/bounditer/main.cc)

Once the class interface (tt(struct String)) has been specified the concept
can be formulated. It simply requires that the arguments of the free operators
are tt(String<Data>::iterator) objects:
    verbinclude(-s4 //concept examples/bounditer/main.cc)

The free operator(s) can now be defined as a function template using the
abbreviated tt(StringIterator auto) type specification:
    verbinclude(-s4 //operator examples/bounditer/main.cc)

By using concepts when defining free operators of nested classes of class
templates we achieve that those operators are bound to the template types of
those class templates, and that the free operators perfectly match those
(nested) classes. Furthermore, when designing the class templates the software
engineer can concentrate on the class's essential characteristics without
having to consider special type-definitions, which are required when using the
em(sfinae) approach covered in section ref(FREEBOUND).