File: usingmulti.yo

package info (click to toggle)
c%2B%2B-annotations 11.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,244 kB
  • sloc: cpp: 21,698; makefile: 1,505; ansic: 165; sh: 121; perl: 90
file content (49 lines) | stat: -rw-r--r-- 2,207 bytes parent folder | download | duplicates (5)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Now that tt(Multi) and its support templates have been developed, how can a
tt(Multi) be used?

A word of warning is in place. To reduce the size of the developed classes
they were designed in a minimalist way. For example, the tt(get) function
template cannot be used with tt(Multi const) objects and there is no default,
or move constructor available for tt(Multi) types. tt(Multi) was designed to
illustrate some of the possibilities of template meta programming and
hopefully tt(Multi)'s implementation served that purpose well. But can it be
used? If so, how?

This section provides some annotated examples. They may be concatenated to
define a series of statements that could be placed in a tt(main) function's
body, which would result in a working program.

    itemization(
    it() A simple tt(Policy) could be defined:
        verbinclude(//POLICY examples/multi.cc)
    tt(Policy) defines a data member and it can be used to define tt(Multi)
objects:
        verbinclude(//ONE examples/multi.cc)

    it() To obtain the number of types defined by a tt(Multi) class or object
    either use the tt(::size) enum value (using the tt(Multi) class) or the
tt(.size) member (using the tt(Multi) object):
        verbinclude(//TWO examples/multi.cc)

    it() Variables of constituting types can be defined using tt(plainTypeAt):
        verbinclude(//THREE examples/multi.cc)

    it() Raw static casts can be used to obtain the constituent type:
        verbinclude(//FIVE examples/multi.cc)

    it() However, this won't work when the template parameter pack contains
identical types, as a cast can't distinguish between identical
tt(Policy<Type>) types. In that case tt(get) still works fine:
        verbinclude(//SIX examples/multi.cc)

    it() Here is an example wrapping a tt(std::vector) in a tt(Vector):
        verbinclude(//SEVEN examples/multi.cc)

    it() Such a vector can be defined by its tt(Multi) type:
        verbinclude(//EIGHT examples/multi.cc)

    it() Knowing that a tt(Vector) is a tt(std::vector), the reference
returned by tt(get) support index operators that can be used as left hand side
or right hand side operands:
        verbinclude(//NINE examples/multi.cc)
    )