source: tests/zero_one.cfa @ 8e4f34e

Last change on this file since 8e4f34e was 8e4f34e, checked in by Michael Brooks <mlbrooks@…>, 8 days ago

Allow builtin ++ from += overloads, and similar, to work on a type witout a parameterless constructor

  • Property mode set to 100644
File size: 861 bytes
RevLine 
[fd0a1799]1#include <fstream.hfa>
2
3void foo(zero_t)
4{
5        sout | "It's a Zero!";
6}
7
8void foo(one_t)
9{
10        sout | "It's a One!";
11}
12
13void foo(int)
14{
15        sout | "It's a Number!";
16}
17
18void testOverloads()
19{
20        foo(0);
21        foo(1);
22        foo(2);
23}
24
25struct S { int i, j; };
26void ?{}( S & s, zero_t ) { s.[i,j] = 0; } // constructors
27void ?{}( S & s, one_t ) { s.[i,j] = 1; }
28S ?=?( S & dst, zero_t ) { dst.[i,j] = 0; return dst; } // assignment
29S ?=?( S & dst, one_t ) { dst.[i,j] = 1; return dst; }
30S ?+=?( S & s, one_t ) { s.[i,j] += 1; return s; } // increment
31S ?-=?( S & s, one_t ) { s.[i,j] -= 1; return s; }
32int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; } // comparison
33void testInitAssignQueryIncrement() {
34        S s = 0;
35        s = 0;
36        s = 1;
37        if ( s ) ++s;
38        sout | s.i | s.j;
39}
40
41int main() {
42        testOverloads();
43        testInitAssignQueryIncrement();
44        return 0;
45}
Note: See TracBrowser for help on using the repository browser.