Changeset b2e2e34 for src/tests/user_literals.c
- Timestamp:
- Sep 12, 2017, 4:08:01 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- c935c3a
- Parents:
- 21a1efb (diff), a46478a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/user_literals.c
r21a1efb rb2e2e34 10 10 // Created On : Wed Sep 6 21:40:50 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Sep 6 23:19:08201713 // Update Count : 3612 // Last Modified On : Sat Sep 9 08:31:32 2017 13 // Update Count : 48 14 14 // 15 15 16 16 #include <fstream> 17 #include <wchar.h> 18 #include <uchar.h> 19 20 int ?`s( int s ) { sout | "secs" | s | endl; return s; } 21 int ?`m( int m ) { sout | "mins" | m | endl; return m * 60; } 22 int ?`h( int h ) { sout | "hours" | h | endl; return h * 3600; } 23 int ?`_A_( int x ) { sout | "_A_" | x | endl; return x; } 24 int ?`__thingy_( int x ) { sout | "_thingy_" | x | endl; return x; } 25 26 int ?`s( const char * s ) { sout | "secs" | s | endl; return 0; } 27 int ?`m( const char16_t * m ) { sout | "mins" | m | endl; return 0;} 28 int ?`h( const char32_t * h ) { sout | "hours" | h | endl; return 0; } 29 int ?`_A_( const wchar_t * str ) { sout | "_A_" | str | endl; return 0; } 30 int ?`__thingy_( const char * str ) { sout | "_thingy_" | str | endl; return 0; } 31 17 32 18 33 struct Weight { 19 34 double stones; 20 35 }; 21 void ?{}( Weight & w ) { w.stones = 0; } // constructors36 void ?{}( Weight & w ) { w.stones = 0; } // operations 22 37 void ?{}( Weight & w, double w ) { w.stones = w; } 23 24 38 Weight ?+?( Weight l, Weight r ) { return (Weight){ l.stones + r.stones }; } 25 39 ofstream * ?|?( ofstream * os, Weight w ) { return os | w.stones; } 26 40 27 Weight ?`st( double w ) { return (Weight){ w }; } //user literals41 Weight ?`st( double w ) { return (Weight){ w }; } // backquote for user literals 28 42 Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; } 29 43 Weight ?`kg( double w ) { return (Weight) { w * 0.1575}; } 30 44 45 31 46 int 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 } 47 Weight w, hw = { 14 }; // 14 stone 48 w = 11`st + 1`lb; 49 sout | w | endl; 50 w = 70.3`kg; 51 sout | w | endl; 52 w = 155`lb; 53 sout | w | endl; 54 w = 0x_9b_u`lb; // hexadecimal unsigned weight (155) 55 sout | w | endl; 56 w = 0_233`lb; // octal weight (155) 57 sout | w | endl; 58 w = 5`st + 8`kg + 25`lb + hw; 59 sout | w | endl; 46 60 61 // 0`secs; 62 1`s; 63 23`s; 64 23u`m; 65 23l`h; 66 23_ul`_A_; 67 1_234_LL`__thingy_; 47 68 69 0xff_ffl; 70 0xff_ff`s; 71 0xff_ffu`m; 72 0xff_ffl`h; 73 0xff_fful`_A_; 74 0xff_ffLL`__thingy_; 75 76 '\n'`s; 77 L'\n'`h; 78 u'\n'`m; 79 L_'\n'`_A_; 80 U_'\n'`__thingy_; 81 82 "abc"`s; 83 u"abc"`m; 84 U_"abc"`h; 85 L"abc"`_A_; 86 u8_"abc"`__thingy_; 87 } // main 48 88 49 89 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.