From 5b9203d9d69c78048fbccfa8c98e5c5776bce67d Mon Sep 17 00:00:00 2001 From: Mike Ford Date: Sat, 30 May 2020 16:19:17 +0100 Subject: [PATCH] Added the "named_deduced_unit" type and more units to the fps system The named_deduced_unit type can be used as a named type for child for child deduced units --- src/include/units/physical/fps/area.h | 2 +- src/include/units/physical/fps/density.h | 46 +++++++++++++++++++++ src/include/units/physical/fps/energy.h | 9 +++-- src/include/units/physical/fps/force.h | 2 +- src/include/units/physical/fps/power.h | 5 +-- src/include/units/physical/fps/volume.h | 51 ++++++++++++++++++++++++ src/include/units/unit.h | 23 +++++++++++ 7 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 src/include/units/physical/fps/density.h create mode 100644 src/include/units/physical/fps/volume.h diff --git a/src/include/units/physical/fps/area.h b/src/include/units/physical/fps/area.h index cd83c0be..d5b7276e 100644 --- a/src/include/units/physical/fps/area.h +++ b/src/include/units/physical/fps/area.h @@ -38,7 +38,7 @@ using area = quantity; inline namespace literals { -// fm2 +// ft2 constexpr auto operator"" q_ft2(unsigned long long l) { return area(l); } constexpr auto operator"" q_ft2(long double l) { return area(l); } diff --git a/src/include/units/physical/fps/density.h b/src/include/units/physical/fps/density.h new file mode 100644 index 00000000..91f8d58f --- /dev/null +++ b/src/include/units/physical/fps/density.h @@ -0,0 +1,46 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +struct pound_per_foot_cub : unit {}; + +struct dim_density : physical::dim_density {}; + +template +using density = quantity; + +inline namespace literals { + +constexpr auto operator"" q_lb_per_ft3(unsigned long long l) { return density(l); } +constexpr auto operator"" q_lb_per_ft3(long double l) { return density(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/energy.h b/src/include/units/physical/fps/energy.h index d3cbd5e7..2cef53bd 100644 --- a/src/include/units/physical/fps/energy.h +++ b/src/include/units/physical/fps/energy.h @@ -32,14 +32,17 @@ namespace units::physical::fps { // https://en.wikipedia.org/wiki/Foot-poundal struct foot_poundal : unit {}; -// https://en.wikipedia.org/wiki/Foot-pound_(energy) -struct foot_pound_force : named_scaled_unit, foot_poundal> {}; - struct dim_energy : physical::dim_energy {}; +// https://en.wikipedia.org/wiki/Foot-pound_(energy) +struct foot_pound_force : named_deduced_unit {}; + + + template using energy = quantity; + inline namespace literals { constexpr auto operator"" q_ft_pdl(unsigned long long l) { return energy(l); } diff --git a/src/include/units/physical/fps/force.h b/src/include/units/physical/fps/force.h index cb038e09..cbd7e88b 100644 --- a/src/include/units/physical/fps/force.h +++ b/src/include/units/physical/fps/force.h @@ -34,7 +34,7 @@ namespace units::physical::fps { struct poundal : named_unit {}; // https://en.wikipedia.org/wiki/Pound_(force) -struct pound_force : named_scaled_unit, poundal> {}; +struct pound_force : named_scaled_unit, poundal> {}; diff --git a/src/include/units/physical/fps/power.h b/src/include/units/physical/fps/power.h index 3e572968..0110360a 100644 --- a/src/include/units/physical/fps/power.h +++ b/src/include/units/physical/fps/power.h @@ -31,11 +31,10 @@ namespace units::physical::fps { struct foot_poundal_per_second : unit {}; -struct foot_pound_force_per_second : scaled_unit, foot_poundal_per_second> {}; - - struct dim_power : physical::dim_power {}; +struct foot_pound_force_per_second : deduced_unit {}; + template using power = quantity; diff --git a/src/include/units/physical/fps/volume.h b/src/include/units/physical/fps/volume.h new file mode 100644 index 00000000..07b6f5f0 --- /dev/null +++ b/src/include/units/physical/fps/volume.h @@ -0,0 +1,51 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +struct cubic_foot : unit {}; +struct dim_volume : physical::dim_volume {}; + +struct cubic_yard : deduced_unit {}; + +template +using volume = quantity; + +inline namespace literals { + +// ft3 +constexpr auto operator"" q_ft3(unsigned long long l) { return volume(l); } +constexpr auto operator"" q_ft3(long double l) { return volume(l); } + +// yard3 +constexpr auto operator"" q_yd3(unsigned long long l) { return volume(l); } +constexpr auto operator"" q_yd3(long double l) { return volume(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 1c32ae24..500c2f5c 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -165,6 +165,29 @@ struct deduced_unit : downcast_child + requires detail::same_scaled_units && + (U::is_named && (URest::is_named && ... && true)) +struct named_deduced_unit : downcast_child> { + static constexpr bool is_named = true; + static constexpr auto symbol = detail::deduced_symbol_text(); + using prefix_family = no_prefix; +}; + // template // struct named_deduced_derived_unit : downcast_child> { // static constexpr bool is_named = true;