source: src/tests/user_literals.c @ f47ba55

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since f47ba55 was f47ba55, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add user-literal test

  • Property mode set to 100644
File size: 1.3 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// user_literals.c --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed Sep  6 21:40:50 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Sep  6 23:19:08 2017
13// Update Count     : 36
14//
15
16#include <fstream>
17
18struct Weight {
19    double stones;
20};
21void ?{}( Weight & w ) { w.stones = 0; }        // constructors
22void ?{}( Weight & w, double w ) { w.stones = w; }
23
24Weight ?+?( Weight l, Weight r ) { return (Weight){ l.stones + r.stones }; }
25ofstream * ?|?( ofstream * os, Weight w ) { return os | w.stones; }
26
27Weight ?`st( double w ) { return (Weight){ w }; } // user literals
28Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
29Weight ?`kg( double w ) { return (Weight) { w * 0.1575}; }
30
31int main() {
32    Weight w, hw = { 14 };
33    w = 11`st + 1`lb;
34    sout | w | endl;
35    w = 70.3`kg;
36    sout | w | endl;
37    w = 155`lb;
38    sout | w | endl;
39    w = 0x9b`lb;                // hexadecimal weight
40    sout | w | endl;
41    w = 0233`lb;                // octal weight
42    sout | w | endl;
43    w = 5`st + 8`kg + 25`lb + hw;
44    sout | w | endl;
45}
46
47
48
49// Local Variables: //
50// tab-width: 4 //
51// compile-command: "cfa user_literals.c" //
52// End: //
Note: See TracBrowser for help on using the repository browser.