source: tests/userLiterals.cfa @ 4ff7ea3

Last change on this file since 4ff7ea3 was e326ebca, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

fix 32-bit build problem

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[73abe95]1//
[f47ba55]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.
[73abe95]6//
[c9f4cf8]7// userLiterals.cfa --
[73abe95]8//
[f47ba55]9// Author           : Peter A. Buhr
10// Created On       : Wed Sep  6 21:40:50 2017
11// Last Modified By : Peter A. Buhr
[e326ebca]12// Last Modified On : Wed Feb 19 07:48:45 2020
13// Update Count     : 74
[73abe95]14//
[f47ba55]15
[73abe95]16#include <fstream.hfa>
[eb68ebb]17#include <wchar.h>
18#include <uchar.h>
19
[200fcb3]20int ?`s( int s ) { sout | "secs" | s; return s; }
21int ?`m( int m ) { sout | "mins" | m; return m * 60; }
22int ?`h( int h ) { sout | "hours" | h; return h * 3600; }
23int ?`_A_( int x ) { sout | "_A_" | x; return x; }
24int ?`__thingy_( int x ) { sout | "_thingy_" | x; return x; }
[eb68ebb]25
[c9f4cf8]26int ?`s( const char * s ) { sout | "s" | s; return 0; }
27int ?`m( const char16_t * m ) { sout | "m" | m; return 0;}
28int ?`h( const char32_t * h ) { sout | "h" | h; return 0; }
[200fcb3]29int ?`_A_( const wchar_t * str ) { sout | "_A_" | str; return 0; }
30int ?`__thingy_( const char * str ) { sout | "_thingy_" | str; return 0; }
[eb68ebb]31
[f47ba55]32
[ea46db7]33struct Weight { double stones; };
34void ?{}( Weight & w ) { w.stones = 0; }
[f47ba55]35void ?{}( Weight & w, double w ) { w.stones = w; }
[ea46db7]36Weight ?+?( Weight l, Weight r ) {
37        return (Weight){ l.stones + r.stones };
38}
[c9f4cf8]39ofstream & ?|?( ofstream & os, Weight w ) { return os | wd(1,1, w.stones); }
40void ?|?( ofstream & os, Weight w ) { (ofstream)(os | w); ends( os ); }
[f47ba55]41
[cd218e8]42Weight ?`st( double w ) { return (Weight){ w }; }               // backquote for user literals
[f47ba55]43Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
[ea46db7]44Weight ?`kg( double w ) { return (Weight) { w * 0.16 }; }
[eb68ebb]45
[f47ba55]46int main() {
[ea46db7]47        Weight w, heavy = { 20 };                                                       // 20 stone
[cd218e8]48        w = 155`lb;
[200fcb3]49        sout | w;
[ea46db7]50        w = 0b_1111`st;
[200fcb3]51        sout | w;
[cd218e8]52        w = 0_233`lb;                                                                           // octal weight (155)
[200fcb3]53        sout | w;
[ea46db7]54        w = 0x_9b_u`kg;
[200fcb3]55        sout | w;
[ea46db7]56        w = 70.3`kg;
[200fcb3]57        sout | w;
[ea46db7]58        w = 11`st + 1`lb;
[200fcb3]59        sout | w;
[ea46db7]60        w = 5`st + 8`kg + 25`lb + heavy;
[200fcb3]61        sout | w;
[f47ba55]62
[c9f4cf8]63        0`s;
[eb68ebb]64        1`s;
65        23`s;
66        23u`m;
67        23l`h;
68        23_ul`_A_;
69        1_234_LL`__thingy_;
70
71        0xff_ffl;
72        0xff_ff`s;
73        0xff_ffu`m;
74        0xff_ffl`h;
75        0xff_fful`_A_;
76        0xff_ffLL`__thingy_;
77
[cd218e8]78        '\n'`s;
79        L'\n'`h;
80        u'\n'`m;
81        L_'\n'`_A_;
82        U_'\n'`__thingy_;
[f47ba55]83
[eb68ebb]84        "abc"`s;
[e326ebca]85        // FIX ME: requires char16_t, char32_t, and wchar_t be unique types
86        // u"abc"`m;
87        // U_"abc"`h;
88        // L"abc"`_A_;
[eb68ebb]89        u8_"abc"`__thingy_;
90} // main
[f47ba55]91
92// Local Variables: //
93// tab-width: 4 //
[c9f4cf8]94// compile-command: "cfa userLiterals.cfa" //
[f47ba55]95// End: //
Note: See TracBrowser for help on using the repository browser.