summaryrefslogtreecommitdiff
path: root/c++/unit.tmpl.hpp
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-29 14:18:30 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-29 14:18:30 +0200
commit700cde2d499742160deb361f42b7e861ae1db8ed (patch)
treeba796243a94578f9c2105080fa19040a341c4482 /c++/unit.tmpl.hpp
parentfb7dd1c9185da30aed8645c084be0722e061a867 (diff)
Renaming to new standard
Diffstat (limited to 'c++/unit.tmpl.hpp')
-rw-r--r--c++/unit.tmpl.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/c++/unit.tmpl.hpp b/c++/unit.tmpl.hpp
new file mode 100644
index 0000000..5eec43d
--- /dev/null
+++ b/c++/unit.tmpl.hpp
@@ -0,0 +1,53 @@
+#include <utility>
+
+namespace kel {
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+unit<StorageT,unit_component<UnitTypes, Exponents>...>::unit(const value_type& value_):
+ value{value_}{}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+unit<StorageT,unit_component<UnitTypes, Exponents>...>::unit(value_type&& value_):value{std::move(value_)}{}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+unit<StorageT,unit_component<UnitTypes, Exponents>...>& unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator=(const typename unit<StorageT,unit_component<UnitTypes, Exponents>...>::value_type& value_){
+ value = value_;
+ return *this;
+}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+unit<StorageT,unit_component<UnitTypes, Exponents>...>& unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator=(typename unit<StorageT,unit_component<UnitTypes, Exponents>...>::value_type&& value_){
+ value = std::move(value_);
+ return *this;
+}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+unit<StorageT,unit_component<UnitTypes, Exponents>...> unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator+(const unit<StorageT,unit_component<UnitTypes, Exponents>...>& rhs){
+ return value + rhs.value;
+}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+unit<StorageT,unit_component<UnitTypes, Exponents>...> unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator-(const unit<StorageT,unit_component<UnitTypes, Exponents>...>& rhs){
+ return value - rhs.value;
+}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+template<typename... Trhs>
+typename unit_multiplication<unit<StorageT,unit_component<UnitTypes,Exponents>...>, unit<StorageT, Trhs...>>::type
+unit<StorageT,unit_component<UnitTypes, Exponents>...>::operator*(const unit<StorageT,Trhs...>& rhs){
+ return value * rhs.data();
+}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+template<typename... Trhs>
+typename unit_multiplication<unit<StorageT,unit_component<UnitTypes,Exponents>...>, typename unit_invert<StorageT,Trhs...>::type>::type
+unit<StorageT,unit_component<UnitTypes,Exponents>...>::operator/(const unit<StorageT, Trhs...>& rhs){
+ typename unit_invert<StorageT, Trhs...>::type rhs_inverted{static_cast<StorageT>(1)/rhs.data()};
+ return value * rhs_inverted.data();
+}
+
+template<typename StorageT, typename... UnitTypes, int64_t... Exponents>
+typename unit<StorageT,unit_component<UnitTypes, Exponents>...>::value_type unit<StorageT,unit_component<UnitTypes, Exponents>...>::data() const {
+ return value;
+}
+}