File: basictype.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 (60 lines) | stat: -rw-r--r-- 2,535 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
The tt(BinExpr) expression template needs to be aware of two types before it
can instantiate objects. First, tt(ObjType) must be known, as this is the 
type of object that is handled by the expression template. tt(ObjType) objects
contain values, and we require that the type of these values can be determined
as tt(ObjType::value_type). E.g., for our tt(IntVect) data type tt(value_type)
is tt(int). 

In expressions like tt(one + two + three), the tt(BinExpr) expression template
receives two tt(IntVect) objects. This is always true: the tt(BinExpr) that is
first constructed receives two tt(IntVect) objects. In this case tt(ObjType)
is simply tt(LHS), and tt(ObjType::value_type) is also available: either
tt(value_type) is already defined by tt(LHS) or tt(BinExpr) em(requires) that
it defines type tt(value_type). 

Since arguments to tt(BinExpr) objects are not em(always) of the basic
tt(ObjType) type (tt(BinExpr) objects at the next nesting level receive at
least one tt(BinExpr) argument) we need a way to determine tt(ObjType) from a
tt(BinExpr). For this we use a em(trait class). The 
trait class tt(BasicType) receives a typename template argument, and equates
its type tt(ObjType) to the received template type argument:
        verb(    template<typename Type>
    struct BasicType
    {
        using ObjType = Type ;
    };)

A specialization handles the case where tt(Type) in fact is a tt(BinExpr):
    template<typename LHS, typename RHS, template<typename> class Operation>
        verb(    template<typename LHS, typename RHS, template<typename> class Operation>
    struct BasicType<BinExpr<LHS, RHS, Operation>>
    {
        using ObjType = BinExpr<LHS, RHS, Operation>::ObjType ;
    };)

Since tt(BinExpr) em(requires) that tt(ObjType::value_type) is a defined
type, tt(value_type) has automatically been taken care of. 

    As tt(BinExpr) refers to tt(BasicType) and tt(BasicType) refers to
tt(BinExpr) somewhere we must provide a forward declaration. As tt(BinExpr's)
declaration has already been provided, we start with that declaration,
resulting in:
        verb(    BinExpr's declaration

    BasicType's definition

    BasicType's specialization (for BinExpr)

    template<typename LHS, typename RHS, template<typename> class Operation>
    class BinExpr 
    {
        LHS const &d_lhs;
        RHS const &d_rhs;

        public:
            using DataType = BasicType<RHS>::DataType ;
            using type = DataType::value_type value_;

            // all BinExpr member functions
    };)