Postfix Call Examples

Weight

Comparison of weight units.

C∀C++
struct Weight {
double stones;
};
void ?{}( Weight & w ) { w.stones = 0; }
void ?{}( Weight & w, double w ) { w.stones = w; }
Weight ?+?( Weight l, Weight r ) {
return (Weight){ l.stones + r.stones };
}
Weight ?`st( double w ) { return (Weight){ w }; }
Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
Weight ?`kg( double w ) { return (Weight){ w * 0.16 }; }

int main() {
Weight w, heavy = { 20 };
w = 155`lb;
w = 0b_1111`st;
w = 0_233`lb;
w = 0x_9b_u`kg;
w = 5.5`st + 8`kg + 25.01`lb + heavy;
}
struct Weight {
double stones;
Weight() { stones = 0.0; }
Weight( double w ) { stones = w; }
};
Weight operator+( Weight l, Weight r ) {
return Weight( l.stones + r.stones );
}
Weight operator""_st( unsigned long long int w ) { return Weight( w); }
Weight operator""_lb( unsigned long long int w ) { return Weight( w / 14.0); }
Weight operator""_kg( unsigned long long int w ) { return Weight( w * 0.16); }
Weight operator""_st( long double w ) { return Weight( w ); }
Weight operator""_lb( long double w ) { return Weight( w / 14.0 ); }
Weight operator""_kg( long double w ) { return Weight( w * 0.16 ); }
int main() {
Weight w, heavy = { 20 };
w = 155_lb;
w = 0b1111_lb;		// error, binary unsupported
w = 0'233_lb;		// quote separator
w = 0x9b_kg;
w = 5.5d_st + 8_kg + 25.01_lb + heavy;
}

Time

Comparison of time units.

C∀C++
#include <fstream.hfa>
#include <time.hfa>

Duration s = 1`h + 2 * 10`m + 70`s / 10;
sout | "1 hour + 2*10 min + 70/10 sec = " | s | "seconds";
sout | "Dividing that by 2 minutes gives" | s / 2`m;
sout | "Dividing that by 2 gives" | s / 2 | "seconds\n";
sout | s | "seconds is"
| s`h | "hours,"
| (s % 1`h)`m | "minutes,"
| (s % 1`m)`s | "seconds";
#include <iostream>
#include <chrono>
using namespace std;
using namespace std::chrono;
seconds s = hours(1) + 2 * minutes(10) + seconds(70) / 10;
cout << "1 hour + 2*10 min + 70/10 sec = " << s.count() << " seconds\n";
cout << "Dividing that by 2 minutes gives " << s / minutes(2) << '\n';
cout << "Dividing that by 2 gives " << (s / 2).count() << " seconds\n";
cout << s.count() << " seconds is "
<< duration_cast<hours>( s ).count() << " hours, "
<< duration_cast<minutes>( s % hours(1) ).count() << " minutes, "
<< duration_cast<seconds>( s % minutes(1) ).count() << " seconds\n";