Prefixed units support redesigned

This commit is contained in:
Mateusz Pusz committed 2019-10-18 15:34:46 +02:00
1 parent 95028d10a7
commit b864461636
30 files changed
+284 -236

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ namespace units {
template<typename T>
concept Acceleration = QuantityOf<T, acceleration>;
struct metre_per_second_sq : coherent_derived_unit<metre_per_second_sq, decltype("m/s^2"_fs), acceleration> {};
struct metre_per_second_sq : coherent_derived_unit<metre_per_second_sq, "m/s^2", acceleration> {};
inline namespace literals {
+5 -5
View File
@@ -31,11 +31,11 @@ namespace units {
template<typename T>
concept Area = QuantityOf<T, area>;
struct square_metre : coherent_derived_unit<square_metre, decltype("m^2"_fs), area> {};
struct square_millimetre : derived_unit<square_millimetre, decltype("mm^2"_fs), area, millimetre> {};
struct square_centimetre : derived_unit<square_centimetre, decltype("cm^2"_fs), area, centimetre> {};
struct square_kilometre : derived_unit<square_kilometre, decltype("km^2"_fs), area, kilometre> {};
struct square_foot : derived_unit<square_foot, decltype("ft^2"_fs), area, foot> {};
struct square_metre : coherent_derived_unit<square_metre, "m^2", area> {};
struct square_millimetre : deduced_derived_unit<square_millimetre, "mm^2", area, millimetre> {};
struct square_centimetre : deduced_derived_unit<square_centimetre, "cm^2", area, centimetre> {};
struct square_kilometre : deduced_derived_unit<square_kilometre, "km^2", area, kilometre> {};
struct square_foot : deduced_derived_unit<square_foot, "ft^2", area, foot> {};
inline namespace literals {
+2 -2
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/electric_charge.h>
#include <units/dimensions/voltage.h>
@@ -33,7 +33,7 @@ namespace units {
template<typename T>
concept Capacitance = QuantityOf<T, capacitance>;
struct farad : coherent_derived_unit<farad, decltype("F"_fs), capacitance, si_prefix> {};
struct farad : coherent_derived_unit<farad, "F", capacitance, si_prefix> {};
inline namespace literals {
+2 -2
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/quantity.h>
namespace units {
@@ -32,7 +32,7 @@ namespace units {
template<typename T>
concept Current = QuantityOf<T, current>;
struct ampere : coherent_derived_unit<ampere, decltype("A"_fs), current, si_prefix> {};
struct ampere : coherent_derived_unit<ampere, "A", current, si_prefix> {};
inline namespace literals {
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/time.h>
#include <units/dimensions/current.h>
@@ -33,7 +33,7 @@ namespace units {
template<typename T>
concept ElectricCharge = QuantityOf<T, electric_charge>;
struct coulomb : coherent_derived_unit<coulomb, decltype("C"_fs), electric_charge, si_prefix> {};
struct coulomb : coherent_derived_unit<coulomb, "C", electric_charge, si_prefix> {};
inline namespace literals {
+7 -6
View File
@@ -22,7 +22,8 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/si_prefixes.h>
#include <units/dimensions/force.h>
#include <units/dimensions/pressure.h>
@@ -33,11 +34,11 @@ namespace units {
template<typename T>
concept Energy = QuantityOf<T, energy>;
struct joule : coherent_derived_unit<joule, decltype("J"_fs), energy, si_prefix> {};
struct millijoule : derived_unit<millijoule, decltype("mJ"_fs), milli<joule>> {};
struct kilojoule : derived_unit<kilojoule, decltype("kJ"_fs), kilo<joule>> {};
struct megajoule : derived_unit<megajoule, decltype("MJ"_fs), mega<joule>> {};
struct gigajoule : derived_unit<gigajoule, decltype("GJ"_fs), giga<joule>> {};
struct joule : coherent_derived_unit<joule, "J", energy, si_prefix> {};
struct millijoule : prefixed_derived_unit<millijoule, milli, joule> {};
struct kilojoule : prefixed_derived_unit<kilojoule, kilo, joule> {};
struct megajoule : prefixed_derived_unit<megajoule, mega, joule> {};
struct gigajoule : prefixed_derived_unit<gigajoule, giga, joule> {};
inline namespace literals {
+2 -2
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/mass.h>
#include <units/dimensions/acceleration.h>
@@ -33,7 +33,7 @@ namespace units {
template<typename T>
concept Force = QuantityOf<T, force>;
struct newton : coherent_derived_unit<newton, decltype("N"_fs), force, si_prefix> {};
struct newton : coherent_derived_unit<newton, "N", force, si_prefix> {};
inline namespace literals {
+8 -7
View File
@@ -22,7 +22,8 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/si_prefixes.h>
#include <units/dimensions/time.h>
namespace units {
@@ -32,12 +33,12 @@ namespace units {
template<typename T>
concept Frequency = QuantityOf<T, frequency>;
struct hertz : coherent_derived_unit<hertz, decltype("Hz"_fs), frequency, si_prefix> {};
struct millihertz : derived_unit<millihertz, decltype("mHz"_fs), milli<hertz>> {};
struct kilohertz : derived_unit<kilohertz, decltype("kHz"_fs), kilo<hertz>> {};
struct megahertz : derived_unit<megahertz, decltype("MHz"_fs), mega<hertz>> {};
struct gigahertz : derived_unit<gigahertz, decltype("GHz"_fs), giga<hertz>> {};
struct terahertz : derived_unit<terahertz, decltype("THz"_fs), tera<hertz>> {};
struct hertz : coherent_derived_unit<hertz, "Hz", frequency, si_prefix> {};
struct millihertz : prefixed_derived_unit<millihertz, milli, hertz> {};
struct kilohertz : prefixed_derived_unit<kilohertz, kilo, hertz> {};
struct megahertz : prefixed_derived_unit<megahertz, mega, hertz> {};
struct gigahertz : prefixed_derived_unit<gigahertz, giga, hertz> {};
struct terahertz : prefixed_derived_unit<terahertz, tera, hertz> {};
inline namespace literals {
+10 -9
View File
@@ -22,7 +22,8 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/si_prefixes.h>
#include <units/quantity.h>
namespace units {
@@ -33,10 +34,10 @@ namespace units {
concept Length = QuantityOf<T, length>;
// SI units
struct metre : coherent_derived_unit<metre, decltype("m"_fs), length, si_prefix> {};
struct millimetre : derived_unit<millimetre, decltype("mm"_fs), milli<metre>> {};
struct centimetre : derived_unit<centimetre, decltype("cm"_fs), centi<metre>> {};
struct kilometre : derived_unit<kilometre, decltype("km"_fs), kilo<metre>> {};
struct metre : coherent_derived_unit<metre, "m", length, si_prefix> {};
struct millimetre : prefixed_derived_unit<millimetre, milli, metre> {};
struct centimetre : prefixed_derived_unit<centimetre, centi, metre> {};
struct kilometre : prefixed_derived_unit<kilometre, kilo, metre> {};
inline namespace literals {
@@ -59,10 +60,10 @@ namespace units {
} // namespace literals
// US customary units
struct yard : derived_unit<yard, decltype("yd"_fs), length, ratio<9'144, 10'000>> {};
struct foot : derived_unit<foot, decltype("ft"_fs), length, ratio_multiply<ratio<1, 3>, yard::ratio>> {};
struct inch : derived_unit<inch, decltype("in"_fs), length, ratio_multiply<ratio<1, 12>, foot::ratio>> {};
struct mile : derived_unit<mile, decltype("mi"_fs), length, ratio_multiply<ratio<1'760>, yard::ratio>> {};
struct yard : derived_unit<yard, "yd", length, ratio<9'144, 10'000>> {};
struct foot : derived_unit<foot, "ft", length, ratio_multiply<ratio<1, 3>, yard::ratio>> {};
struct inch : derived_unit<inch, "in", length, ratio_multiply<ratio<1, 12>, foot::ratio>> {};
struct mile : derived_unit<mile, "mi", length, ratio_multiply<ratio<1'760>, yard::ratio>> {};
inline namespace literals {
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/quantity.h>
namespace units {
@@ -32,7 +32,7 @@ namespace units {
template<typename T>
concept LuminousIntensity = QuantityOf<T, luminous_intensity>;
struct candela : coherent_derived_unit<candela, decltype("cd"_fs), luminous_intensity, si_prefix> {};
struct candela : coherent_derived_unit<candela, "cd", luminous_intensity, si_prefix> {};
inline namespace literals {
+3 -3
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/quantity.h>
namespace units {
@@ -32,8 +32,8 @@ namespace units {
template<typename T>
concept Mass = QuantityOf<T, mass>;
struct kilogram : coherent_derived_unit<kilogram, decltype("kg"_fs), mass> {};
struct gram : derived_unit<gram, decltype("g"_fs), mass, ratio<1, 1000>> {};
struct kilogram : coherent_derived_unit<kilogram, "kg", mass> {};
struct gram : derived_unit<gram, "g", mass, ratio<1, 1000>> {};
inline namespace literals {
+7 -6
View File
@@ -22,7 +22,8 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/si_prefixes.h>
#include <units/dimensions/energy.h>
namespace units {
@@ -32,11 +33,11 @@ namespace units {
template<typename T>
concept Power = QuantityOf<T, power>;
struct watt : coherent_derived_unit<watt, decltype("W"_fs), power, si_prefix> {};
struct milliwatt : derived_unit<milliwatt, decltype("mW"_fs), milli<watt>> {};
struct kilowatt : derived_unit<kilowatt, decltype("kW"_fs), kilo<watt>> {};
struct megawatt : derived_unit<megawatt, decltype("MW"_fs), mega<watt>> {};
struct gigawatt : derived_unit<gigawatt, decltype("GW"_fs), giga<watt>> {};
struct watt : coherent_derived_unit<watt, "W", power, si_prefix> {};
struct milliwatt : prefixed_derived_unit<milliwatt, milli, watt> {};
struct kilowatt : prefixed_derived_unit<kilowatt, kilo, watt> {};
struct megawatt : prefixed_derived_unit<megawatt, mega, watt> {};
struct gigawatt : prefixed_derived_unit<gigawatt, giga, watt> {};
inline namespace literals {
+2 -2
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/force.h>
#include <units/dimensions/area.h>
@@ -33,7 +33,7 @@ namespace units {
template<typename T>
concept Pressure = QuantityOf<T, pressure>;
struct pascal : coherent_derived_unit<pascal, decltype("Pa"_fs), pressure, si_prefix> {};
struct pascal : coherent_derived_unit<pascal, "Pa", pressure, si_prefix> {};
inline namespace literals {
@@ -0,0 +1,69 @@
// 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 <units/unit.h>
#include <units/format.h>
namespace units {
// prefix tags
struct si_prefix;
// SI prefixes
using atto = prefix<si_prefix, ratio<1, std::atto::den>, "a">;
using femto = prefix<si_prefix, ratio<1, std::femto::den>, "f">;
using pico = prefix<si_prefix, ratio<1, std::pico::den>, "p">;
using nano = prefix<si_prefix, ratio<1, std::nano::den>, "n">;
using micro = prefix<si_prefix, ratio<1, std::micro::den>, "µ">;
using milli = prefix<si_prefix, ratio<1, std::milli::den>, "m">;
using centi = prefix<si_prefix, ratio<1, std::centi::den>, "c">;
using deci = prefix<si_prefix, ratio<1, std::deci::den>, "d">;
using deca = prefix<si_prefix, ratio<std::deca::num>, "da">;
using hecto = prefix<si_prefix, ratio<std::hecto::num>, "h">;
using kilo = prefix<si_prefix, ratio<std::kilo::num>, "k">;
using mega = prefix<si_prefix, ratio<std::mega::num>, "M">;
using giga = prefix<si_prefix, ratio<std::giga::num>, "G">;
using tera = prefix<si_prefix, ratio<std::tera::num>, "T">;
using peta = prefix<si_prefix, ratio<std::peta::num>, "P">;
using exa = prefix<si_prefix, ratio<std::exa::num>, "E">;
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::atto::den>> = "a";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::femto::den>> = "f";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::pico::den>> = "p";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::nano::den>> = "n";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::micro::den>> = "µ";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::milli::den>> = "m";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::centi::den>> = "c";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<1, std::deci::den>> = "d";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::deca::num>> = "da";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::hecto::num>> = "h";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::kilo::num>> = "k";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::mega::num>> = "M";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::giga::num>> = "G";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::tera::num>> = "T";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::peta::num>> = "P";
template<> inline constexpr std::string_view prefix_symbol<si_prefix, ratio<std::exa::num>> = "E";
}
+2 -2
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/quantity.h>
namespace units {
@@ -32,7 +32,7 @@ namespace units {
template<typename T>
concept Substance = QuantityOf<T, substance>;
struct mole : coherent_derived_unit<mole, decltype("mol"_fs), substance, si_prefix> {};
struct mole : coherent_derived_unit<mole, "mol", substance, si_prefix> {};
inline namespace literals {
+2 -2
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/quantity.h>
namespace units {
@@ -32,7 +32,7 @@ namespace units {
template<typename T>
concept ThermodynamicTemperature = QuantityOf<T, temperature>;
struct kelvin : coherent_derived_unit<kelvin, decltype("K"_fs), temperature> {};
struct kelvin : coherent_derived_unit<kelvin, "K", temperature> {};
inline namespace literals {
+8 -7
View File
@@ -22,7 +22,8 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/si_prefixes.h>
#include <units/quantity.h>
namespace units {
@@ -32,12 +33,12 @@ namespace units {
template<typename T>
concept Time = QuantityOf<T, time>;
struct second : coherent_derived_unit<second, decltype("s"_fs), time, si_prefix> {};
struct nanosecond : derived_unit<nanosecond, decltype("ns"_fs), nano<second>> {};
struct microsecond : derived_unit<microsecond, decltype("us"_fs), micro<second>> {};
struct millisecond : derived_unit<millisecond, decltype("ms"_fs), milli<second>> {};
struct minute : derived_unit<minute, decltype("min"_fs), time, ratio<60>> {};
struct hour : derived_unit<hour, decltype("h"_fs), time, ratio<3600>> {};
struct second : coherent_derived_unit<second, "s", time, si_prefix> {};
struct nanosecond : prefixed_derived_unit<nanosecond, nano, second> {};
struct microsecond : prefixed_derived_unit<microsecond, micro, second> {};
struct millisecond : prefixed_derived_unit<millisecond, milli, second> {};
struct minute : derived_unit<minute, "min", time, ratio<60>> {};
struct hour : derived_unit<hour, "h", time, ratio<3600>> {};
inline namespace literals {
+3 -3
View File
@@ -32,9 +32,9 @@ namespace units {
template<typename T>
concept Velocity = QuantityOf<T, velocity>;
struct metre_per_second : coherent_derived_unit<metre_per_second, decltype("m/s"_fs), velocity> {};
struct kilometre_per_hour : derived_unit<kilometre_per_hour, decltype("km/h"_fs), velocity, kilometre, hour> {};
struct mile_per_hour : derived_unit<mile_per_hour, decltype("mi/h"_fs), velocity, mile, hour> {};
struct metre_per_second : coherent_derived_unit<metre_per_second, "m/s", velocity> {};
struct kilometre_per_hour : deduced_derived_unit<kilometre_per_hour, "km/h", velocity, kilometre, hour> {};
struct mile_per_hour : deduced_derived_unit<mile_per_hour, "mi/h", velocity, mile, hour> {};
inline namespace literals {
+2 -2
View File
@@ -22,7 +22,7 @@
#pragma once
#include <units/dimensions/base_dimensions.h>
#include <units/dimensions/si_base_dimensions.h>
#include <units/dimensions/power.h>
#include <units/dimensions/current.h>
#include <units/dimensions/energy.h>
@@ -35,7 +35,7 @@ namespace units {
template<typename T>
concept Voltage = QuantityOf<T, voltage>;
struct volt : coherent_derived_unit<volt, decltype("V"_fs), voltage, si_prefix> {};
struct volt : coherent_derived_unit<volt, "V", voltage, si_prefix> {};
inline namespace literals {
+5 -5
View File
@@ -31,11 +31,11 @@ namespace units {
template<typename T>
concept Volume = QuantityOf<T, volume>;
struct cubic_metre : coherent_derived_unit<cubic_metre, decltype("m^3"_fs), volume> {};
struct cubic_millimetre : derived_unit<cubic_millimetre, decltype("mm^3"_fs), volume, millimetre> {};
struct cubic_centimetre : derived_unit<cubic_centimetre, decltype("cm^3"_fs), volume, centimetre> {};
struct cubic_kilometre : derived_unit<cubic_kilometre, decltype("km^3"_fs), volume, kilometre, metre> {};
struct cubic_foot : derived_unit<cubic_foot, decltype("ft^3"_fs), volume, foot> {};
struct cubic_metre : coherent_derived_unit<cubic_metre, "m^3", volume> {};
struct cubic_millimetre : deduced_derived_unit<cubic_millimetre, "mm^3", volume, millimetre> {};
struct cubic_centimetre : deduced_derived_unit<cubic_centimetre, "cm^3", volume, centimetre> {};
struct cubic_kilometre : deduced_derived_unit<cubic_kilometre, "km^3", volume, kilometre, metre> {};
struct cubic_foot : deduced_derived_unit<cubic_foot, "ft^3", volume, foot> {};
inline namespace literals {