File: test_templates.cxx

package info (click to toggle)
libdecaf 1.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,280 kB
  • sloc: ansic: 8,294; cpp: 2,606; python: 421; makefile: 21
file content (29 lines) | stat: -rw-r--r-- 702 bytes parent folder | download | duplicates (2)
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
#include "decaf/expr.hxx"

class Foo {
private:
    template<BinOp OP, class L, class R, class T> friend class BinExpr;
    template<UnOp OP, class R, class T> friend class UnExpr;
    template<class T> friend struct Reify;
    Foo(const NOINIT&) {}
public:
    int x;
    Foo(int x) : x(x) {}
};

namespace decaf { namespace internal {
DECLARE_BINOP(ADD,Foo,Foo,Foo,out.x = l.x+r.x)
DECLARE_BINOP(SUB,Foo,Foo,Foo,out.x = l.x-r.x)
DECLARE_BINOP(MUL,Foo,Foo,Foo,out.x = l.x*r.x)
DECLARE_BINOP(EQ,Foo,Foo,bool,out = l.x==r.x)
DECLARE_PARTIAL_UNOP(INV,Foo,Foo,out.x = 1/r.x; return (r.x!=0))
}}

Foo frobble() {
    Foo a(1);
    a = a+a+a;
    a = a*a;
    a = a/a;
    (void)(a==(a+a));
    return a;
}