ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
Last change
on this file since 9f5ecf5 was f47ba55, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago |
add user-literal test
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[f47ba55] | 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 |
|
---|
| 18 | struct Weight {
|
---|
| 19 | double stones;
|
---|
| 20 | };
|
---|
| 21 | void ?{}( Weight & w ) { w.stones = 0; } // constructors
|
---|
| 22 | void ?{}( Weight & w, double w ) { w.stones = w; }
|
---|
| 23 |
|
---|
| 24 | Weight ?+?( Weight l, Weight r ) { return (Weight){ l.stones + r.stones }; }
|
---|
| 25 | ofstream * ?|?( ofstream * os, Weight w ) { return os | w.stones; }
|
---|
| 26 |
|
---|
| 27 | Weight ?`st( double w ) { return (Weight){ w }; } // user literals
|
---|
| 28 | Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
|
---|
| 29 | Weight ?`kg( double w ) { return (Weight) { w * 0.1575}; }
|
---|
| 30 |
|
---|
| 31 | 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 | }
|
---|
| 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.