source: src/tests/user_literals.c @ 6de9f4a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 6de9f4a was eb68ebb, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

extend test program

  • Property mode set to 100644
File size: 2.2 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 : Thu Sep  7 22:53:49 2017
13// Update Count     : 39
14//
15
16#include <fstream>
17#include <wchar.h>
18#include <uchar.h>
19
20int ?`s( int s ) { sout | "secs" | s | endl; }
21int ?`m( int m ) { sout | "mins" | m | endl; }
22int ?`h( int h ) { sout | "hours" | h | endl; }
23int ?`_A_( int x ) { sout | "_A_" | x | endl; }
24int ?`__thingy_( int x ) { sout | "_thingy_" | x | endl; }
25
26int ?`s( const char * s ) { sout | "secs" | s | endl; }
27int ?`m( const char16_t * m ) { sout | "mins" | m | endl; }
28int ?`h( const char32_t * h ) { sout | "hours" | h | endl; }
29int ?`_A_( const wchar_t * x ) { sout | "_A_" | x | endl; }
30int ?`__thingy_( const char * x ) { sout | "_thingy_" | x | endl; }
31
32
33struct Weight {
34    double stones;
35};
36void ?{}( Weight & w ) { w.stones = 0; }        // constructors
37void ?{}( Weight & w, double w ) { w.stones = w; }
38
39Weight ?+?( Weight l, Weight r ) { return (Weight){ l.stones + r.stones }; }
40ofstream * ?|?( ofstream * os, Weight w ) { return os | w.stones; }
41
42Weight ?`st( double w ) { return (Weight){ w }; } // user literals
43Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
44Weight ?`kg( double w ) { return (Weight) { w * 0.1575}; }
45
46
47int main() {
48    Weight w, hw = { 14 };
49    w = 11`st + 1`lb;
50    sout | w | endl;
51    w = 70.3`kg;
52    sout | w | endl;
53    w = 155`lb;
54    sout | w | endl;
55    w = 0x9b`lb;                // hexadecimal weight
56    sout | w | endl;
57    w = 0233`lb;                // octal weight
58    sout | w | endl;
59    w = 5`st + 8`kg + 25`lb + hw;
60    sout | w | endl;
61
62//      0`secs;
63        1`s;
64        23`s;
65        23u`m;
66        23l`h;
67        23_ul`_A_;
68        1_234_LL`__thingy_;
69
70        0xff_ffl;
71        0xff_ff`s;
72        0xff_ffu`m;
73        0xff_ffl`h;
74        0xff_fful`_A_;
75        0xff_ffLL`__thingy_;
76
77    '\n'`s;
78    L'\n'`h;
79    u'\n'`m;
80    L_'\n'`_A_;
81    U_'\n'`__thingy_;
82
83        "abc"`s;
84        u"abc"`m;
85        U_"abc"`h;
86        L"abc"`_A_;
87        u8_"abc"`__thingy_;
88} // main
89
90// Local Variables: //
91// tab-width: 4 //
92// compile-command: "cfa user_literals.c" //
93// End: //
Note: See TracBrowser for help on using the repository browser.