diff --git a/example/example.cpp b/example/example.cpp index 2729bf33..6e89dda0 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "units/si/velocity.h" +#include #include namespace { diff --git a/src/include/units/si/base_dimensions.h b/src/include/units/base_dimensions.h similarity index 91% rename from src/include/units/si/base_dimensions.h rename to src/include/units/base_dimensions.h index b939e86a..293bb227 100644 --- a/src/include/units/si/base_dimensions.h +++ b/src/include/units/base_dimensions.h @@ -22,7 +22,7 @@ #pragma once -#include "../dimension.h" +#include namespace units { @@ -31,9 +31,9 @@ namespace units { struct base_dim_length : dim_id<0> {}; struct base_dim_mass : dim_id<1> {}; struct base_dim_time : dim_id<2> {}; - struct base_dim_electric_current : dim_id<3> {}; + struct base_dim_current : dim_id<3> {}; struct base_dim_temperature : dim_id<4> {}; - struct base_dim_amount_of_substance : dim_id<5> {}; + struct base_dim_substance : dim_id<5> {}; struct base_dim_luminous_intensity : dim_id<6> {}; } // namespace units diff --git a/src/include/units/bits/type_list.h b/src/include/units/bits/type_list.h index 2e25082c..5a493e8a 100644 --- a/src/include/units/bits/type_list.h +++ b/src/include/units/bits/type_list.h @@ -22,7 +22,7 @@ #pragma once -#include "tools.h" +#include #include namespace mp { diff --git a/src/include/units/current.h b/src/include/units/current.h new file mode 100644 index 00000000..06e918ab --- /dev/null +++ b/src/include/units/current.h @@ -0,0 +1,50 @@ +// 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 + +namespace units { + + struct dimension_current : make_dimension_t> {}; + template<> struct upcasting_traits> : upcast_to {}; + + template + concept bool Current = Quantity && std::experimental::ranges::Same; + + template + using current = quantity; + + struct ampere : unit> {}; + template<> struct upcasting_traits> : upcast_to {}; + + inline namespace literals { + + // A + constexpr auto operator""_A(unsigned long long l) { return current(l); } + constexpr auto operator""_A(long double l) { return current(l); } + + } + +} // namespace units diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index 29791b49..1ce9956c 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -22,8 +22,8 @@ #pragma once -#include "bits/tools.h" -#include "bits/type_list.h" +#include +#include namespace units { diff --git a/src/include/units/si/frequency.h b/src/include/units/frequency.h similarity index 97% rename from src/include/units/si/frequency.h rename to src/include/units/frequency.h index 319a0a05..c2e8b37e 100644 --- a/src/include/units/si/frequency.h +++ b/src/include/units/frequency.h @@ -22,14 +22,20 @@ #pragma once -#include "base_dimensions.h" -#include "time.h" +#include +#include namespace units { struct dimension_frequency : make_dimension_t> {}; template<> struct upcasting_traits> : upcast_to {}; + template + concept bool Frequency = Quantity && std::experimental::ranges::Same; + + template + using frequency = quantity; + struct millihertz : unit {}; template<> struct upcasting_traits> : upcast_to {}; @@ -48,12 +54,6 @@ namespace units { struct terahertz : unit {}; template<> struct upcasting_traits> : upcast_to {}; - template - using frequency = quantity; - - template - concept bool Frequency = Quantity && std::experimental::ranges::Same; - inline namespace literals { // mHz diff --git a/src/include/units/si/length.h b/src/include/units/length.h similarity index 96% rename from src/include/units/si/length.h rename to src/include/units/length.h index 48766f21..be662b5c 100644 --- a/src/include/units/si/length.h +++ b/src/include/units/length.h @@ -22,15 +22,20 @@ #pragma once -#include "base_dimensions.h" -#include "../quantity.h" +#include +#include namespace units { - // dimension struct dimension_length : make_dimension_t> {}; template<> struct upcasting_traits> : upcast_to {}; + template + concept bool Length = Quantity && std::experimental::ranges::Same; + + template + using length = quantity; + // SI units struct millimeter : unit {}; template<> struct upcasting_traits> : upcast_to {}; @@ -44,26 +49,6 @@ namespace units { struct kilometer : unit {}; template<> struct upcasting_traits> : upcast_to {}; - // US customary units - struct yard : unit> {}; - template<> struct upcasting_traits> : upcast_to {}; - - struct foot : unit, yard::ratio>> {}; - template<> struct upcasting_traits> : upcast_to {}; - - struct inch : unit, foot::ratio>> {}; - template<> struct upcasting_traits> : upcast_to {}; - - struct mile : unit, yard::ratio>> {}; - template<> struct upcasting_traits> : upcast_to {}; - - // length - template - using length = quantity; - - template - concept bool Length = Quantity && std::experimental::ranges::Same; - inline namespace literals { // mm @@ -82,6 +67,23 @@ namespace units { constexpr auto operator""_km(unsigned long long l) { return length(l); } constexpr auto operator""_km(long double l) { return length(l); } + } // namespace literals + + // US customary units + struct yard : unit> {}; + template<> struct upcasting_traits> : upcast_to {}; + + struct foot : unit, yard::ratio>> {}; + template<> struct upcasting_traits> : upcast_to {}; + + struct inch : unit, foot::ratio>> {}; + template<> struct upcasting_traits> : upcast_to {}; + + struct mile : unit, yard::ratio>> {}; + template<> struct upcasting_traits> : upcast_to {}; + + inline namespace literals { + // yd constexpr auto operator""_yd(unsigned long long l) { return length(l); } constexpr auto operator""_yd(long double l) { return length(l); } diff --git a/src/include/units/luminous_intensity.h b/src/include/units/luminous_intensity.h new file mode 100644 index 00000000..ac203384 --- /dev/null +++ b/src/include/units/luminous_intensity.h @@ -0,0 +1,50 @@ +// 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 + +namespace units { + + struct dimension_luminous_intensity : make_dimension_t> {}; + template<> struct upcasting_traits> : upcast_to {}; + + template + concept bool LuminousIntensity = Quantity && std::experimental::ranges::Same; + + template + using luminous_intensity = quantity; + + struct candela : unit> {}; + template<> struct upcasting_traits> : upcast_to {}; + + inline namespace literals { + + // cd + constexpr auto operator""_cd(unsigned long long l) { return luminous_intensity(l); } + constexpr auto operator""_cd(long double l) { return luminous_intensity(l); } + + } // namespace literals + +} // namespace units diff --git a/src/include/units/mass.h b/src/include/units/mass.h new file mode 100644 index 00000000..d0672020 --- /dev/null +++ b/src/include/units/mass.h @@ -0,0 +1,53 @@ +// 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 + +namespace units { + + struct dimension_mass : make_dimension_t> {}; + template<> struct upcasting_traits> : upcast_to {}; + + template + concept bool Mass = Quantity && std::experimental::ranges::Same; + + template + using mass = quantity; + + struct gram : unit {}; + template<> struct upcasting_traits> : upcast_to {}; + + struct kilogram : unit> {}; + template<> struct upcasting_traits> : upcast_to {}; + + inline namespace literals { + + // kg + constexpr auto operator""_kg(unsigned long long l) { return mass(l); } + constexpr auto operator""_kg(long double l) { return mass(l); } + + } // namespace literals + +} // namespace units diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index e7e9ce51..d35b10bd 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -22,7 +22,7 @@ #pragma once -#include "unit.h" +#include #include #include diff --git a/src/include/units/substance.h b/src/include/units/substance.h new file mode 100644 index 00000000..bc3e9b44 --- /dev/null +++ b/src/include/units/substance.h @@ -0,0 +1,50 @@ +// 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 + +namespace units { + + struct dimension_substance : make_dimension_t> {}; + template<> struct upcasting_traits> : upcast_to {}; + + template + concept bool Substance = Quantity && std::experimental::ranges::Same; + + template + using substance = quantity; + + struct mole : unit> {}; + template<> struct upcasting_traits> : upcast_to {}; + + inline namespace literals { + + // mol + constexpr auto operator""_mol(unsigned long long l) { return substance(l); } + constexpr auto operator""_mol(long double l) { return substance(l); } + + } // namespace literals + +} // namespace units diff --git a/src/include/units/temperature.h b/src/include/units/temperature.h new file mode 100644 index 00000000..87414c1d --- /dev/null +++ b/src/include/units/temperature.h @@ -0,0 +1,50 @@ +// 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 + +namespace units { + + struct dimension_temperature : make_dimension_t> {}; + template<> struct upcasting_traits> : upcast_to {}; + + template + concept bool ThermodynamicTemperature = Quantity && std::experimental::ranges::Same; + + template + using temperature = quantity; + + struct kelvin : unit> {}; + template<> struct upcasting_traits> : upcast_to {}; + + inline namespace literals { + + // K + constexpr auto operator""_K(unsigned long long l) { return temperature(l); } + constexpr auto operator""_K(long double l) { return temperature(l); } + + } // namespace literals + +} // namespace units diff --git a/src/include/units/si/time.h b/src/include/units/time.h similarity index 96% rename from src/include/units/si/time.h rename to src/include/units/time.h index 02e65bac..3602fa06 100644 --- a/src/include/units/si/time.h +++ b/src/include/units/time.h @@ -22,14 +22,20 @@ #pragma once -#include "base_dimensions.h" -#include "../quantity.h" +#include +#include namespace units { struct dimension_time : make_dimension_t> {}; template<> struct upcasting_traits> : upcast_to {}; + template + concept bool Time = Quantity && std::experimental::ranges::Same; + + template + using time = quantity; + struct nanosecond : unit {}; template<> struct upcasting_traits> : upcast_to {}; @@ -48,13 +54,6 @@ namespace units { struct hour : unit> {}; template<> struct upcasting_traits> : upcast_to {}; - template - using time = quantity; - - - template - concept bool Time = Quantity && std::experimental::ranges::Same; - inline namespace literals { // ns diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 628a28ab..067a1364 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -22,8 +22,7 @@ #pragma once -#include "bits/tools.h" -#include "dimension.h" +#include namespace units { diff --git a/src/include/units/si/velocity.h b/src/include/units/velocity.h similarity index 95% rename from src/include/units/si/velocity.h rename to src/include/units/velocity.h index 379bfcc2..9cec999e 100644 --- a/src/include/units/si/velocity.h +++ b/src/include/units/velocity.h @@ -22,15 +22,21 @@ #pragma once -#include "base_dimensions.h" -#include "length.h" -#include "time.h" +#include +#include +#include namespace units { struct dimension_velocity : make_dimension_t, exp> {}; template<> struct upcasting_traits> : upcast_to {}; + template + concept bool Velocity = Quantity && std::experimental::ranges::Same; + + template + using velocity = quantity; + struct meter_per_second : unit> {}; template<> struct upcasting_traits> : upcast_to {}; @@ -40,12 +46,6 @@ namespace units { struct mile_per_hour : unit> {}; template<> struct upcasting_traits> : upcast_to {}; - template - using velocity = quantity; - - template - concept bool Velocity = Quantity && std::experimental::ranges::Same; - inline namespace literals { // mps diff --git a/test/test_quantity.cpp b/test/test_quantity.cpp index 9bb00ed9..f240d814 100644 --- a/test/test_quantity.cpp +++ b/test/test_quantity.cpp @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "units/si/velocity.h" -#include "units/si/frequency.h" +#include "units/velocity.h" +#include "units/frequency.h" #include #include diff --git a/test/test_units.cpp b/test/test_units.cpp index 9900a73f..aa8cf785 100644 --- a/test/test_units.cpp +++ b/test/test_units.cpp @@ -20,10 +20,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "units/si/frequency.h" -#include "units/si/length.h" -#include "units/si/time.h" -#include "units/si/velocity.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + #include namespace {