Update basic.cpp
parent
1dcc94ddde
commit
4dfcfaf821
|
@ -6,6 +6,18 @@
|
|||
#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 = kelun::scalar<float>;
|
||||
using meter = kelun::meter<float>;
|
||||
using square_meter = kelun::square_meter<float>;
|
||||
|
@ -17,15 +29,18 @@ int main(){
|
|||
|
||||
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;
|
||||
|
||||
auto mps = b / s;
|
||||
|
||||
std::cout<<"Values:\n";
|
||||
std::cout<<"a: "<<a<<"\n";
|
||||
std::cout<<"b: "<<b<<"\n";
|
||||
|
|
Loading…
Reference in New Issue