diff options
author | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-07-29 14:18:30 +0200 |
---|---|---|
committer | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-07-29 14:18:30 +0200 |
commit | 700cde2d499742160deb361f42b7e861ae1db8ed (patch) | |
tree | ba796243a94578f9c2105080fa19040a341c4482 | |
parent | fb7dd1c9185da30aed8645c084be0722e061a867 (diff) |
Renaming to new standard
-rw-r--r-- | c++/distance/meter.hpp (renamed from c++/distance/meter.h) | 0 | ||||
-rw-r--r-- | c++/time/second.hpp (renamed from c++/time/second.h) | 0 | ||||
-rw-r--r-- | c++/unit.hpp (renamed from c++/unit.h) | 0 | ||||
-rw-r--r-- | c++/unit.tmpl.hpp (renamed from c++/unit.tmpl.h) | 0 | ||||
-rw-r--r-- | c++/unit_cast.hpp (renamed from c++/unit_cast.h) | 0 | ||||
-rw-r--r-- | c++/unit_print.hpp (renamed from c++/unit_print.h) | 0 | ||||
-rw-r--r-- | c++/unit_reduction.hpp (renamed from c++/unit_reduction.h) | 0 | ||||
-rw-r--r-- | examples/basic.cpp | 55 |
8 files changed, 55 insertions, 0 deletions
diff --git a/c++/distance/meter.h b/c++/distance/meter.hpp index 0d9fb3b..0d9fb3b 100644 --- a/c++/distance/meter.h +++ b/c++/distance/meter.hpp diff --git a/c++/time/second.h b/c++/time/second.hpp index 6dca456..6dca456 100644 --- a/c++/time/second.h +++ b/c++/time/second.hpp diff --git a/c++/unit.h b/c++/unit.hpp index a8e8320..a8e8320 100644 --- a/c++/unit.h +++ b/c++/unit.hpp diff --git a/c++/unit.tmpl.h b/c++/unit.tmpl.hpp index 5eec43d..5eec43d 100644 --- a/c++/unit.tmpl.h +++ b/c++/unit.tmpl.hpp diff --git a/c++/unit_cast.h b/c++/unit_cast.hpp index 8dc2689..8dc2689 100644 --- a/c++/unit_cast.h +++ b/c++/unit_cast.hpp diff --git a/c++/unit_print.h b/c++/unit_print.hpp index 4d9187b..4d9187b 100644 --- a/c++/unit_print.h +++ b/c++/unit_print.hpp diff --git a/c++/unit_reduction.h b/c++/unit_reduction.hpp index df02a4d..df02a4d 100644 --- a/c++/unit_reduction.h +++ b/c++/unit_reduction.hpp diff --git a/examples/basic.cpp b/examples/basic.cpp new file mode 100644 index 0000000..d322ac7 --- /dev/null +++ b/examples/basic.cpp @@ -0,0 +1,55 @@ +#include "../c++/kelunit/distance/meter.hpp" +#include "../c++/kelunit/time/second.hpp" + +#include "../c++/kelunit/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; +} |