blob: 2c852ac4da73dd0b4b56e2c9188b632e4274e38b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include "../c++/distance/meter.hpp"
#include "../c++/time/second.hpp"
#include "../c++/unit_print.hpp"
#include <iostream>
int main(){
/**
* The definition is a bit convoluted, so I leave it in the hands of the headers themselves and define a convenience alias for the user.
* meter e.g. is defined by
*
* namespace unit_type {
* struct meter {};
* }
* template<typename S>
* using meter = unit<S, unit_base<unit_type::meter, 1>>;
*
* which then can be used as follows
*/
using scalar = kel::scalar<float>;
using meter = kel::meter<float>;
using square_meter = kel::square_meter<float>;
using second = kel::second<float>;
meter a = 6.f;
meter b = 3.f;
second s = 10.f;
// Since it is not compileable I cannot show it, but c + s would throw a compilation error.
meter c = a+b;
meter d = a-b;
// Auto deduced type. Based on the template parameters automatically stitches together a valid unit
auto mps = b / s;
// Technically auto deduced, but predefined for convenience.
square_meter e = a*b;
//
scalar f = a/b;
std::cout<<"Values:\n";
std::cout<<"a: "<<a<<"\n";
std::cout<<"b: "<<b<<"\n";
std::cout<<"c: "<<c<<"\n";
std::cout<<"d: "<<d<<"\n";
std::cout<<"e: "<<e<<"\n";
std::cout<<"f: "<<f<<"\n";
std::cout<<"mps: "<<mps<<"\n";
std::cout<<std::endl;
return 0;
}
|