mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 12:54:25 +02:00
Short name added to derived unit definition
This commit is contained in:
@@ -66,6 +66,8 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
|||||||
-fconcepts
|
-fconcepts
|
||||||
-Wno-literal-suffix
|
-Wno-literal-suffix
|
||||||
-Wno-non-template-friend
|
-Wno-non-template-friend
|
||||||
|
# TODO gcc:92101
|
||||||
|
-Wno-pedantic
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
add_library(mp::units ALIAS units)
|
add_library(mp::units ALIAS units)
|
||||||
|
67
src/include/units/bits/fixed_string.h
Normal file
67
src/include/units/bits/fixed_string.h
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace units {
|
||||||
|
|
||||||
|
// TODO gcc:92101
|
||||||
|
// Gated by the following gcc bug
|
||||||
|
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92101
|
||||||
|
//
|
||||||
|
// template<typename CharT, std::size_t N>
|
||||||
|
// struct basic_fixed_string {
|
||||||
|
// CharT data_[N+1] = {};
|
||||||
|
|
||||||
|
// constexpr basic_fixed_string(const CharT (&txt)[N+1]) noexcept
|
||||||
|
// {
|
||||||
|
// for(std::size_t i = 0; i <= N; ++i)
|
||||||
|
// data_[i] = txt[i];
|
||||||
|
// }
|
||||||
|
// // auto operator==(const basic_fixed_string &) = default;
|
||||||
|
// [[nodiscard]] constexpr const CharT* c_str() const noexcept { return data_; }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// template<typename CharT, std::size_t N>
|
||||||
|
// basic_fixed_string(const CharT (&str)[N]) -> basic_fixed_string<CharT, N-1>;
|
||||||
|
|
||||||
|
// template<std::size_t N>
|
||||||
|
// using fixed_string = basic_fixed_string<char, N>;
|
||||||
|
|
||||||
|
template<typename CharT, CharT... Chars>
|
||||||
|
struct basic_fixed_string {
|
||||||
|
static constexpr CharT txt[] = { Chars..., '\0' };
|
||||||
|
|
||||||
|
static constexpr const CharT* c_str() noexcept
|
||||||
|
{
|
||||||
|
return txt;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline namespace hacks {
|
||||||
|
|
||||||
|
template<typename T, T... chars>
|
||||||
|
constexpr basic_fixed_string<T, chars...> operator""_fs() { return {}; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -31,7 +31,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Acceleration = QuantityOf<T, acceleration>;
|
concept Acceleration = QuantityOf<T, acceleration>;
|
||||||
|
|
||||||
struct metre_per_second_sq : derived_unit<metre_per_second_sq, acceleration, metre, second> {};
|
struct metre_per_second_sq : derived_unit<metre_per_second_sq, decltype("m/s^2"_fs), acceleration, metre, second> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -31,11 +31,11 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Area = QuantityOf<T, area>;
|
concept Area = QuantityOf<T, area>;
|
||||||
|
|
||||||
struct square_millimetre : derived_unit<square_millimetre, area, millimetre> {};
|
struct square_millimetre : derived_unit<square_millimetre, decltype("mm^2"_fs), area, millimetre> {};
|
||||||
struct square_centimetre : derived_unit<square_centimetre, area, centimetre> {};
|
struct square_centimetre : derived_unit<square_centimetre, decltype("cm^2"_fs), area, centimetre> {};
|
||||||
struct square_metre : derived_unit<square_metre, area, metre> {};
|
struct square_metre : derived_unit<square_metre, decltype("m^2"_fs), area, metre> {};
|
||||||
struct square_kilometre : derived_unit<square_kilometre, area, kilometre> {};
|
struct square_kilometre : derived_unit<square_kilometre, decltype("km^2"_fs), area, kilometre> {};
|
||||||
struct square_foot : derived_unit<square_foot, area, foot> {};
|
struct square_foot : derived_unit<square_foot, decltype("ft^2"_fs), area, foot> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
@@ -55,6 +55,10 @@ namespace units {
|
|||||||
constexpr auto operator""sq_km(unsigned long long l) { return quantity<square_kilometre, std::int64_t>(l); }
|
constexpr auto operator""sq_km(unsigned long long l) { return quantity<square_kilometre, std::int64_t>(l); }
|
||||||
constexpr auto operator""sq_km(long double l) { return quantity<square_kilometre, long double>(l); }
|
constexpr auto operator""sq_km(long double l) { return quantity<square_kilometre, long double>(l); }
|
||||||
|
|
||||||
|
// sq_ft
|
||||||
|
constexpr auto operator""sq_ft(unsigned long long l) { return quantity<square_foot, std::int64_t>(l); }
|
||||||
|
constexpr auto operator""sq_ft(long double l) { return quantity<square_foot, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
} // namespace units
|
} // namespace units
|
||||||
|
@@ -33,7 +33,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Capacitance = QuantityOf<T, capacitance>;
|
concept Capacitance = QuantityOf<T, capacitance>;
|
||||||
|
|
||||||
struct farad : derived_unit<farad, capacitance, kilogram, metre, second, ampere> {};
|
struct farad : derived_unit<farad, decltype("F"_fs), capacitance, kilogram, metre, second, ampere> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Current = QuantityOf<T, current>;
|
concept Current = QuantityOf<T, current>;
|
||||||
|
|
||||||
struct ampere : derived_unit<ampere, current> {};
|
struct ampere : derived_unit<ampere, decltype("A"_fs), current> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept ElectricCharge = QuantityOf<T, electric_charge>;
|
concept ElectricCharge = QuantityOf<T, electric_charge>;
|
||||||
|
|
||||||
struct coulomb : derived_unit<coulomb, electric_charge, second, ampere> {};
|
struct coulomb : derived_unit<coulomb, decltype("C"_fs), electric_charge, second, ampere> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Energy = QuantityOf<T, energy>;
|
concept Energy = QuantityOf<T, energy>;
|
||||||
|
|
||||||
struct joule : derived_unit<joule, energy, kilogram, metre, second> {};
|
struct joule : derived_unit<joule, decltype("J"_fs), energy, kilogram, metre, second> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Force = QuantityOf<T, force>;
|
concept Force = QuantityOf<T, force>;
|
||||||
|
|
||||||
struct newton : derived_unit<newton, force, kilogram, metre, second> {};
|
struct newton : derived_unit<newton, decltype("N"_fs), force, kilogram, metre, second> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,23 +32,23 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Frequency = QuantityOf<T, frequency>;
|
concept Frequency = QuantityOf<T, frequency>;
|
||||||
|
|
||||||
struct hertz : derived_unit<hertz, frequency, second> {};
|
struct hertz : derived_unit<hertz, decltype("Hz"_fs), frequency, second> {};
|
||||||
struct millihertz : derived_unit<millihertz, milli<hertz>> {};
|
struct millihertz : derived_unit<millihertz, decltype("mHz"_fs), milli<hertz>> {};
|
||||||
struct kilohertz : derived_unit<kilohertz, kilo<hertz>> {};
|
struct kilohertz : derived_unit<kilohertz, decltype("kHz"_fs), kilo<hertz>> {};
|
||||||
struct megahertz : derived_unit<megahertz, mega<hertz>> {};
|
struct megahertz : derived_unit<megahertz, decltype("MHz"_fs), mega<hertz>> {};
|
||||||
struct gigahertz : derived_unit<gigahertz, giga<hertz>> {};
|
struct gigahertz : derived_unit<gigahertz, decltype("GHz"_fs), giga<hertz>> {};
|
||||||
struct terahertz : derived_unit<terahertz, tera<hertz>> {};
|
struct terahertz : derived_unit<terahertz, decltype("THz"_fs), tera<hertz>> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// mHz
|
|
||||||
constexpr auto operator""mHz(unsigned long long l) { return quantity<millihertz, std::int64_t>(l); }
|
|
||||||
constexpr auto operator""mHz(long double l) { return quantity<millihertz, long double>(l); }
|
|
||||||
|
|
||||||
// Hz
|
// Hz
|
||||||
constexpr auto operator""Hz(unsigned long long l) { return quantity<hertz, std::int64_t>(l); }
|
constexpr auto operator""Hz(unsigned long long l) { return quantity<hertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""Hz(long double l) { return quantity<hertz, long double>(l); }
|
constexpr auto operator""Hz(long double l) { return quantity<hertz, long double>(l); }
|
||||||
|
|
||||||
|
// mHz
|
||||||
|
constexpr auto operator""mHz(unsigned long long l) { return quantity<millihertz, std::int64_t>(l); }
|
||||||
|
constexpr auto operator""mHz(long double l) { return quantity<millihertz, long double>(l); }
|
||||||
|
|
||||||
// kHz
|
// kHz
|
||||||
constexpr auto operator""kHz(unsigned long long l) { return quantity<kilohertz, std::int64_t>(l); }
|
constexpr auto operator""kHz(unsigned long long l) { return quantity<kilohertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""kHz(long double l) { return quantity<kilohertz, long double>(l); }
|
constexpr auto operator""kHz(long double l) { return quantity<kilohertz, long double>(l); }
|
||||||
|
@@ -33,13 +33,17 @@ namespace units {
|
|||||||
concept Length = QuantityOf<T, length>;
|
concept Length = QuantityOf<T, length>;
|
||||||
|
|
||||||
// SI units
|
// SI units
|
||||||
struct metre : derived_unit<metre, length> {};
|
struct metre : derived_unit<metre, decltype("m"_fs), length> {};
|
||||||
struct millimetre : derived_unit<millimetre, milli<metre>> {};
|
struct millimetre : derived_unit<millimetre, decltype("mm"_fs), milli<metre>> {};
|
||||||
struct centimetre : derived_unit<centimetre, centi<metre>> {};
|
struct centimetre : derived_unit<centimetre, decltype("cm"_fs), centi<metre>> {};
|
||||||
struct kilometre : derived_unit<kilometre, kilo<metre>> {};
|
struct kilometre : derived_unit<kilometre, decltype("km"_fs), kilo<metre>> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
// m
|
||||||
|
constexpr auto operator""m(unsigned long long l) { return quantity<metre, std::int64_t>(l); }
|
||||||
|
constexpr auto operator""m(long double l) { return quantity<metre, long double>(l); }
|
||||||
|
|
||||||
// mm
|
// mm
|
||||||
constexpr auto operator""mm(unsigned long long l) { return quantity<millimetre, std::int64_t>(l); }
|
constexpr auto operator""mm(unsigned long long l) { return quantity<millimetre, std::int64_t>(l); }
|
||||||
constexpr auto operator""mm(long double l) { return quantity<millimetre, long double>(l); }
|
constexpr auto operator""mm(long double l) { return quantity<millimetre, long double>(l); }
|
||||||
@@ -48,10 +52,6 @@ namespace units {
|
|||||||
constexpr auto operator""cm(unsigned long long l) { return quantity<centimetre, std::int64_t>(l); }
|
constexpr auto operator""cm(unsigned long long l) { return quantity<centimetre, std::int64_t>(l); }
|
||||||
constexpr auto operator""cm(long double l) { return quantity<centimetre, long double>(l); }
|
constexpr auto operator""cm(long double l) { return quantity<centimetre, long double>(l); }
|
||||||
|
|
||||||
// m
|
|
||||||
constexpr auto operator""m(unsigned long long l) { return quantity<metre, std::int64_t>(l); }
|
|
||||||
constexpr auto operator""m(long double l) { return quantity<metre, long double>(l); }
|
|
||||||
|
|
||||||
// km
|
// km
|
||||||
constexpr auto operator""km(unsigned long long l) { return quantity<kilometre, std::int64_t>(l); }
|
constexpr auto operator""km(unsigned long long l) { return quantity<kilometre, std::int64_t>(l); }
|
||||||
constexpr auto operator""km(long double l) { return quantity<kilometre, long double>(l); }
|
constexpr auto operator""km(long double l) { return quantity<kilometre, long double>(l); }
|
||||||
@@ -59,10 +59,10 @@ namespace units {
|
|||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
// US customary units
|
// US customary units
|
||||||
struct yard : derived_unit<yard, length, ratio<9'144, 10'000>> {};
|
struct yard : derived_unit<yard, decltype("yd"_fs), length, ratio<9'144, 10'000>> {};
|
||||||
struct foot : derived_unit<foot, length, ratio_multiply<ratio<1, 3>, yard::ratio>> {};
|
struct foot : derived_unit<foot, decltype("ft"_fs), length, ratio_multiply<ratio<1, 3>, yard::ratio>> {};
|
||||||
struct inch : derived_unit<inch, length, ratio_multiply<ratio<1, 12>, foot::ratio>> {};
|
struct inch : derived_unit<inch, decltype("in"_fs), length, ratio_multiply<ratio<1, 12>, foot::ratio>> {};
|
||||||
struct mile : derived_unit<mile, length, ratio_multiply<ratio<1'760>, yard::ratio>> {};
|
struct mile : derived_unit<mile, decltype("mi"_fs), length, ratio_multiply<ratio<1'760>, yard::ratio>> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept LuminousIntensity = QuantityOf<T, luminous_intensity>;
|
concept LuminousIntensity = QuantityOf<T, luminous_intensity>;
|
||||||
|
|
||||||
struct candela : derived_unit<candela, luminous_intensity> {};
|
struct candela : derived_unit<candela, decltype("cd"_fs), luminous_intensity> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,8 +32,8 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Mass = QuantityOf<T, mass>;
|
concept Mass = QuantityOf<T, mass>;
|
||||||
|
|
||||||
struct gram : derived_unit<gram, mass, ratio<1, 1000>> {};
|
struct gram : derived_unit<gram, decltype("g"_fs), mass, ratio<1, 1000>> {};
|
||||||
struct kilogram : derived_unit<kilogram, kilo<gram>> {};
|
struct kilogram : derived_unit<kilogram, decltype("kg"_fs), kilo<gram>> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Power = QuantityOf<T, power>;
|
concept Power = QuantityOf<T, power>;
|
||||||
|
|
||||||
struct watt : derived_unit<watt, power, kilogram, metre, second> {};
|
struct watt : derived_unit<watt, decltype("W"_fs), power, kilogram, metre, second> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Pressure = QuantityOf<T, pressure>;
|
concept Pressure = QuantityOf<T, pressure>;
|
||||||
|
|
||||||
struct pascal : derived_unit<pascal, pressure, kilogram, metre, second> {};
|
struct pascal : derived_unit<pascal, decltype("Pa"_fs), pressure, kilogram, metre, second> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Substance = QuantityOf<T, substance>;
|
concept Substance = QuantityOf<T, substance>;
|
||||||
|
|
||||||
struct mole : derived_unit<mole, substance> {};
|
struct mole : derived_unit<mole, decltype("mol"_fs), substance> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept ThermodynamicTemperature = QuantityOf<T, temperature>;
|
concept ThermodynamicTemperature = QuantityOf<T, temperature>;
|
||||||
|
|
||||||
struct kelvin : derived_unit<kelvin, temperature> {};
|
struct kelvin : derived_unit<kelvin, decltype("K"_fs), temperature> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,12 +32,12 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Time = QuantityOf<T, time>;
|
concept Time = QuantityOf<T, time>;
|
||||||
|
|
||||||
struct second : derived_unit<second, time> {};
|
struct second : derived_unit<second, decltype("s"_fs), time> {};
|
||||||
struct nanosecond : derived_unit<nanosecond, nano<second>> {};
|
struct nanosecond : derived_unit<nanosecond, decltype("ns"_fs), nano<second>> {};
|
||||||
struct microsecond : derived_unit<microsecond, micro<second>> {};
|
struct microsecond : derived_unit<microsecond, decltype("us"_fs), micro<second>> {};
|
||||||
struct millisecond : derived_unit<millisecond, milli<second>> {};
|
struct millisecond : derived_unit<millisecond, decltype("ms"_fs), milli<second>> {};
|
||||||
struct minute : derived_unit<minute, time, ratio<60>> {};
|
struct minute : derived_unit<minute, decltype("min"_fs), time, ratio<60>> {};
|
||||||
struct hour : derived_unit<hour, time, ratio<3600>> {};
|
struct hour : derived_unit<hour, decltype("h"_fs), time, ratio<3600>> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -32,9 +32,9 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Velocity = QuantityOf<T, velocity>;
|
concept Velocity = QuantityOf<T, velocity>;
|
||||||
|
|
||||||
struct metre_per_second : derived_unit<metre_per_second, velocity, metre, second> {};
|
struct metre_per_second : derived_unit<metre_per_second, decltype("m/s"_fs), velocity, metre, second> {};
|
||||||
struct kilometre_per_hour : derived_unit<kilometre_per_hour, velocity, kilometre, hour> {};
|
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, velocity, mile, hour> {};
|
struct mile_per_hour : derived_unit<mile_per_hour, decltype("mi/h"_fs), velocity, mile, hour> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Voltage = QuantityOf<T, voltage>;
|
concept Voltage = QuantityOf<T, voltage>;
|
||||||
|
|
||||||
struct volt : derived_unit<volt, voltage, kilogram, metre, second, ampere> {};
|
struct volt : derived_unit<volt, decltype("V"_fs), voltage, kilogram, metre, second, ampere> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
@@ -31,11 +31,11 @@ namespace units {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Volume = QuantityOf<T, volume>;
|
concept Volume = QuantityOf<T, volume>;
|
||||||
|
|
||||||
struct cubic_millimetre : derived_unit<cubic_millimetre, volume, millimetre> {};
|
struct cubic_millimetre : derived_unit<cubic_millimetre, decltype("mm^3"_fs), volume, millimetre> {};
|
||||||
struct cubic_centimetre : derived_unit<cubic_centimetre, volume, centimetre> {};
|
struct cubic_centimetre : derived_unit<cubic_centimetre, decltype("cm^3"_fs), volume, centimetre> {};
|
||||||
struct cubic_metre : derived_unit<cubic_metre, volume, metre> {};
|
struct cubic_metre : derived_unit<cubic_metre, decltype("m^3"_fs), volume, metre> {};
|
||||||
struct cubic_kilometre : derived_unit<cubic_kilometre, volume, kilometre, metre> {};
|
struct cubic_kilometre : derived_unit<cubic_kilometre, decltype("km^3"_fs), volume, kilometre, metre> {};
|
||||||
struct cubic_foot : derived_unit<cubic_foot, volume, foot> {};
|
struct cubic_foot : derived_unit<cubic_foot, decltype("ft^3"_fs), volume, foot> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
@@ -55,6 +55,10 @@ namespace units {
|
|||||||
constexpr auto operator""cub_km(unsigned long long l) { return quantity<cubic_kilometre, std::int64_t>(l); }
|
constexpr auto operator""cub_km(unsigned long long l) { return quantity<cubic_kilometre, std::int64_t>(l); }
|
||||||
constexpr auto operator""cub_km(long double l) { return quantity<cubic_kilometre, long double>(l); }
|
constexpr auto operator""cub_km(long double l) { return quantity<cubic_kilometre, long double>(l); }
|
||||||
|
|
||||||
|
// cub_ft
|
||||||
|
constexpr auto operator""cub_ft(unsigned long long l) { return quantity<cubic_foot, std::int64_t>(l); }
|
||||||
|
constexpr auto operator""cub_ft(long double l) { return quantity<cubic_foot, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
} // namespace units
|
} // namespace units
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <units/dimension.h>
|
#include <units/dimension.h>
|
||||||
#include <units/ratio.h>
|
#include <units/ratio.h>
|
||||||
|
#include <units/bits/fixed_string.h>
|
||||||
#include <ratio>
|
#include <ratio>
|
||||||
|
|
||||||
namespace units {
|
namespace units {
|
||||||
@@ -115,20 +116,54 @@ namespace units {
|
|||||||
|
|
||||||
// derived_unit
|
// derived_unit
|
||||||
|
|
||||||
template<typename Child, typename...>
|
// TODO gcc:92101
|
||||||
|
// Gated by the following gcc bug
|
||||||
|
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92101
|
||||||
|
// template<typename Child, fixed_string Name, typename...>
|
||||||
|
// struct derived_unit;
|
||||||
|
|
||||||
|
// template<typename Child, fixed_string Name, Dimension D>
|
||||||
|
// struct derived_unit<Child, Name, D> : downcast_helper<Child, unit<D, ratio<1>>> {
|
||||||
|
// static constexpr auto name = Name;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// template<typename Child, fixed_string Name, Dimension D, Ratio R>
|
||||||
|
// struct derived_unit<Child, Name, D, R> : downcast_helper<Child, unit<D, R>> {
|
||||||
|
// static constexpr auto name = Name;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// template<typename Child, fixed_string Name, Unit U>
|
||||||
|
// struct derived_unit<Child, Name, U> : downcast_helper<Child, U> {
|
||||||
|
// static constexpr auto name = Name;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// template<typename Child, fixed_string Name, Dimension D, Unit U, Unit... Us>
|
||||||
|
// struct derived_unit<Child, Name, D, U, Us...> : downcast_helper<Child, detail::make_derived_unit<D, U, Us...>> {
|
||||||
|
// static constexpr auto name = Name;
|
||||||
|
// };
|
||||||
|
|
||||||
|
template<typename Child, typename Name, typename...>
|
||||||
struct derived_unit;
|
struct derived_unit;
|
||||||
|
|
||||||
template<typename Child, Dimension D>
|
template<typename Child, typename Name, Dimension D>
|
||||||
struct derived_unit<Child, D> : downcast_helper<Child, unit<D, ratio<1>>> {};
|
struct derived_unit<Child, Name, D> : downcast_helper<Child, unit<D, ratio<1>>> {
|
||||||
|
static constexpr auto name = Name::c_str();
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Child, Dimension D, Ratio R>
|
template<typename Child, typename Name, Dimension D, Ratio R>
|
||||||
struct derived_unit<Child, D, R> : downcast_helper<Child, unit<D, R>> {};
|
struct derived_unit<Child, Name, D, R> : downcast_helper<Child, unit<D, R>> {
|
||||||
|
static constexpr auto name = Name::c_str();
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Child, Unit U>
|
template<typename Child, typename Name, Unit U>
|
||||||
struct derived_unit<Child, U> : downcast_helper<Child, U> {};
|
struct derived_unit<Child, Name, U> : downcast_helper<Child, U> {
|
||||||
|
static constexpr auto name = Name::c_str();
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Child, Dimension D, Unit U, Unit... Us>
|
template<typename Child, typename Name, Dimension D, Unit U, Unit... Us>
|
||||||
struct derived_unit<Child, D, U, Us...> : downcast_helper<Child, detail::make_derived_unit<D, U, Us...>> {};
|
struct derived_unit<Child, Name, D, U, Us...> : downcast_helper<Child, detail::make_derived_unit<D, U, Us...>> {
|
||||||
|
static constexpr auto name = Name::c_str();
|
||||||
|
};
|
||||||
|
|
||||||
// SI prefixes
|
// SI prefixes
|
||||||
|
|
||||||
|
@@ -21,21 +21,16 @@
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
#include "units/dimensions/area.h"
|
#include "units/dimensions/area.h"
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
// TODO Remove when a text formatting is implemented
|
// TODO Remove when a text formatting is implemented
|
||||||
|
|
||||||
namespace units {
|
namespace units {
|
||||||
|
|
||||||
template<typename Rep>
|
template<typename Unit, typename Rep>
|
||||||
std::ostream& operator<<(std::ostream& os, const quantity<metre, Rep>& value)
|
std::ostream& operator<<(std::ostream& os, const quantity<Unit, Rep>& value)
|
||||||
{
|
{
|
||||||
return os << value.count() << "m";
|
return os << value.count() << Unit::name;
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Rep>
|
|
||||||
std::ostream& operator<<(std::ostream& os, const quantity<square_metre, Rep>& value)
|
|
||||||
{
|
|
||||||
return os << value.count() << "m^2";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -35,8 +35,9 @@ namespace {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept DigitalInformation = units::QuantityOf<T, digital_information>;
|
concept DigitalInformation = units::QuantityOf<T, digital_information>;
|
||||||
|
|
||||||
struct bit : units::derived_unit<bit, digital_information> {};
|
using namespace units::hacks;
|
||||||
struct byte : units::derived_unit<byte, digital_information, units::ratio<8>> {};
|
struct bit : units::derived_unit<bit, decltype("b"_fs), digital_information> {};
|
||||||
|
struct byte : units::derived_unit<byte, decltype("B"_fs), digital_information, units::ratio<8>> {};
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
@@ -61,13 +62,13 @@ namespace {
|
|||||||
|
|
||||||
// power spectral density
|
// power spectral density
|
||||||
struct power_spectral_density : derived_dimension<power_spectral_density, units::exp<voltage, 2>, units::exp<frequency, -1>> {};
|
struct power_spectral_density : derived_dimension<power_spectral_density, units::exp<voltage, 2>, units::exp<frequency, -1>> {};
|
||||||
struct sq_volt_per_hertz : derived_unit<sq_volt_per_hertz, power_spectral_density> {};
|
struct sq_volt_per_hertz : derived_unit<sq_volt_per_hertz, decltype("V^2/Hz"_fs), power_spectral_density> {};
|
||||||
|
|
||||||
// amplitude spectral density
|
// amplitude spectral density
|
||||||
struct amplitude_spectral_density : derived_dimension<amplitude_spectral_density, units::exp<voltage, 1>, units::exp<frequency, -1, 2>> {};
|
struct amplitude_spectral_density : derived_dimension<amplitude_spectral_density, units::exp<voltage, 1>, units::exp<frequency, -1, 2>> {};
|
||||||
// todo: add support for derived_unit
|
// todo: add support for derived_unit
|
||||||
//struct volt_per_sq_hertz : derived_unit<volt_per_sq_hertz, amplitude_spectral_density, volt, hertz> {};
|
//struct volt_per_sq_hertz : derived_unit<volt_per_sq_hertz, amplitude_spectral_density, volt, hertz> {};
|
||||||
struct volt_per_sqrt_hertz : derived_unit<volt_per_sqrt_hertz, amplitude_spectral_density> {};
|
struct volt_per_sqrt_hertz : derived_unit<volt_per_sqrt_hertz, decltype("V/Hz^(1/2)"_fs), amplitude_spectral_density> {};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
Reference in New Issue
Block a user