refactor: 💥 q_* UDL renamed to _q_*
We had some fun exploring the STD UDLs for potential collisions, we have learnt our lesson and know how to proceed. Now is high time to start behaving and obeying C++ rules.
This commit is contained in:
1 parent
2b408f19c0
commit
9527b39005
130 files changed
+2221
-2235
No files matched your search
@@ -18,8 +18,8 @@ stream::
|
||||
|
||||
using namespace units::physical::si::literals;
|
||||
using namespace units::physical::international::literals;
|
||||
constexpr Speed auto v1 = avg_speed(220.q_km, 2q_h);
|
||||
constexpr Speed auto v2 = avg_speed(140.q_mi, 2q_h);
|
||||
constexpr Speed auto v1 = avg_speed(220._q_km, 2_q_h);
|
||||
constexpr Speed auto v2 = avg_speed(140._q_mi, 2_q_h);
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
std::cout << v2 << '\n'; // 70 mi/h
|
||||
|
||||
@@ -41,9 +41,9 @@ Stream Output Formatting
|
||||
Only a basic formatting can be applied for output streams. It includes control
|
||||
over width, fill, and alignment::
|
||||
|
||||
os << "|" << std::setw(10) << 123q_m << "|"; // | 123 m|
|
||||
os << "|" << std::setw(10) << std::left << 123q_m << "|"; // |123 m |
|
||||
os << "|" << std::setw(10) << std::setfill('*') << 123q_m << "|"; // |*****123 m|
|
||||
os << "|" << std::setw(10) << 123_q_m << "|"; // | 123 m|
|
||||
os << "|" << std::setw(10) << std::left << 123_q_m << "|"; // |123 m |
|
||||
os << "|" << std::setw(10) << std::setfill('*') << 123_q_m << "|"; // |*****123 m|
|
||||
|
||||
|
||||
fmt::format
|
||||
@@ -91,9 +91,9 @@ In case it is left empty the default formatting of ``{:%Q %q}`` is applied. The
|
||||
default formatting is also applied to the output streams. This is why the following
|
||||
code lines produce the same output::
|
||||
|
||||
std::cout << "Distance: " << 123q_km << "\n";
|
||||
fmt::print("Distance: {}\n", 123q_km);
|
||||
fmt::print("Distance: {:%Q %q}\n", 123q_km);
|
||||
std::cout << "Distance: " << 123_q_km << "\n";
|
||||
fmt::print("Distance: {}\n", 123_q_km);
|
||||
fmt::print("Distance: {:%Q %q}\n", 123_q_km);
|
||||
|
||||
|
||||
Quantity Value, Symbol, or Both?
|
||||
@@ -102,9 +102,9 @@ Quantity Value, Symbol, or Both?
|
||||
The user can easily decide to either print a whole quantity (value and symbol) or
|
||||
only its parts. Also a different quantity formatting might be applied::
|
||||
|
||||
fmt::print("{:%Q}", 123q_km); // 123
|
||||
fmt::print("{:%q}", 123q_km); // km
|
||||
fmt::print("{:%Q%q}", 123q_km); // 123km
|
||||
fmt::print("{:%Q}", 123_q_km); // 123
|
||||
fmt::print("{:%q}", 123_q_km); // km
|
||||
fmt::print("{:%Q%q}", 123_q_km); // 123km
|
||||
|
||||
|
||||
Controlling Width, Fill, and Alignment
|
||||
@@ -114,14 +114,14 @@ To control width, fill, and alignment the C++ standard grammar tokens ``fill-and
|
||||
and ``width`` are being used and they treat a quantity value and symbol as a contiguous
|
||||
text::
|
||||
|
||||
fmt::print("|{:0}|", 123q_m); // |123 m|
|
||||
fmt::print("|{:10}|", 123q_m); // | 123 m|
|
||||
fmt::print("|{:<10}|", 123q_m); // |123 m |
|
||||
fmt::print("|{:>10}|", 123q_m); // | 123 m|
|
||||
fmt::print("|{:^10}|", 123q_m); // | 123 m |
|
||||
fmt::print("|{:*<10}|", 123q_m); // |123 m*****|
|
||||
fmt::print("|{:*>10}|", 123q_m); // |*****123 m|
|
||||
fmt::print("|{:*^10}|", 123q_m); // |**123 m***|
|
||||
fmt::print("|{:0}|", 123_q_m); // |123 m|
|
||||
fmt::print("|{:10}|", 123_q_m); // | 123 m|
|
||||
fmt::print("|{:<10}|", 123_q_m); // |123 m |
|
||||
fmt::print("|{:>10}|", 123_q_m); // | 123 m|
|
||||
fmt::print("|{:^10}|", 123_q_m); // | 123 m |
|
||||
fmt::print("|{:*<10}|", 123_q_m); // |123 m*****|
|
||||
fmt::print("|{:*>10}|", 123_q_m); // |*****123 m|
|
||||
fmt::print("|{:*^10}|", 123_q_m); // |**123 m***|
|
||||
|
||||
|
||||
ASCII-only Quantity Symbols
|
||||
@@ -133,12 +133,12 @@ this by default. From the engineering point of view sometimes Unicode text migh
|
||||
not be a solution as terminals of many (especially embedded) devices are ASCII-only.
|
||||
In such a case the unit symbol can be forced to be printed using ASCII-only characters::
|
||||
|
||||
fmt::print("{}", 10q_R); // 10 Ω
|
||||
fmt::print("{:%Q %Aq}", 10q_R); // 10 ohm
|
||||
fmt::print("{}", 125q_us); // 125 µs
|
||||
fmt::print("{:%Q %Aq}", 125q_us); // 125 us
|
||||
fmt::print("{}", 9.8q_m_per_s2); // 9.8 m/s²
|
||||
fmt::print("{:%Q %Aq}", 9.8q_m_per_s2); // 9.8 m/s^2
|
||||
fmt::print("{}", 10_q_R); // 10 Ω
|
||||
fmt::print("{:%Q %Aq}", 10_q_R); // 10 ohm
|
||||
fmt::print("{}", 125_q_us); // 125 µs
|
||||
fmt::print("{:%Q %Aq}", 125_q_us); // 125 us
|
||||
fmt::print("{}", 9.8_q_m_per_s2); // 9.8 m/s²
|
||||
fmt::print("{:%Q %Aq}", 9.8_q_m_per_s2); // 9.8 m/s^2
|
||||
|
||||
|
||||
Controlling on How the Quantity Value Is Being Printed
|
||||
@@ -146,8 +146,8 @@ Controlling on How the Quantity Value Is Being Printed
|
||||
|
||||
``sign`` token allows us to specify on how the value's sign is being printed::
|
||||
|
||||
fmt::print("{0:%Q %q},{0:%+Q %q},{0:%-Q %q},{0:% Q %q}", 1q_m); // 1 m,+1 m,1 m, 1 m
|
||||
fmt::print("{0:%Q %q},{0:%+Q %q},{0:%-Q %q},{0:% Q %q}", -1q_m); // -1 m,-1 m,-1 m,-1 m
|
||||
fmt::print("{0:%Q %q},{0:%+Q %q},{0:%-Q %q},{0:% Q %q}", 1_q_m); // 1 m,+1 m,1 m, 1 m
|
||||
fmt::print("{0:%Q %q},{0:%+Q %q},{0:%-Q %q},{0:% Q %q}", -1_q_m); // -1 m,-1 m,-1 m,-1 m
|
||||
|
||||
where:
|
||||
|
||||
@@ -159,47 +159,47 @@ where:
|
||||
|
||||
``precision`` token is allowed only for floating-point representation types::
|
||||
|
||||
fmt::print("{:%.0Q %q}", 1.2345q_m); // 1 m
|
||||
fmt::print("{:%.1Q %q}", 1.2345q_m); // 1.2 m
|
||||
fmt::print("{:%.2Q %q}", 1.2345q_m); // 1.23 m
|
||||
fmt::print("{:%.0Q %q}", 1.2345_q_m); // 1 m
|
||||
fmt::print("{:%.1Q %q}", 1.2345_q_m); // 1.2 m
|
||||
fmt::print("{:%.2Q %q}", 1.2345_q_m); // 1.23 m
|
||||
|
||||
|
||||
:token:`units-rep-type` specifies how a value of the representation type is being
|
||||
printed. For integral types::
|
||||
|
||||
fmt::print("{:%bQ %q}", 42q_m); // 101010 m
|
||||
fmt::print("{:%BQ %q}", 42q_m); // 101010 m
|
||||
fmt::print("{:%dQ %q}", 42q_m); // 42 m
|
||||
fmt::print("{:%oQ %q}", 42q_m); // 52 m
|
||||
fmt::print("{:%xQ %q}", 42q_m); // 2a m
|
||||
fmt::print("{:%XQ %q}", 42q_m); // 2A m
|
||||
fmt::print("{:%bQ %q}", 42_q_m); // 101010 m
|
||||
fmt::print("{:%BQ %q}", 42_q_m); // 101010 m
|
||||
fmt::print("{:%dQ %q}", 42_q_m); // 42 m
|
||||
fmt::print("{:%oQ %q}", 42_q_m); // 52 m
|
||||
fmt::print("{:%xQ %q}", 42_q_m); // 2a m
|
||||
fmt::print("{:%XQ %q}", 42_q_m); // 2A m
|
||||
|
||||
The above can be printed in an alternate version thanks to the ``#`` token::
|
||||
|
||||
fmt::print("{:%#bQ %q}", 42q_m); // 0b101010 m
|
||||
fmt::print("{:%#BQ %q}", 42q_m); // 0B101010 m
|
||||
fmt::print("{:%#oQ %q}", 42q_m); // 052 m
|
||||
fmt::print("{:%#xQ %q}", 42q_m); // 0x2a m
|
||||
fmt::print("{:%#XQ %q}", 42q_m); // 0X2A m
|
||||
fmt::print("{:%#bQ %q}", 42_q_m); // 0b101010 m
|
||||
fmt::print("{:%#BQ %q}", 42_q_m); // 0B101010 m
|
||||
fmt::print("{:%#oQ %q}", 42_q_m); // 052 m
|
||||
fmt::print("{:%#xQ %q}", 42_q_m); // 0x2a m
|
||||
fmt::print("{:%#XQ %q}", 42_q_m); // 0X2A m
|
||||
|
||||
For floating-point values the :token:`units-rep-type` token works as follows::
|
||||
|
||||
fmt::print("{:%aQ %q}", 1.2345678q_m); // 0x9.e065152d8eae841p-3 m
|
||||
fmt::print("{:%.3aQ %q}", 1.2345678q_m); // 0x9.e06p-3 m
|
||||
fmt::print("{:%AQ %q}", 1.2345678q_m); // 0X9.E065152D8EAE841P-3 m
|
||||
fmt::print("{:%.3AQ %q}", 1.2345678q_m); // 0X9.E06P-3 m
|
||||
fmt::print("{:%eQ %q}", 1.2345678q_m); // 1.234568e+00 m
|
||||
fmt::print("{:%.3eQ %q}", 1.2345678q_m); // 1.235e+00 m
|
||||
fmt::print("{:%EQ %q}", 1.2345678q_m); // 1.234568E+00 m
|
||||
fmt::print("{:%.3EQ %q}", 1.2345678q_m); // 1.235E+00 m
|
||||
fmt::print("{:%gQ %q}", 1.2345678q_m); // 1.23457 m
|
||||
fmt::print("{:%gQ %q}", 1.2345678e8q_m); // 1.23457e+08 m
|
||||
fmt::print("{:%.3gQ %q}", 1.2345678q_m); // 1.23 m
|
||||
fmt::print("{:%.3gQ %q}", 1.2345678e8q_m); // 1.23e+08 m
|
||||
fmt::print("{:%GQ %q}", 1.2345678q_m); // 1.23457 m
|
||||
fmt::print("{:%GQ %q}", 1.2345678e8q_m); // 1.23457E+08 m
|
||||
fmt::print("{:%.3GQ %q}", 1.2345678q_m); // 1.23 m
|
||||
fmt::print("{:%.3GQ %q}", 1.2345678e8q_m); // 1.23E+08 m
|
||||
fmt::print("{:%aQ %q}", 1.2345678_q_m); // 0x9.e065152d8eae841p-3 m
|
||||
fmt::print("{:%.3aQ %q}", 1.2345678_q_m); // 0x9.e06p-3 m
|
||||
fmt::print("{:%AQ %q}", 1.2345678_q_m); // 0X9.E065152D8EAE841P-3 m
|
||||
fmt::print("{:%.3AQ %q}", 1.2345678_q_m); // 0X9.E06P-3 m
|
||||
fmt::print("{:%eQ %q}", 1.2345678_q_m); // 1.234568e+00 m
|
||||
fmt::print("{:%.3eQ %q}", 1.2345678_q_m); // 1.235e+00 m
|
||||
fmt::print("{:%EQ %q}", 1.2345678_q_m); // 1.234568E+00 m
|
||||
fmt::print("{:%.3EQ %q}", 1.2345678_q_m); // 1.235E+00 m
|
||||
fmt::print("{:%gQ %q}", 1.2345678_q_m); // 1.23457 m
|
||||
fmt::print("{:%gQ %q}", 1.2345678e8_q_m); // 1.23457e+08 m
|
||||
fmt::print("{:%.3gQ %q}", 1.2345678_q_m); // 1.23 m
|
||||
fmt::print("{:%.3gQ %q}", 1.2345678e8_q_m); // 1.23e+08 m
|
||||
fmt::print("{:%GQ %q}", 1.2345678_q_m); // 1.23457 m
|
||||
fmt::print("{:%GQ %q}", 1.2345678e8_q_m); // 1.23457E+08 m
|
||||
fmt::print("{:%.3GQ %q}", 1.2345678_q_m); // 1.23 m
|
||||
fmt::print("{:%.3GQ %q}", 1.2345678e8_q_m); // 1.23E+08 m
|
||||
|
||||
|
||||
Special Signs
|
||||
@@ -208,7 +208,7 @@ Special Signs
|
||||
Beside adding any list of regular characters as a separator between the value and the
|
||||
symbol, it is possible to type a few special signs there too::
|
||||
|
||||
fmt::print("{:%Q_%q}", 123q_km); // 123_km
|
||||
fmt::print("{:%Q%t%q}", 123q_km); // 123\tkm <tab>
|
||||
fmt::print("{:%Q%n%q}", 123q_km); // 123\nkm <new line>
|
||||
fmt::print("{:%Q%% %q}", 123q_km); // 123% km
|
||||
fmt::print("{:%Q_%q}", 123_q_km); // 123_km
|
||||
fmt::print("{:%Q%t%q}", 123_q_km); // 123\tkm <tab>
|
||||
fmt::print("{:%Q%n%q}", 123_q_km); // 123\nkm <new line>
|
||||
fmt::print("{:%Q%% %q}", 123_q_km); // 123% km
|
||||
Reference in new issue
Block a user