Skip to content

Commit 38fefb9

Browse files
committed
docs: "Quantity Kind Safety" and "Quantity Safety" chapters improved in "Safety Features"
1 parent 4865917 commit 38fefb9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

docs/getting_started/safety_features.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,17 @@ quantity dose_equivalent = 2.0 * Sv;
131131
// auto result = absorbed_dose + dose_equivalent; // ❌ Compile-time error!
132132
// Error: cannot add absorbed dose and dose equivalent (both L²T⁻², but different kinds)
133133

134-
// QuantityOf<isq::absorbed_dose> auto d = 2.5 * Sv; // ❌ Compile-time error!
135-
// Error: cannot initialize absorbed dose with dose equivalent (different quantity kinds)
134+
// auto equal = (absorbed_dose == dose_equivalent); // ❌ Compile-time error!
135+
// Error: cannot compare absorbed dose and dose equivalent
136136
```
137137

138138
Examples of quantities with same dimension but different kinds:
139139

140140
- **Absorbed dose (Gy)** and **Dose equivalent (Sv)**: Both `length²/time²`
141141
- **Frequency (Hz)** and **Activity (Bq)**: Both `1/time`
142142
- **Plane angle (rad)** and **Solid angle (sr)**: Both dimensionless
143+
- **Area (m²)** and **Fuel consumption (L/100km)**: Both `length²` (dimension L²)
144+
- **Distance (m)** and **Wavelength (m)**: Both `length`
143145

144146
!!! important
145147

@@ -159,16 +161,16 @@ Examples of quantities with same dimension but different kinds:
159161
// Quantity Type: Hierarchy prevents mixing energy types
160162
void process_kinetic(quantity<isq::kinetic_energy[J]> ke) { /* ... */ }
161163

162-
quantity pe = isq::potential_energy(100 * J);
163-
// process_kinetic(pe); // ❌ Compile-time error!
164-
// Error: cannot pass potential_energy where kinetic_energy is required
165-
166164
// Quantity Type: Ingredient validation requires specific quantity types
167-
quantity<isq::height[m]> h = 5 * m;
168-
quantity<gravitational_potential_energy[J]> Ep = mass * g * height;
169-
// quantity<gravitational_potential_energy[J]> wrong = mass * g * width; // ❌ Compile-time error!
165+
constexpr quantity g0 = isq::acceleration_of_free_fall(1 * si::standard_gravity);
166+
quantity<isq::height[m]> height = 5 * m;
167+
quantity<gravitational_potential_energy[J]> Ep = mass * g0 * height;
168+
// quantity<gravitational_potential_energy[J]> wrong = mass * g0 * width; // ❌ Compile-time error!
170169
// Error: cannot form gravitational potential energy from width
171170

171+
// process_kinetic(pe); // ❌ Compile-time error!
172+
// Error: cannot pass potential_energy where kinetic_energy is required
173+
172174
// Quantity Character: Vector vs. scalar distinction
173175
quantity<isq::speed[m/s]> speed = cartesian_vector{1, 2, 3} * m / s; // ❌ Compile-time error!
174176
// Error: cannot initialize scalar quantity (speed) with vector representation

0 commit comments

Comments
 (0)